Completed
Push — master ( 0e83ef...caafb0 )
by Klaus
42:35 queued 19:54
created
api/src/Mail.php 2 patches
Spacing   +1137 added lines, -1138 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,13 +196,13 @@  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
-		self::$profileDefunct = Cache::getCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),5*1);
205
+		self::$profileDefunct = Cache::getCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 5 * 1);
206 206
 		if (isset(self::$profileDefunct[$_profileID]) && strlen(self::$profileDefunct[$_profileID]))
207 207
 		{
208 208
 			throw new Exception(__METHOD__." failed to instanciate Mail for Profile #$_profileID Reason:".self::$profileDefunct[$_profileID]);
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
 		{
212 212
 			if (!is_object(self::$instances[$_profileID]))
213 213
 			{
214
-				self::$instances[$_profileID] = new Mail('utf-8',false,$_profileID,false,$_reuseCache);
214
+				self::$instances[$_profileID] = new Mail('utf-8', false, $_profileID, false, $_reuseCache);
215 215
 			}
216 216
 			self::$instances[$_profileID]->icServer = $_oldImapServerObject;
217
-			self::$instances[$_profileID]->accountid= $_oldImapServerObject->ImapServerId;
218
-			self::$instances[$_profileID]->profileID= $_oldImapServerObject->ImapServerId;
217
+			self::$instances[$_profileID]->accountid = $_oldImapServerObject->ImapServerId;
218
+			self::$instances[$_profileID]->profileID = $_oldImapServerObject->ImapServerId;
219 219
 			self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
220
-			self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
220
+			self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
221 221
 			return self::$instances[$_profileID];
222 222
 		}
223 223
 		if ($_profileID == 0)
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
 			{
231 231
 				$profileID = Mail\Account::get_default_acc_id();
232 232
 			}
233
-			if ($profileID!=$_profileID) $_restoreSession==false;
234
-			$_profileID=$profileID;
233
+			if ($profileID != $_profileID) $_restoreSession == false;
234
+			$_profileID = $profileID;
235 235
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
236 236
 		}
237 237
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
238
-		if ($_oldImapServerObject===true)
238
+		if ($_oldImapServerObject === true)
239 239
 		{
240
-			return new Mail('utf-8',false,$_profileID,true,$_reuseCache);
240
+			return new Mail('utf-8', false, $_profileID, true, $_reuseCache);
241 241
 		}
242 242
 		if ($_profileID != 0 && $_validate)
243 243
 		{
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
 			//Cache::setSession('mail','activeProfileID',$_profileID);
258 258
 		}
259 259
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
260
-		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession===false))
260
+		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession === false))
261 261
 		{
262
-			self::$instances[$_profileID] = new Mail('utf-8',$_restoreSession,$_profileID,false,$_reuseCache);
262
+			self::$instances[$_profileID] = new Mail('utf-8', $_restoreSession, $_profileID, false, $_reuseCache);
263 263
 		}
264 264
 		else
265 265
 		{
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 				self::$instances[$_profileID]->ogServer = Mail\Account::read($_profileID)->smtpServer();
271 271
 				// TODO: merge mailprefs into userprefs, for easy treatment
272 272
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
273
-				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
273
+				self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
274 274
 			} catch (\Exception $e)
275 275
 			{
276 276
 				$newprofileID = Mail\Account::get_default_acc_id();
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 				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());
279 279
 				if ($newprofileID)
280 280
 				{
281
-					self::$instances[$newprofileID] = new Mail('utf-8',false,$newprofileID,false,$_reuseCache);
281
+					self::$instances[$newprofileID] = new Mail('utf-8', false, $newprofileID, false, $_reuseCache);
282 282
 					$_profileID = $newprofileID;
283 283
 				}
284 284
 				else
285 285
 				{
286
-					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details?', '.$e->details:''));
286
+					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
287 287
 				}
288 288
 			}
289
-			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
289
+			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate);
290 290
 		}
291 291
 		self::$instances[$_profileID]->profileID = $_profileID;
292 292
 		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 * @param boolean $_testConnection = 0
303 303
 	 * @return mixed $_profileID or false on failed ConnectionTest
304 304
 	 */
305
-	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID=0, $_testConnection=true)
305
+	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID = 0, $_testConnection = true)
306 306
 	{
307 307
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
308 308
 		{
@@ -323,12 +323,12 @@  discard block
 block discarded – undo
323 323
 		}
324 324
 		if ($oldProfileID != $_profileID)
325 325
 		{
326
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
327
-			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
326
+			if ($oldProfileID && $_profileID == 0) $_profileID = $oldProfileID;
327
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveProfileID', $_profileID, 'user');
328 328
 			// save prefs
329 329
 			$GLOBALS['egw']->preferences->save_repository(true);
330 330
 			$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $_profileID;
331
-			Cache::setSession('mail','activeProfileID',$_profileID);
331
+			Cache::setSession('mail', 'activeProfileID', $_profileID);
332 332
 		}
333 333
 		return $_profileID;
334 334
 	}
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	 * @param int $_acc_id = 0
344 344
 	 * @return int validated acc_id -> either acc_id given, or first valid one
345 345
 	 */
346
-	public static function validateProfileID($_acc_id=0)
346
+	public static function validateProfileID($_acc_id = 0)
347 347
 	{
348 348
 		if ($_acc_id)
349 349
 		{
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		}
363 363
 		// no account specified or specified account not found or not valid
364 364
 		// --> search existing account for first valid one and return that
365
-		foreach(Mail\Account::search($only_current_user=true, 'acc_imap_host') as $acc_id => $imap_host)
365
+		foreach (Mail\Account::search($only_current_user = true, 'acc_imap_host') as $acc_id => $imap_host)
366 366
 		{
367 367
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
368 368
 			{
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 	 * @param boolean $_oldImapServerObject = false
385 385
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
386 386
 	 */
387
-	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
387
+	private function __construct($_displayCharset = 'utf-8', $_restoreSession = true, $_profileID = 0, $_oldImapServerObject = false, $_reuseCache = null)
388 388
 	{
389 389
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
390 390
 		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 			$firstMessage = $this->sessionData['previewMessage'];
405 405
 			$this->sessionData = array();
406 406
 		}
407
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
407
+		if (!$_reuseCache) $this->forcePrefReload($_profileID, !$_reuseCache);
408 408
 		try
409 409
 		{
410 410
 			$this->profileID = self::validateProfileID($_profileID);
@@ -418,11 +418,11 @@  discard block
 block discarded – undo
418 418
 			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage());
419 419
 		}
420 420
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($acc->imapServer()));
421
-		$this->icServer = ($_oldImapServerObject?$acc->oldImapServer():$acc->imapServer());
421
+		$this->icServer = ($_oldImapServerObject ? $acc->oldImapServer() : $acc->imapServer());
422 422
 		$this->ogServer = $acc->smtpServer();
423 423
 		// TODO: merge mailprefs into userprefs, for easy treatment
424 424
 		$this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
425
-		$this->htmlOptions  = $this->mailPreferences['htmlOptions'];
425
+		$this->htmlOptions = $this->mailPreferences['htmlOptions'];
426 426
 		if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
427 427
 		{
428 428
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 	public static function &forceEAProfileLoad($_profile_id)
441 441
 	{
442 442
 		self::unsetCachedObjects($_profile_id);
443
-		$mail = self::getInstance(false, $_profile_id,false);
443
+		$mail = self::getInstance(false, $_profile_id, false);
444 444
 		//_debug_array( $_profile_id);
445 445
 		$mail->icServer = Mail\Account::read($_profile_id)->imapServer();
446 446
 		$mail->ogServer = Mail\Account::read($_profile_id)->smtpServer();
@@ -452,11 +452,11 @@  discard block
 block discarded – undo
452 452
 	 * @param int $_profile_id
453 453
 	 * @param boolean $_resetFolderObjects
454 454
 	 */
455
-	public static function forcePrefReload($_profile_id=null,$_resetFolderObjects=true)
455
+	public static function forcePrefReload($_profile_id = null, $_resetFolderObjects = true)
456 456
 	{
457 457
 		// unset the mail_preferences session object, to force the reload/rebuild
458
-		Cache::setSession('mail','mail_preferences',serialize(array()));
459
-		Cache::setSession('emailadmin','session_data',serialize(array()));
458
+		Cache::setSession('mail', 'mail_preferences', serialize(array()));
459
+		Cache::setSession('emailadmin', 'session_data', serialize(array()));
460 460
 		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
461 461
 	}
462 462
 
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 	 */
466 466
 	function restoreSessionData()
467 467
 	{
468
-		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
469
-		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
468
+		$this->sessionData = array(); //Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
469
+		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
470 470
 		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
471 471
 	}
472 472
 
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 	function saveSessionData()
477 477
 	{
478 478
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
479
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
479
+		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID] = $this->sessionData['mailbox'];
480 480
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
481 481
 		{
482
-			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
482
+			Cache::setCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), self::$activeFolderCache, 60 * 60 * 10);
483 483
 		}
484 484
 	}
485 485
 
@@ -495,40 +495,40 @@  discard block
 block discarded – undo
495 495
 	 * @param int $_profileID = null default profile of user as returned by getUserDefaultProfileID
496 496
 	 * @return void
497 497
 	 */
498
-	static function unsetCachedObjects($_profileID=null)
498
+	static function unsetCachedObjects($_profileID = null)
499 499
 	{
500 500
 		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
501 501
 		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
502 502
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
503
-		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
503
+		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID, 'tracker_') === false)))
504 504
 		{
505 505
 			self::resetConnectionErrorCache($_profileID);
506
-			$rawHeadersCache = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
506
+			$rawHeadersCache = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
507 507
 			if (isset($rawHeadersCache[$_profileID]))
508 508
 			{
509 509
 				unset($rawHeadersCache[$_profileID]);
510
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$rawHeadersCache, $expiration=60*60*1);
510
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $rawHeadersCache, $expiration = 60 * 60 * 1);
511 511
 			}
512
-			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*5);
512
+			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 5);
513 513
 			if (isset($HierarchyDelimiterCache[$_profileID]))
514 514
 			{
515 515
 				unset($HierarchyDelimiterCache[$_profileID]);
516
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$HierarchyDelimiterCache, $expiration=60*60*24*5);
516
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $HierarchyDelimiterCache, $expiration = 60 * 60 * 24 * 5);
517 517
 			}
518 518
 			//reset folderObject cache, to trigger reload
519 519
 			self::resetFolderObjectCache($_profileID);
520 520
 			//reset counter of deleted messages per folder
521
-			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
521
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
522 522
 			if (isset($eMailListContainsDeletedMessages[$_profileID]))
523 523
 			{
524 524
 				unset($eMailListContainsDeletedMessages[$_profileID]);
525
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$eMailListContainsDeletedMessages, $expiration=60*60*1);
525
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $eMailListContainsDeletedMessages, $expiration = 60 * 60 * 1);
526 526
 			}
527
-			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*1);
527
+			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 1);
528 528
 			if (isset($vacationCached[$_profileID]))
529 529
 			{
530 530
 				unset($vacationCached[$_profileID]);
531
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
531
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $vacationCached, $expiration = 60 * 60 * 24 * 1);
532 532
 			}
533 533
 
534 534
 			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
@@ -536,17 +536,17 @@  discard block
 block discarded – undo
536 536
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
537 537
 		{
538 538
 			// called via hook
539
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account)
539
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account)
540 540
 			{
541 541
 				//error_log(__METHOD__.__LINE__.array2string($account));
542 542
 				$account_id = $account['account_id'];
543 543
 				$_profileID = null;
544
-				self::resetConnectionErrorCache($_profileID,$account_id);
545
-				self::resetFolderObjectCache($_profileID,$account_id);
546
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),array(), 60*60*1);
547
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),array(), 60*60*24*5);
548
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),array(), 60*60*1);
549
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),array(), 60*60*24*1);
544
+				self::resetConnectionErrorCache($_profileID, $account_id);
545
+				self::resetFolderObjectCache($_profileID, $account_id);
546
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), array(), 60 * 60 * 1);
547
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), array(), 60 * 60 * 24 * 5);
548
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), array(), 60 * 60 * 1);
549
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), array(), 60 * 60 * 24 * 1);
550 550
 			}
551 551
 		}
552 552
 	}
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 	 * @param int $_ImapServerId the profileID to look for
558 558
 	 * @param int $account_id the egw account to look for
559 559
 	 */
560
-	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
560
+	static function resetConnectionErrorCache($_ImapServerId = null, $account_id = null)
561 561
 	{
562 562
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
563 563
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -575,19 +575,19 @@  discard block
 block discarded – undo
575 575
 		}
576 576
 		else
577 577
 		{
578
-			$isConError = Cache::getCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id));
578
+			$isConError = Cache::getCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id));
579 579
 			if (isset($isConError[$_ImapServerId]))
580 580
 			{
581 581
 				unset($isConError[$_ImapServerId]);
582 582
 			}
583
-			$waitOnFailure = Cache::getCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),null,array(),60*60*2);
583
+			$waitOnFailure = Cache::getCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), null, array(), 60 * 60 * 2);
584 584
 			if (isset($waitOnFailure[$_ImapServerId]))
585 585
 			{
586 586
 				unset($waitOnFailure[$_ImapServerId]);
587 587
 			}
588 588
 		}
589
-		Cache::setCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,60*15);
590
-		Cache::setCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),$waitOnFailure,60*60*2);
589
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id), $isConError, 60 * 15);
590
+		Cache::setCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), $waitOnFailure, 60 * 60 * 2);
591 591
 	}
592 592
 
593 593
 	/**
@@ -596,13 +596,13 @@  discard block
 block discarded – undo
596 596
 	 * @param int $_ImapServerId the profileID to look for
597 597
 	 * @param int $account_id the egw account to look for
598 598
 	 */
599
-	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
599
+	static function resetFolderObjectCache($_ImapServerId = null, $account_id = null)
600 600
 	{
601 601
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
602 602
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
603 603
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
604 604
 		// or treat it as not given. we try that path
605
-		if (is_null($_ImapServerId)||is_array($_ImapServerId))
605
+		if (is_null($_ImapServerId) || is_array($_ImapServerId))
606 606
 		{
607 607
 			$folders2return = array();
608 608
 			$folderInfo = array();
@@ -611,12 +611,12 @@  discard block
 block discarded – undo
611 611
 		}
612 612
 		else
613 613
 		{
614
-			$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),null,array(),60*60*1);
614
+			$folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), null, array(), 60 * 60 * 1);
615 615
 			if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
616 616
 			{
617 617
 				unset($folders2return[$_ImapServerId]);
618 618
 			}
619
-			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),60*60*5);
619
+			$folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), null, array(), 60 * 60 * 5);
620 620
 			if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
621 621
 			{
622 622
 				unset($folderInfo[$_ImapServerId]);
@@ -628,23 +628,23 @@  discard block
 block discarded – undo
628 628
 				unset($lastFolderUsedForMove[$_ImapServerId]);
629 629
 			}
630 630
 			*/
631
-			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),60*60*1);
631
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), null, array(), 60 * 60 * 1);
632 632
 			if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
633 633
 			{
634 634
 				unset($folderBasicInfo[$_ImapServerId]);
635 635
 			}
636
-			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),60*60*12);
636
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), null, array(), 60 * 60 * 12);
637 637
 			if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
638 638
 			{
639 639
 				unset($_specialUseFolders[$_ImapServerId]);
640
-				self::$specialUseFolders=null;
640
+				self::$specialUseFolders = null;
641 641
 			}
642 642
 		}
643
-		Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),$folders2return, 60*60*1);
644
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),$folderInfo,60*60*5);
643
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), $folders2return, 60 * 60 * 1);
644
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), $folderInfo, 60 * 60 * 5);
645 645
 		//Cache::setCache(Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($account_id),$lastFolderUsedForMove,$expiration=60*60*1);
646
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),$folderBasicInfo,60*60*1);
647
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),$_specialUseFolders,60*60*12);
646
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), $folderBasicInfo, 60 * 60 * 1);
647
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), $_specialUseFolders, 60 * 60 * 12);
648 648
 	}
649 649
 
650 650
 	/**
@@ -665,15 +665,15 @@  discard block
 block discarded – undo
665 665
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
666 666
 	 * @return array - array(email=>realname)
667 667
 	 */
668
-	function getUserEMailAddresses($_profileID=null)
668
+	function getUserEMailAddresses($_profileID = null)
669 669
 	{
670
-		$acc = Mail\Account::read((!empty($_profileID)?$_profileID:$this->profileID));
670
+		$acc = Mail\Account::read((!empty($_profileID) ? $_profileID : $this->profileID));
671 671
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
672 672
 		$identities = Mail\Account::identities($acc);
673 673
 
674 674
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
675 675
 
676
-		foreach($identities as $ik => $ident) {
676
+		foreach ($identities as $ik => $ident) {
677 677
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
678 678
 			$identity = Mail\Account::read_identity($ik);
679 679
 			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
@@ -688,19 +688,19 @@  discard block
 block discarded – undo
688 688
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
689 689
 	 * @return array - array(email=>realname)
690 690
 	 */
691
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false)
691
+	static function getAllIdentities($_accountToSearch = null, $resolve_placeholders = false)
692 692
 	{
693 693
 		$userEMailAdresses = array();
694
-		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
694
+		foreach (Mail\Account::search($only_current_user = ($_accountToSearch ? $_accountToSearch : true), $just_name = true) as $acc_id => $identity_name)
695 695
 		{
696
-			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
697
-			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']);
696
+			$acc = Mail\Account::read($acc_id, ($_accountToSearch ? $_accountToSearch : null));
697
+			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']);
698 698
 
699
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
699
+			foreach (Mail\Account::identities($acc) as $ik => $ident) {
700 700
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
701
-				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
701
+				$identity = Mail\Account::read_identity($ik, $resolve_placeholders);
702 702
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
703
-				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
+				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']);
704 704
 			}
705 705
 		}
706 706
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -720,9 +720,9 @@  discard block
 block discarded – undo
720 720
 			$account = Mail\Account::read($account);
721 721
 		}
722 722
 		$userEMailAdresses = array();
723
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
723
+		foreach (Mail\Account::identities($account, true, 'params') as $ik => $ident) {
724 724
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
725
-			$identity = Mail\Account::read_identity($ik,true,null,$account);
725
+			$identity = Mail\Account::read_identity($ik, true, null, $account);
726 726
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
727 727
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
728 728
 			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
@@ -749,9 +749,9 @@  discard block
 block discarded – undo
749 749
 	function getDefaultIdentity()
750 750
 	{
751 751
 		// retrieve the signature accociated with the identity
752
-		$id = $this->getIdentitiesWithAccounts($_accountData=array());
753
-		foreach(Mail\Account::identities($_accountData[$this->profileID] ?
754
-			$this->profileID : $_accountData[$id],false,'ident_id') as $accountData)
752
+		$id = $this->getIdentitiesWithAccounts($_accountData = array());
753
+		foreach (Mail\Account::identities($_accountData[$this->profileID] ?
754
+			$this->profileID : $_accountData[$id], false, 'ident_id') as $accountData)
755 755
 		{
756 756
 			return $accountData;
757 757
 		}
@@ -767,13 +767,13 @@  discard block
 block discarded – undo
767 767
 	{
768 768
 		// account select box
769 769
 		$selectedID = $this->profileID;
770
-		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
770
+		$allAccountData = Mail\Account::search($only_current_user = true, false, null);
771 771
 		if ($allAccountData) {
772
-			$rememberFirst=$selectedFound=null;
772
+			$rememberFirst = $selectedFound = null;
773 773
 			foreach ($allAccountData as $tmpkey => $icServers)
774 774
 			{
775 775
 				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
776
-				if ($tmpkey == $selectedID) $selectedFound=true;
776
+				if ($tmpkey == $selectedID) $selectedFound = true;
777 777
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
778 778
 				$host = $icServers->acc_imap_host;
779 779
 				if (empty($host)) continue;
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
782 782
 			}
783 783
 		}
784
-		return ($selectedFound?$selectedID:$rememberFirst);
784
+		return ($selectedFound ? $selectedID : $rememberFirst);
785 785
 	}
786 786
 
787 787
 	/**
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 * @var boolean $fullString full or false=NamePart only is returned
792 792
 	 * @return string - constructed of identity object data as defined in mailConfig
793 793
 	 */
794
-	static function generateIdentityString($identity, $fullString=true)
794
+	static function generateIdentityString($identity, $fullString = true)
795 795
 	{
796 796
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($identity));
797 797
 		//if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
@@ -802,16 +802,16 @@  discard block
 block discarded – undo
802 802
 		{
803 803
 			case 'email';
804 804
 				//$retData = str_replace('@',' ',$identity->emailAddress).($fullString===true?' <'.$identity->emailAddress.'>':'');
805
-				$retData = $identity['ident_email'].($fullString===true?' <'.$identity['ident_email'].'>':'');
805
+				$retData = $identity['ident_email'].($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
806 806
 				break;
807 807
 			case 'nameNemail';
808
-				$retData = (!empty($identity['ident_realname'])?$identity['ident_realname']:substr_replace($identity['ident_email'],'',strpos($identity['ident_email'],'@'))).($fullString===true?' <'.$identity['ident_email'].'>':'');
808
+				$retData = (!empty($identity['ident_realname']) ? $identity['ident_realname'] : substr_replace($identity['ident_email'], '', strpos($identity['ident_email'], '@'))).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
809 809
 				break;
810 810
 			case 'orgNemail';
811
-				$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
+				$retData = (!empty($identity['ident_org']) ? $identity['ident_org'] : substr_replace($identity['ident_email'], '', 0, strpos($identity['ident_email'], '@') + 1)).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
812 812
 				break;
813 813
 			default:
814
-				$retData = $identity['ident_realname'].(!empty($identity['ident_org'])?' '.$identity['ident_org']:'').($fullString===true?' <'.$identity['ident_email'].'>':'');
814
+				$retData = $identity['ident_realname'].(!empty($identity['ident_org']) ? ' '.$identity['ident_org'] : '').($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
815 815
 		}
816 816
 		return $retData;
817 817
 	}
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 	 */
837 837
 	function reopen($_foldername)
838 838
 	{
839
-		if (self::$debugTimes) $starttime = microtime (true);
839
+		if (self::$debugTimes) $starttime = microtime(true);
840 840
 
841 841
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
842 842
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 			}
852 852
 			$folderOpened = $_foldername;
853 853
 		//}
854
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
854
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'Folder:'.$_foldername, __METHOD__.' ('.__LINE__.') ');
855 855
 	}
856 856
 
857 857
 
@@ -862,15 +862,15 @@  discard block
 block discarded – undo
862 862
 	 * @throws Horde_Imap_Client_Exception on connection error or authentication failure
863 863
 	 * @throws InvalidArgumentException on missing credentials
864 864
 	 */
865
-	function openConnection($_icServerID=0)
865
+	function openConnection($_icServerID = 0)
866 866
 	{
867 867
 		//error_log( "-------------------------->open connection ".function_backtrace());
868 868
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
869
-		if (self::$debugTimes) $starttime = microtime (true);
870
-		$mailbox=null;
869
+		if (self::$debugTimes) $starttime = microtime(true);
870
+		$mailbox = null;
871 871
 		try
872 872
 		{
873
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
873
+			if (isset($this->sessionData['mailbox']) && $this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
874 874
 			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
875 875
 /*
876 876
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
898 898
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
899 899
 		}
900
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
900
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'ProfileID:'.$_icServerID, __METHOD__.' ('.__LINE__.') ');
901 901
 	}
902 902
 
903 903
 	/**
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 		try
919 919
 		{
920 920
 			$this->icServer->getCurrentMailbox();
921
-			if(!$this->icServer->hasCapability('QUOTA')) {
921
+			if (!$this->icServer->hasCapability('QUOTA')) {
922 922
 				$quota = false;
923 923
 				return false;
924 924
 			}
@@ -928,15 +928,15 @@  discard block
 block discarded – undo
928 928
 		{
929 929
 			//error_log(__METHOD__.array2string($e));
930 930
 			//error_log(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
931
-			if ($e->getCode()==102)
931
+			if ($e->getCode() == 102)
932 932
 			{
933
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
934
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
935
-				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
933
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
934
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
935
+				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
936 936
 			}
937 937
 		}
938 938
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
939
-		if(is_array($quota)) {
939
+		if (is_array($quota)) {
940 940
 			$quota = array(
941 941
 				'usage'	=> $quota['USED'],
942 942
 				'limit'	=> $quota['QMAX'],
@@ -954,10 +954,10 @@  discard block
 block discarded – undo
954 954
 	 *
955 955
 	 * @return int - timeout (either set or default 20/10)
956 956
 	 */
957
-	static function getTimeOut($_use='IMAP')
957
+	static function getTimeOut($_use = 'IMAP')
958 958
 	{
959 959
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
960
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
960
+		if (empty($timeout)) $timeout = ($_use == 'SIEVE' ? 10 : 20); // this is the default value
961 961
 		return $timeout;
962 962
 	}
963 963
 
@@ -978,18 +978,18 @@  discard block
 block discarded – undo
978 978
 		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
979 979
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
980 980
 		if (is_array($nameSpace)) {
981
-			foreach($nameSpace as $type => $singleNameSpaceArray)
981
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
982 982
 			{
983 983
 				foreach ($singleNameSpaceArray as $singleNameSpace)
984 984
 				{
985 985
 					$_foldersNameSpace = array();
986
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
986
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
987 987
 					{
988 988
 						$_foldersNameSpace['prefix_present'] = 'forced';
989 989
 						// uw-imap server with mailbox prefix or dovecot maybe
990
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
990
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
991 991
 					}
992
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
992
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
993 993
 					{
994 994
 						$_foldersNameSpace['prefix_present'] = 'forced';
995 995
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -998,9 +998,9 @@  discard block
 block discarded – undo
998 998
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
999 999
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
1000 1000
 					}
1001
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
1001
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
1002 1002
 					$_foldersNameSpace['type'] = $type;
1003
-					$foldersNameSpace[] =$_foldersNameSpace;
1003
+					$foldersNameSpace[] = $_foldersNameSpace;
1004 1004
 				}
1005 1005
 				//echo "############## $type->".print_r($foldersNameSpace[$type],true)." ###################<br>";
1006 1006
 			}
@@ -1018,10 +1018,10 @@  discard block
 block discarded – undo
1018 1018
 	 */
1019 1019
 	function getFolderPrefixFromNamespace($nameSpace, $folderName)
1020 1020
 	{
1021
-		foreach($nameSpace as &$singleNameSpace)
1021
+		foreach ($nameSpace as &$singleNameSpace)
1022 1022
 		{
1023 1023
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1024
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1024
+			if (substr($folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1025 1025
 		}
1026 1026
 		return "";
1027 1027
 	}
@@ -1032,12 +1032,12 @@  discard block
 block discarded – undo
1032 1032
 	 * @var boolean $_useCache
1033 1033
 	 * @return string the hierarchyDelimiter
1034 1034
 	 */
1035
-	function getHierarchyDelimiter($_useCache=true)
1035
+	function getHierarchyDelimiter($_useCache = true)
1036 1036
 	{
1037 1037
 		static $HierarchyDelimiter = null;
1038
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1039
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1040
-		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1038
+		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1039
+		if ($_useCache === false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1040
+		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId]) && !empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1041 1041
 		{
1042 1042
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
1043 1043
 		}
@@ -1047,17 +1047,17 @@  discard block
 block discarded – undo
1047 1047
 			$this->icServer->getCurrentMailbox();
1048 1048
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = $this->icServer->getDelimiter();
1049 1049
 		}
1050
-		catch(\Exception $e)
1050
+		catch (\Exception $e)
1051 1051
 		{
1052
-			if ($e->getCode()==102)
1052
+			if ($e->getCode() == 102)
1053 1053
 			{
1054
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1055
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1054
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1055
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1056 1056
 			}
1057 1057
 			unset($e);
1058 1058
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1059 1059
 		}
1060
-		Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),$HierarchyDelimiter, 60*60*24*5);
1060
+		Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), $HierarchyDelimiter, 60 * 60 * 24 * 5);
1061 1061
 		return $HierarchyDelimiter[$this->icServer->ImapServerId];
1062 1062
 	}
1063 1063
 
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 	{
1071 1071
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1072 1072
 		static $_specialUseFolders = null;
1073
-		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);
1073
+		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);
1074 1074
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1075 1075
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1076 1076
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
@@ -1078,20 +1078,20 @@  discard block
 block discarded – undo
1078 1078
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1079 1079
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1080 1080
 			return $_specialUseFolders[$this->icServer->ImapServerId];
1081
-		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1081
+		$_specialUseFolders[$this->icServer->ImapServerId] = array();
1082 1082
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1083
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
1083
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash] = 'Trash';
1084 1084
 		//if (!empty($this->icServer->acc_folder_draft) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]))
1085
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]='Drafts';
1085
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft] = 'Drafts';
1086 1086
 		//if (!empty($this->icServer->acc_folder_sent) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]))
1087
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]='Sent';
1087
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent] = 'Sent';
1088 1088
 		//if (!empty($this->icServer->acc_folder_template) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]))
1089
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]='Templates';
1090
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk]='Junk';
1091
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive]='Archive';
1089
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template] = 'Templates';
1090
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk] = 'Junk';
1091
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive] = 'Archive';
1092 1092
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_specialUseFolders));//.'<->'.array2string($this->icServer));
1093 1093
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1094
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders, 60*60*24*5);
1094
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $_specialUseFolders, 60 * 60 * 24 * 5);
1095 1095
 		return $_specialUseFolders[$this->icServer->ImapServerId];
1096 1096
 	}
1097 1097
 
@@ -1105,8 +1105,8 @@  discard block
 block discarded – undo
1105 1105
 	function folderIsSelectable($folderToSelect)
1106 1106
 	{
1107 1107
 		$retval = true;
1108
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1109
-			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1108
+		if ($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect, false, true))) {
1109
+			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']), 'noselect') !== false)
1110 1110
 			{
1111 1111
 				$retval = false;
1112 1112
 			}
@@ -1126,7 +1126,7 @@  discard block
 block discarded – undo
1126 1126
 	 *
1127 1127
 	 * @throws Exception
1128 1128
 	 */
1129
-	function _getStatus($folderName,$ignoreStatusCache=false)
1129
+	function _getStatus($folderName, $ignoreStatusCache = false)
1130 1130
 	{
1131 1131
 		static $folderStatus = null;
1132 1132
 		if (!$ignoreStatusCache && isset($folderStatus[$this->icServer->ImapServerId][$folderName]))
@@ -1136,11 +1136,11 @@  discard block
 block discarded – undo
1136 1136
 		}
1137 1137
 		try
1138 1138
 		{
1139
-			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName,$ignoreStatusCache);
1139
+			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName, $ignoreStatusCache);
1140 1140
 		}
1141 1141
 		catch (\Exception $e)
1142 1142
 		{
1143
-			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details?', '.$e->details:''));
1143
+			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
1144 1144
 		}
1145 1145
 		return $folderStatus[$this->icServer->ImapServerId][$folderName];
1146 1146
 	}
@@ -1156,10 +1156,10 @@  discard block
 block discarded – undo
1156 1156
 	 * @param fetchSubscribedInfo bool fetch Subscribed Info on folder
1157 1157
 	 * @return array
1158 1158
 	 */
1159
-	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1159
+	function getFolderStatus($_folderName, $ignoreStatusCache = false, $basicInfoOnly = false, $fetchSubscribedInfo = true)
1160 1160
 	{
1161 1161
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1162
-		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1162
+		if (!is_string($_folderName) || empty($_folderName) || (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1163 1163
 		{
1164 1164
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
1165 1165
 			return false;
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 		{
1171 1171
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1172 1172
 		}
1173
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1173
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache == false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1174 1174
 		$retValue = array();
1175 1175
 		$retValue['subscribed'] = false;
1176 1176
 /*
@@ -1191,41 +1191,41 @@  discard block
 block discarded – undo
1191 1191
 			{
1192 1192
 				//error_log(__METHOD__.array2string($e));
1193 1193
 				//error_log(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1194
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1195
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1196
-				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1194
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1195
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1196
+				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
1197 1197
 			}
1198 1198
 			//error_log(__METHOD__.' ('.__LINE__.') '.$_folderName.' '.array2string($ret));
1199 1199
 			if (is_array($ret))
1200 1200
 			{
1201 1201
 				$retkeys = array_keys($ret);
1202
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1202
+				if ($retkeys[0] == $_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1203 1203
 			}
1204 1204
 			else
1205 1205
 			{
1206
-				$folderInfoCache[$_folderName]=false;
1206
+				$folderInfoCache[$_folderName] = false;
1207 1207
 			}
1208 1208
 		}
1209 1209
 		$folderInfo = $folderInfoCache[$_folderName];
1210 1210
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1211
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1211
+		if ($ignoreStatusCache || !$folderInfo || !is_array($folderInfo)) {
1212 1212
 			try
1213 1213
 			{
1214
-				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
1214
+				$folderInfo = $this->_getStatus($_folderName, $ignoreStatusCache);
1215 1215
 			}
1216 1216
 			catch (\Exception $e)
1217 1217
 			{
1218 1218
 				//error_log(__METHOD__.array2string($e));
1219
-				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1220
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1221
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1219
+				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : '')/*.function_backtrace()*/);
1220
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1221
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1222 1222
 				//throw new Exception(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1223
-				$folderInfo=null;
1223
+				$folderInfo = null;
1224 1224
 			}
1225 1225
 			if (!is_array($folderInfo))
1226 1226
 			{
1227 1227
 				// no folder info, but there is a status returned for the folder: something is wrong, try to cope with it
1228
-				$folderInfo = is_array($folderInfo)?$folderInfo:array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1228
+				$folderInfo = is_array($folderInfo) ? $folderInfo : array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1229 1229
 					'ATTRIBUTES' => '');
1230 1230
 				if (!isset($folderInfo['HIERACHY_DELIMITER']) || empty($folderInfo['HIERACHY_DELIMITER']) || (isset($folderInfo['delimiter']) && empty($folderInfo['delimiter'])))
1231 1231
 				{
@@ -1237,24 +1237,24 @@  discard block
 block discarded – undo
1237 1237
 		#if(!is_array($folderInfo)) {
1238 1238
 		#	return false;
1239 1239
 		#}
1240
-		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER']?$folderInfo['HIERACHY_DELIMITER']:$folderInfo['delimiter']);
1241
-		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES']?$folderInfo['ATTRIBUTES']:$folderInfo['attributes']);
1242
-		$shortNameParts			= explode($retValue['delimiter'], $_folderName);
1240
+		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER'] ? $folderInfo['HIERACHY_DELIMITER'] : $folderInfo['delimiter']);
1241
+		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES'] ? $folderInfo['ATTRIBUTES'] : $folderInfo['attributes']);
1242
+		$shortNameParts = explode($retValue['delimiter'], $_folderName);
1243 1243
 		$retValue['shortName']		= array_pop($shortNameParts);
1244 1244
 		$retValue['displayName']	= $_folderName;
1245
-		$retValue['shortDisplayName']	= $retValue['shortName'];
1246
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1247
-			$retValue['displayName']	= lang('INBOX');
1248
-			$retValue['shortDisplayName']	= lang('INBOX');
1245
+		$retValue['shortDisplayName'] = $retValue['shortName'];
1246
+		if (strtoupper($retValue['shortName']) == 'INBOX') {
1247
+			$retValue['displayName'] = lang('INBOX');
1248
+			$retValue['shortDisplayName'] = lang('INBOX');
1249 1249
 		}
1250 1250
 		// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
1251
-		elseif (in_array($retValue['shortName'],self::$autoFolders))
1251
+		elseif (in_array($retValue['shortName'], self::$autoFolders))
1252 1252
 		{
1253 1253
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1254 1254
 		}
1255
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1255
+		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName] = $retValue;
1256 1256
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1257
-		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1257
+		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']), 'noselect') !== false))
1258 1258
 		{
1259 1259
 			return $retValue;
1260 1260
 		}
@@ -1267,12 +1267,12 @@  discard block
 block discarded – undo
1267 1267
 		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1268 1268
 		if (!empty($nameSpace[$this->profileID]))
1269 1269
 		{
1270
-			$nsNoPersonal=array();
1271
-			foreach($nameSpace[$this->profileID] as &$ns)
1270
+			$nsNoPersonal = array();
1271
+			foreach ($nameSpace[$this->profileID] as &$ns)
1272 1272
 			{
1273
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1273
+				if ($ns['type'] != 'personal') $nsNoPersonal[] = $ns;
1274 1274
 			}
1275
-			$nameSpace[$this->profileID]=$nsNoPersonal;
1275
+			$nameSpace[$this->profileID] = $nsNoPersonal;
1276 1276
 		}
1277 1277
 		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1278 1278
 
@@ -1281,33 +1281,33 @@  discard block
 block discarded – undo
1281 1281
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1282 1282
 		}
1283 1283
 
1284
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1284
+		if ($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName, $subscribedFolders[$this->profileID])) {
1285 1285
 			$retValue['subscribed'] = true;
1286 1286
 		}
1287 1287
 
1288 1288
 		try
1289 1289
 		{
1290 1290
 			//$folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache);
1291
-			$folderStatus = $this->getMailBoxCounters($_folderName,false);
1292
-			$retValue['messages']		= $folderStatus['MESSAGES'];
1291
+			$folderStatus = $this->getMailBoxCounters($_folderName, false);
1292
+			$retValue['messages'] = $folderStatus['MESSAGES'];
1293 1293
 			$retValue['recent']		= $folderStatus['RECENT'];
1294
-			$retValue['uidnext']		= $folderStatus['UIDNEXT'];
1295
-			$retValue['uidvalidity']	= $folderStatus['UIDVALIDITY'];
1294
+			$retValue['uidnext'] = $folderStatus['UIDNEXT'];
1295
+			$retValue['uidvalidity'] = $folderStatus['UIDVALIDITY'];
1296 1296
 			$retValue['unseen']		= $folderStatus['UNSEEN'];
1297 1297
 			if (//$retValue['unseen']==0 &&
1298 1298
 				(isset($this->mailPreferences['trustServersUnseenInfo']) && // some servers dont serve the UNSEEN information
1299
-				$this->mailPreferences['trustServersUnseenInfo']==false) ||
1299
+				$this->mailPreferences['trustServersUnseenInfo'] == false) ||
1300 1300
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1301
-				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1302
-				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1301
+				$this->mailPreferences['trustServersUnseenInfo'] == 2 &&
1302
+				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName, $prefix[$this->profileID][$_folderName]) !== false)
1303 1303
 			)
1304 1304
 			{
1305 1305
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1306 1306
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1307 1307
 				try
1308 1308
 				{
1309
-					$byUid=true;
1310
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse=1, array('status'=>array('UNSEEN','UNDELETED')),$byUid,false);
1309
+					$byUid = true;
1310
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse = 1, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid, false);
1311 1311
 					$retValue['unseen'] = $sortResult['count'];
1312 1312
 				}
1313 1313
 				catch (\Exception $ee)
@@ -1318,7 +1318,7 @@  discard block
 block discarded – undo
1318 1318
 		}
1319 1319
 		catch (\Exception $e)
1320 1320
 		{
1321
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1321
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1322 1322
 		}
1323 1323
 
1324 1324
 		return $retValue;
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
 	 * @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))
1341 1341
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1342 1342
 	 */
1343
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1343
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true, $_fetchPreviews = false)
1344 1344
 	{
1345 1345
 		//self::$debug=true;
1346 1346
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 		$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
1354 1354
 		#print "<pre>";
1355 1355
 		#$this->icServer->setDebug(true);
1356
-		$total=0;
1356
+		$total = 0;
1357 1357
 		if ($_thisUIDOnly === null)
1358 1358
 		{
1359 1359
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1366,24 +1366,24 @@  discard block
 block discarded – undo
1366 1366
 				//$_filter['range'] ="$_startMessage:*";
1367 1367
 			}
1368 1368
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1369
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1369
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1370 1370
 			//see this example below for a 12 week datefilter (since)
1371 1371
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1372 1372
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1373 1373
 			$sortResult = $_sortResult['match']->ids;
1374 1374
 			//$modseq = $_sortResult['modseq'];
1375 1375
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1376
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1376
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1377 1377
 
1378 1378
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1379 1379
 			#$this->icServer->setDebug(false);
1380 1380
 			#print "</pre>";
1381 1381
 			// nothing found
1382
-			if(!is_array($sortResult) || empty($sortResult)) {
1382
+			if (!is_array($sortResult) || empty($sortResult)) {
1383 1383
 				$retValue = array();
1384 1384
 				$retValue['info']['total']	= 0;
1385 1385
 				$retValue['info']['first']	= 0;
1386
-				$retValue['info']['last']	= 0;
1386
+				$retValue['info']['last'] = 0;
1387 1387
 				return $retValue;
1388 1388
 			}
1389 1389
 
@@ -1391,54 +1391,54 @@  discard block
 block discarded – undo
1391 1391
 			#_debug_array($sortResult);
1392 1392
 			#_debug_array(array_slice($sortResult, -5, -2));
1393 1393
 			//error_log("REVERSE: $reverse");
1394
-			if($reverse === true) {
1395
-				if  ($_startMessage<=$total)
1394
+			if ($reverse === true) {
1395
+				if ($_startMessage <= $total)
1396 1396
 				{
1397
-					$startMessage = $_startMessage-1;
1397
+					$startMessage = $_startMessage - 1;
1398 1398
 				}
1399 1399
 				else
1400 1400
 				{
1401 1401
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1402
-					if ($_startMessage+$_numberOfMessages>$total)
1402
+					if ($_startMessage + $_numberOfMessages > $total)
1403 1403
 					{
1404
-						$numberOfMessages = $total%$_numberOfMessages;
1404
+						$numberOfMessages = $total % $_numberOfMessages;
1405 1405
 						//$numberOfMessages = abs($_startMessage-$total-1);
1406
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1406
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1407 1407
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1408 1408
 					}
1409
-					$startMessage=($total-$_numberOfMessages)-1;
1409
+					$startMessage = ($total - $_numberOfMessages) - 1;
1410 1410
 					//$retValue['info']['first'] = $startMessage;
1411 1411
 					//$retValue['info']['last'] = $total;
1412 1412
 
1413 1413
 				}
1414
-				if ($startMessage+$_numberOfMessages>$total)
1414
+				if ($startMessage + $_numberOfMessages > $total)
1415 1415
 				{
1416
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1416
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1417 1417
 					//$retValue['info']['first'] = $startMessage;
1418 1418
 					//$retValue['info']['last'] = $total;
1419 1419
 				}
1420
-				if($startMessage > 0) {
1421
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1422
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1420
+				if ($startMessage > 0) {
1421
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1422
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1423 1423
 				} else {
1424
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1425
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1424
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1425
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1426 1426
 				}
1427 1427
 				$sortResult = array_reverse($sortResult);
1428 1428
 			} else {
1429
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1430
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1429
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1430
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1431 1431
 			}
1432 1432
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1433 1433
 		}
1434 1434
 		else
1435 1435
 		{
1436
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1436
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1437 1437
 		}
1438 1438
 
1439 1439
 
1440 1440
 		// fetch the data for the selected messages
1441
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1441
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1442 1442
 		try
1443 1443
 		{
1444 1444
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1447,22 +1447,22 @@  discard block
 block discarded – undo
1447 1447
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1448 1448
 
1449 1449
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1450
-			$fquery->headers('fetchHeaders',array(
1451
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1452
-				'DATE','SUBJECT','FROM','TO','CC',
1450
+			$fquery->headers('fetchHeaders', array(
1451
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1452
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC',
1453 1453
 				'X-PRIORITY'
1454
-			),array(
1454
+			), array(
1455 1455
 				// Cache headers, we'll look at them below
1456
-				'cache' => true,//$_cacheResult,
1456
+				'cache' => true, //$_cacheResult,
1457 1457
 				// Set peek so messages are not flagged as read
1458 1458
 				'peek' => true
1459 1459
 			));
1460 1460
 			$fquery->size();
1461 1461
 			$fquery->structure();
1462 1462
 			$fquery->flags();
1463
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1463
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1464 1464
 			// if $_fetchPreviews is activated fetch part of the messages too
1465
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1465
+			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true, 'length'=>((int)$_fetchPreviews < 5000 ? 5000 : $_fetchPreviews), 'start'=>0));
1466 1466
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1467 1467
 				'ids' => $uidsToFetch,
1468 1468
 			));
@@ -1473,9 +1473,9 @@  discard block
 block discarded – undo
1473 1473
 			$headersNew = array();
1474 1474
 			$sortResult = array();
1475 1475
 		}
1476
-		if (self::$debug||self::$debugTimes)
1476
+		if (self::$debug || self::$debugTimes)
1477 1477
 		{
1478
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1478
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1479 1479
 			if (self::$debug)
1480 1480
 			{
1481 1481
 				$queryString = implode(',', $sortResult);
@@ -1485,27 +1485,27 @@  discard block
 block discarded – undo
1485 1485
 
1486 1486
 		$cnt = 0;
1487 1487
 
1488
-		foreach((array)$sortResult as $uid) {
1488
+		foreach ((array)$sortResult as $uid) {
1489 1489
 			$sortOrder[$uid] = $cnt++;
1490 1490
 		}
1491 1491
 
1492 1492
 		$count = 0;
1493 1493
 		if (is_object($headersNew)) {
1494
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1495
-			foreach($headersNew->ids() as $id) {
1494
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1495
+			foreach ($headersNew->ids() as $id) {
1496 1496
 				$_headerObject = $headersNew->get($id);
1497 1497
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1498 1498
 				$headerObject = array();
1499 1499
 				$bodyPreview = null;
1500
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1500
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1501 1501
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1502 1502
 				$headerObject['SIZE'] = $_headerObject->getSize();
1503 1503
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1504 1504
 
1505 1505
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1506
-				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1506
+				$headerForPrio = $_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1507 1507
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1508
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1508
+				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1509 1509
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1510 1510
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1511 1511
 				if ($_fetchPreviews)
@@ -1513,16 +1513,16 @@  discard block
 block discarded – undo
1513 1513
 					// on enabled preview $bodyPreview is needed lateron. fetched here, for fallback-reasons
1514 1514
 					// in case of failed Header-Retrieval
1515 1515
 					$bodyPreview = $_headerObject->getFullMsg();
1516
-					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1516
+					if (empty($headerForPrio) || (is_array($headerForPrio) && count($headerForPrio) === 1 && $headerForPrio['']))
1517 1517
 					{
1518 1518
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1519
-						if ($length===false) $length = strlen($bodyPreview);
1520
-						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1519
+						if ($length === false) $length = strlen($bodyPreview);
1520
+						$headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0, $length))->toArray();
1521 1521
 					}
1522 1522
 				}
1523 1523
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1524 1524
 				if (self::$debug) {
1525
-					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'));
1525
+					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'));
1526 1526
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1527 1527
 				}
1528 1528
 				// message deleted from server but cache still reporting its existence ; may happen on QRESYNC with No permanent modsequences
@@ -1531,21 +1531,21 @@  discard block
 block discarded – undo
1531 1531
 					$total--;
1532 1532
 					continue;
1533 1533
 				}
1534
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1534
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1535 1535
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1536
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1536
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1537 1537
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1538
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1538
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1539 1539
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1540 1540
 				} /*else $sent_not = "";*/
1541 1541
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1542 1542
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1543
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1544
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1543
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1544
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1545 1545
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1546
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1547
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1548
-				foreach (array('FROM','TO','CC') as $key)
1546
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1547
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1548
+				foreach (array('FROM', 'TO', 'CC') as $key)
1549 1549
 				{
1550 1550
 					$address = array();
1551 1551
 					foreach ($headerObject[$key] as $k => $ad)
@@ -1567,13 +1567,13 @@  discard block
 block discarded – undo
1567 1567
 						foreach ($rfcAddr as $_rfcAddr)
1568 1568
 						{
1569 1569
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1570
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1570
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1571 1571
 						}
1572 1572
 					}
1573 1573
 					$headerObject[$key] = $address;
1574 1574
 				}
1575 1575
 				$headerObject['FLAGS'] = $_headerObject->getFlags();
1576
-				$headerObject['BODYPREVIEW']=null;
1576
+				$headerObject['BODYPREVIEW'] = null;
1577 1577
 				// this section fetches part of the message-body (if enabled) for some kind of preview
1578 1578
 				// if we fail to succeed, we fall back to the retrieval of the message-body with
1579 1579
 				// fetchPartContents (see below, when we iterate over the structure to determine the
@@ -1585,17 +1585,17 @@  discard block
 block discarded – undo
1585 1585
 					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1586 1586
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1587 1587
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1588
-					foreach($base->partIterator() as $part)
1588
+					foreach ($base->partIterator() as $part)
1589 1589
 					{
1590 1590
 						//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
1591
-						if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
1591
+						if (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'text')
1592 1592
 						{
1593 1593
 							$charset = $part->getContentTypeParameter('charset');
1594 1594
 							$buffer = Mail\Html::convertHTMLToText($part->toString(array(
1595
-												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1595
+												'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
1596 1596
 											)), $charset, 'utf-8');
1597
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1598
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1597
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Translation::convert_jsonsafe($buffer), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1598
+						} elseif (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'multipart')
1599 1599
 						{
1600 1600
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1601 1601
 						}
@@ -1606,12 +1606,12 @@  discard block
 block discarded – undo
1606 1606
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1607 1607
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1608 1608
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1609
-				$headerObject['ATTACHMENTS']=null;
1610
-				$skipParts=array();
1611
-				$messageMimeType='';
1609
+				$headerObject['ATTACHMENTS'] = null;
1610
+				$skipParts = array();
1611
+				$messageMimeType = '';
1612 1612
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1613 1613
 				{
1614
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1614
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1615 1615
 					$part = $mailStructureObject->getPart($mime_id);
1616 1616
 					$partdisposition = $part->getDisposition();
1617 1617
 					$partPrimaryType = $part->getPrimaryType();
@@ -1619,16 +1619,16 @@  discard block
 block discarded – undo
1619 1619
 					// drawback here it is talking to the mailserver for each mail thus consuming
1620 1620
 					// more time than expected; so we call this section only when there is no
1621 1621
 					// bodypreview could be found (multipart/....)
1622
-					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1622
+					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW']) && ($partPrimaryType == 'text') &&
1623 1623
 						((intval($mime_id) === 1) || !$mime_id) &&
1624 1624
 						($partdisposition !== 'attachment')) {
1625
-							$_structure=$part;
1626
-							$this->fetchPartContents($uid, $_structure, false,true);
1627
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1628
-							$charSet=Translation::detect_encoding($headerObject['BODYPREVIEW']);
1625
+							$_structure = $part;
1626
+							$this->fetchPartContents($uid, $_structure, false, true);
1627
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1628
+							$charSet = Translation::detect_encoding($headerObject['BODYPREVIEW']);
1629 1629
 							// add line breaks to $bodyParts
1630 1630
 							//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
1631
-							$headerObject['BODYPREVIEW']  = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1631
+							$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1632 1632
 							//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
1633 1633
 					}
1634 1634
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
@@ -1638,28 +1638,28 @@  discard block
 block discarded – undo
1638 1638
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1639 1639
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1640 1640
 						// as attachment in order to not loose/miss information on our data
1641
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1641
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1642 1642
 					}
1643
-					if ($mime_type=='message/rfc822')
1643
+					if ($mime_type == 'message/rfc822')
1644 1644
 					{
1645 1645
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1646
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1646
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1647 1647
 					}
1648 1648
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1649
-					if (array_key_exists($mime_id,$skipParts)) continue;
1650
-					if ($partdisposition=='attachment' ||
1651
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1652
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1653
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1649
+					if (array_key_exists($mime_id, $skipParts)) continue;
1650
+					if ($partdisposition == 'attachment' ||
1651
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1652
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1653
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1654 1654
 					{
1655
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1656
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1657
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1655
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1656
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1657
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1658 1658
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1659
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1660
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1661
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1662
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1659
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1660
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1661
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1662
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1663 1663
 						{
1664 1664
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1665 1665
 						}
@@ -1674,54 +1674,54 @@  discard block
 block discarded – undo
1674 1674
 				if (empty($headerObject['UID'])) continue;
1675 1675
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1676 1676
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1677
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1677
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1678 1678
 					$headerObject['DATE'] .= 'C';
1679 1679
 				}
1680
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1680
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1681 1681
 					$headerObject['INTERNALDATE'] .= 'C';
1682 1682
 				}
1683 1683
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1684 1684
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1685
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1686
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1687
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1688
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1689
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1690
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1691
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1692
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1693
-				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1694
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1685
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1686
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1687
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1688
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1689
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1690
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1691
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1692
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1693
+				$retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW'];
1694
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1695 1695
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1696 1696
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1697 1697
 				if (is_array($headerObject['FLAGS'])) {
1698
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1698
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1699 1699
 				}
1700 1700
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1701
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1702
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1701
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1702
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1703 1703
 				}
1704
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1705
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1706
-					if (count($headerObject['TO'])>1)
1704
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1705
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1706
+					if (count($headerObject['TO']) > 1)
1707 1707
 					{
1708
-						$ki=0;
1709
-						foreach($headerObject['TO'] as $k => $add)
1708
+						$ki = 0;
1709
+						foreach ($headerObject['TO'] as $k => $add)
1710 1710
 						{
1711
-							if ($k==0) continue;
1711
+							if ($k == 0) continue;
1712 1712
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1713
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1713
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1714 1714
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1715 1715
 							$ki++;
1716 1716
 						}
1717 1717
 					}
1718 1718
 				}
1719
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1720
-					$ki=0;
1721
-					foreach($headerObject['CC'] as $k => $add)
1719
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1720
+					$ki = 0;
1721
+					foreach ($headerObject['CC'] as $k => $add)
1722 1722
 					{
1723 1723
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1724
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1724
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1725 1725
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1726 1726
 						$ki++;
1727 1727
 					}
@@ -1730,27 +1730,27 @@  discard block
 block discarded – undo
1730 1730
 
1731 1731
 				$count++;
1732 1732
 			}
1733
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1733
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1734 1734
 			//self::$debug=false;
1735 1735
 			// sort the messages to the requested displayorder
1736
-			if(is_array($retValue['header'])) {
1736
+			if (is_array($retValue['header'])) {
1737 1737
 				$countMessages = $total;
1738 1738
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1739 1739
 				ksort($retValue['header']);
1740 1740
 				$retValue['info']['total']	= $total;
1741 1741
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1742 1742
 				$retValue['info']['first']	= $_startMessage;
1743
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1743
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1744 1744
 				return $retValue;
1745 1745
 			} else {
1746 1746
 				$retValue = array();
1747 1747
 				$retValue['info']['total']	= 0;
1748 1748
 				$retValue['info']['first']	= 0;
1749
-				$retValue['info']['last']	= 0;
1749
+				$retValue['info']['last'] = 0;
1750 1750
 				return $retValue;
1751 1751
 			}
1752 1752
 		} else {
1753
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1753
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1754 1754
 			$retValue = array();
1755 1755
 			$retValue['info']['total']  = 0;
1756 1756
 			$retValue['info']['first']  = 0;
@@ -1767,17 +1767,17 @@  discard block
 block discarded – undo
1767 1767
 	 */
1768 1768
 	static function prepareFlagsArray($headerObject)
1769 1769
 	{
1770
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1770
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1771 1771
 		$retValue = array();
1772 1772
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1773 1773
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1774
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1775
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1774
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1775
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1776 1776
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1777
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1778
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1779
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1780
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1777
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1778
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1779
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1780
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1781 1781
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1782 1782
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1783 1783
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1801,12 +1801,12 @@  discard block
 block discarded – undo
1801 1801
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1802 1802
 	 * @return mixed bool/array false or array of ids
1803 1803
 	 */
1804
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1804
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1805 1805
 	{
1806 1806
 		static $cachedFolderStatus = null;
1807 1807
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1808 1808
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1809
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1809
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1810 1810
 		{
1811 1811
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1812 1812
 		}
@@ -1818,28 +1818,28 @@  discard block
 block discarded – undo
1818 1818
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1819 1819
 		$try2useCache = true;
1820 1820
 		static $eMailListContainsDeletedMessages = null;
1821
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1821
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1822 1822
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1823
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1823
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1824 1824
 		{
1825 1825
 			if (self::$debugTimes) $starttime = microtime(true);
1826
-			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);
1827
-			$five=true;
1828
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
1826
+			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);
1827
+			$five = true;
1828
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three = 1, array('status'=>array('DELETED')), $five, false);
1829 1829
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1830
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1831
-			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1832
-			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']);
1830
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1831
+			Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1832
+			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']);
1833 1833
 		}
1834 1834
 		$try2useCache = false;
1835 1835
 		//self::$supportsORinQuery[$this->profileID]=true;
1836 1836
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1837 1837
 		{
1838
-			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1839
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1838
+			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1839
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1840 1840
 		}
1841 1841
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1842
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1842
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1843 1843
 		if (self::$debug)
1844 1844
 		{
1845 1845
 			$query_str = $filter->build();
@@ -1847,14 +1847,14 @@  discard block
 block discarded – undo
1847 1847
 		}
1848 1848
 		//_debug_array($filter);
1849 1849
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1850
-		if($this->icServer->hasCapability('SORT')) {
1850
+		if ($this->icServer->hasCapability('SORT')) {
1851 1851
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1852 1852
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1853 1853
 			// there is no messing with the dates)
1854 1854
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1855 1855
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1856 1856
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1857
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1857
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1858 1858
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1859 1859
 			try
1860 1860
 			{
@@ -1862,24 +1862,24 @@  discard block
 block discarded – undo
1862 1862
 					'sort' => $sortOrder,));
1863 1863
 			// if there is an Error, we assume that the server is not capable of sorting
1864 1864
 			}
1865
-			catch(\Exception $e)
1865
+			catch (\Exception $e)
1866 1866
 			{
1867 1867
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1868 1868
 				$resultByUid = false;
1869 1869
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1870
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1870
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1871 1871
 				try
1872 1872
 				{
1873 1873
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1874 1874
 						'sort' => $sortOrder));
1875 1875
 				}
1876
-				catch(\Exception $e)
1876
+				catch (\Exception $e)
1877 1877
 				{
1878 1878
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1879 1879
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1880 1880
 				}
1881 1881
 			}
1882
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1882
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1883 1883
 		} else {
1884 1884
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1885 1885
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1889,12 +1889,12 @@  discard block
 block discarded – undo
1889 1889
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1890 1890
 					'sort' => $sortOrder)*/);
1891 1891
 			}
1892
-			catch(\Exception $e)
1892
+			catch (\Exception $e)
1893 1893
 			{
1894 1894
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1895 1895
 				// possible error OR Query. But Horde gives no detailed Info :-(
1896
-				self::$supportsORinQuery[$this->profileID]=false;
1897
-				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1896
+				self::$supportsORinQuery[$this->profileID] = false;
1897
+				Cache::setCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1898 1898
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1899 1899
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1900 1900
 				try
@@ -1902,25 +1902,25 @@  discard block
 block discarded – undo
1902 1902
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1903 1903
 						'sort' => $sortOrder)*/);
1904 1904
 				}
1905
-				catch(\Exception $e)
1905
+				catch (\Exception $e)
1906 1906
 				{
1907 1907
 				}
1908 1908
 			}
1909
-			if(is_array($sortResult['match'])) {
1909
+			if (is_array($sortResult['match'])) {
1910 1910
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1911 1911
 					sort($sortResult['match'], SORT_NUMERIC);
1912 1912
 			}
1913
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1913
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1914 1914
 		}
1915 1915
 		if ($setSession)
1916 1916
 		{
1917 1917
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1918
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1918
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1919 1919
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1920 1920
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1921
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1921
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1922 1922
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1923
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1923
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1924 1924
 		}
1925 1925
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1926 1926
 		//_debug_array($sortResult['match']->ids);
@@ -1934,12 +1934,12 @@  discard block
 block discarded – undo
1934 1934
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1935 1935
 	 * @return the sort sequence for horde search
1936 1936
 	 */
1937
-	function _getSortString($_sort, $_reverse=false)
1937
+	function _getSortString($_sort, $_reverse = false)
1938 1938
 	{
1939
-		$_reverse=false;
1939
+		$_reverse = false;
1940 1940
 		if (is_numeric($_sort))
1941 1941
 		{
1942
-			switch($_sort) {
1942
+			switch ($_sort) {
1943 1943
 				case 2:
1944 1944
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1945 1945
 					break;
@@ -1961,7 +1961,7 @@  discard block
 block discarded – undo
1961 1961
 		}
1962 1962
 		else
1963 1963
 		{
1964
-			switch(strtoupper($_sort)) {
1964
+			switch (strtoupper($_sort)) {
1965 1965
 				case 'FROMADDRESS':
1966 1966
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1967 1967
 					break;
@@ -1987,7 +1987,7 @@  discard block
 block discarded – undo
1987 1987
 					break;
1988 1988
 			}
1989 1989
 		}
1990
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
1990
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
1991 1991
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1992 1992
 		return $retValue;
1993 1993
 	}
@@ -2000,28 +2000,28 @@  discard block
 block discarded – undo
2000 2000
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
2001 2001
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
2002 2002
 	 */
2003
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
2003
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
2004 2004
 	{
2005 2005
 		$imapFilter = new Horde_Imap_Client_Search_Query();
2006 2006
 		$imapFilter->charset('UTF-8');
2007 2007
 
2008 2008
 		//_debug_array($_criterias);
2009
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2010
-		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2009
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
2010
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') &&
2011 2011
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2012
-			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
2013
-			( !empty($_criterias['range'])&& ($_criterias['range']!='BETWEEN' && empty($_criterias['date'])||
2014
-			($_criterias['range']=='BETWEEN' && empty($_criterias['since'])&& empty($_criterias['before']))))))
2012
+			(!isset($_criterias['range']) || empty($_criterias['range']) ||
2013
+			(!empty($_criterias['range']) && ($_criterias['range'] != 'BETWEEN' && empty($_criterias['date']) ||
2014
+			($_criterias['range'] == 'BETWEEN' && empty($_criterias['since']) && empty($_criterias['before']))))))
2015 2015
 		{
2016 2016
 			//error_log(__METHOD__.' ('.__LINE__.') returning early Criterias:'.print_r($_criterias, true));
2017
-			$imapFilter->flag('DELETED', $set=false);
2017
+			$imapFilter->flag('DELETED', $set = false);
2018 2018
 			return $imapFilter;
2019 2019
 		}
2020 2020
 		$queryValid = false;
2021 2021
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2022 2022
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2023 2023
 		$statusQueryValid = false;
2024
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2024
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
2025 2025
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2026 2026
 			$imapStatusFilter->charset('UTF-8');
2027 2027
 			$criteria = strtoupper($criteria);
@@ -2031,12 +2031,12 @@  discard block
 block discarded – undo
2031 2031
 				case 'FLAGGED':
2032 2032
 				case 'RECENT':
2033 2033
 				case 'SEEN':
2034
-					$imapStatusFilter->flag($criteria, $set=true);
2035
-					$queryValid = $statusQueryValid =true;
2034
+					$imapStatusFilter->flag($criteria, $set = true);
2035
+					$queryValid = $statusQueryValid = true;
2036 2036
 					break;
2037 2037
 				case 'READ':
2038
-					$imapStatusFilter->flag('SEEN', $set=true);
2039
-					$queryValid = $statusQueryValid =true;
2038
+					$imapStatusFilter->flag('SEEN', $set = true);
2039
+					$queryValid = $statusQueryValid = true;
2040 2040
 					break;
2041 2041
 				case 'LABEL1':
2042 2042
 				case 'KEYWORD1':
@@ -2048,38 +2048,38 @@  discard block
 block discarded – undo
2048 2048
 				case 'KEYWORD4':
2049 2049
 				case 'LABEL5':
2050 2050
 				case 'KEYWORD5':
2051
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
2052
-					$queryValid = $statusQueryValid =true;
2051
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
2052
+					$queryValid = $statusQueryValid = true;
2053 2053
 					break;
2054 2054
 				case 'NEW':
2055
-					$imapStatusFilter->flag('RECENT', $set=true);
2056
-					$imapStatusFilter->flag('SEEN', $set=false);
2057
-					$queryValid = $statusQueryValid =true;
2055
+					$imapStatusFilter->flag('RECENT', $set = true);
2056
+					$imapStatusFilter->flag('SEEN', $set = false);
2057
+					$queryValid = $statusQueryValid = true;
2058 2058
 					break;
2059 2059
 				case 'OLD':
2060
-					$imapStatusFilter->flag('RECENT', $set=false);
2061
-					$queryValid = $statusQueryValid =true;
2060
+					$imapStatusFilter->flag('RECENT', $set = false);
2061
+					$queryValid = $statusQueryValid = true;
2062 2062
 					break;
2063 2063
 // operate only on system flags
2064 2064
 //        $systemflags = array(
2065 2065
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
2066 2066
 //        );
2067 2067
 				case 'UNANSWERED':
2068
-					$imapStatusFilter->flag('ANSWERED', $set=false);
2069
-					$queryValid = $statusQueryValid =true;
2068
+					$imapStatusFilter->flag('ANSWERED', $set = false);
2069
+					$queryValid = $statusQueryValid = true;
2070 2070
 					break;
2071 2071
 				case 'UNDELETED':
2072
-					$imapFilter->flag('DELETED', $set=false);
2072
+					$imapFilter->flag('DELETED', $set = false);
2073 2073
 					$queryValid = true;
2074 2074
 					break;
2075 2075
 				case 'UNFLAGGED':
2076
-					$imapStatusFilter->flag('FLAGGED', $set=false);
2077
-					$queryValid = $statusQueryValid =true;
2076
+					$imapStatusFilter->flag('FLAGGED', $set = false);
2077
+					$queryValid = $statusQueryValid = true;
2078 2078
 					break;
2079 2079
 				case 'UNREAD':
2080 2080
 				case 'UNSEEN':
2081
-					$imapStatusFilter->flag('SEEN', $set=false);
2082
-					$queryValid = $statusQueryValid =true;
2081
+					$imapStatusFilter->flag('SEEN', $set = false);
2082
+					$queryValid = $statusQueryValid = true;
2083 2083
 					break;
2084 2084
 				case 'UNLABEL1':
2085 2085
 				case 'UNKEYWORD1':
@@ -2091,8 +2091,8 @@  discard block
 block discarded – undo
2091 2091
 				case 'UNKEYWORD4':
2092 2092
 				case 'UNLABEL5':
2093 2093
 				case 'UNKEYWORD5':
2094
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
2095
-					$queryValid = $statusQueryValid =true;
2094
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
2095
+					$queryValid = $statusQueryValid = true;
2096 2096
 					break;
2097 2097
 				default:
2098 2098
 					$statusQueryValid = false;
@@ -2108,20 +2108,20 @@  discard block
 block discarded – undo
2108 2108
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2109 2109
 		$imapSearchFilter->charset('UTF-8');
2110 2110
 
2111
-		if(!empty($_criterias['string'])) {
2111
+		if (!empty($_criterias['string'])) {
2112 2112
 			$criteria = strtoupper($_criterias['type']);
2113 2113
 			switch ($criteria) {
2114 2114
 				case 'BYDATE':
2115 2115
 				case 'QUICK':
2116 2116
 				case 'QUICKWITHCC':
2117
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
2117
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
2118 2118
 					//$imapSearchFilter->charset('UTF-8');
2119 2119
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2120 2120
 					$imapFilter2->charset('UTF-8');
2121
-					if($this->isSentFolder($_folder)) {
2122
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2121
+					if ($this->isSentFolder($_folder)) {
2122
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
2123 2123
 					} else {
2124
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2124
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
2125 2125
 					}
2126 2126
 					if ($_supportsOrInQuery)
2127 2127
 					{
@@ -2131,31 +2131,31 @@  discard block
 block discarded – undo
2131 2131
 					{
2132 2132
 						$imapSearchFilter->andSearch($imapFilter2);
2133 2133
 					}
2134
-					if ($_supportsOrInQuery && $criteria=='QUICKWITHCC')
2134
+					if ($_supportsOrInQuery && $criteria == 'QUICKWITHCC')
2135 2135
 					{
2136 2136
 						$imapFilter3 = new Horde_Imap_Client_Search_Query();
2137 2137
 						$imapFilter3->charset('UTF-8');
2138
-						$imapFilter3->headerText('CC', $_criterias['string'], $not=false);
2138
+						$imapFilter3->headerText('CC', $_criterias['string'], $not = false);
2139 2139
 						$imapSearchFilter->orSearch($imapFilter3);
2140 2140
 					}
2141 2141
 					$queryValid = true;
2142 2142
 					break;
2143 2143
 				case 'LARGER':
2144 2144
 				case 'SMALLER':
2145
-					if (strlen(trim($_criterias['string'])) != strlen((float) trim($_criterias['string'])))
2145
+					if (strlen(trim($_criterias['string'])) != strlen((float)trim($_criterias['string'])))
2146 2146
 					{
2147 2147
 						//examine string to evaluate size
2148
-						$unit = strtoupper(trim(substr(trim($_criterias['string']),strlen((float) trim($_criterias['string'])))));
2149
-						$multipleBy = array('KB'=>1024,'K'=>1024,
2150
-											'MB'=>1024*1000,'M'=>1024*1000,
2151
-											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2152
-											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2153
-						$numberinBytes=(float)$_criterias['string'];
2154
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2148
+						$unit = strtoupper(trim(substr(trim($_criterias['string']), strlen((float)trim($_criterias['string'])))));
2149
+						$multipleBy = array('KB'=>1024, 'K'=>1024,
2150
+											'MB'=>1024 * 1000, 'M'=>1024 * 1000,
2151
+											'GB'=>1024 * 1000 * 1000, 'G'=>1024 * 1000 * 1000,
2152
+											'TB'=>1024 * 1000 * 1000 * 1000, 'T'=>1024 * 1000 * 1000 * 1000);
2153
+						$numberinBytes = (float)$_criterias['string'];
2154
+						if (isset($multipleBy[$unit])) $numberinBytes = (float)$_criterias['string'] * $multipleBy[$unit];
2155 2155
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2156
-						$_criterias['string']=$numberinBytes;
2156
+						$_criterias['string'] = $numberinBytes;
2157 2157
 					}
2158
-					$imapSearchFilter->size( $_criterias['string'], ($criteria=='LARGER'?true:false), $not=false);
2158
+					$imapSearchFilter->size($_criterias['string'], ($criteria == 'LARGER' ? true : false), $not = false);
2159 2159
 					//$imapSearchFilter->charset('UTF-8');
2160 2160
 					$queryValid = true;
2161 2161
 					break;
@@ -2164,31 +2164,31 @@  discard block
 block discarded – undo
2164 2164
 				case 'CC':
2165 2165
 				case 'BCC':
2166 2166
 				case 'SUBJECT':
2167
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
2167
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
2168 2168
 					//$imapSearchFilter->charset('UTF-8');
2169 2169
 					$queryValid = true;
2170 2170
 					break;
2171 2171
 				case 'BODY':
2172 2172
 				case 'TEXT':
2173
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2173
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ? true : false), $not = false);
2174 2174
 					//$imapSearchFilter->charset('UTF-8');
2175 2175
 					$queryValid = true;
2176 2176
 					break;
2177 2177
 				case 'SINCE':
2178
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2178
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2179 2179
 					$queryValid = true;
2180 2180
 					break;
2181 2181
 				case 'BEFORE':
2182
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2182
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2183 2183
 					$queryValid = true;
2184 2184
 					break;
2185 2185
 				case 'ON':
2186
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2186
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2187 2187
 					$queryValid = true;
2188 2188
 					break;
2189 2189
 			}
2190 2190
 		}
2191
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2191
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2192 2192
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2193 2193
 
2194 2194
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2197,12 +2197,12 @@  discard block
 block discarded – undo
2197 2197
 			$imapRangeFilter = new Horde_Imap_Client_Search_Query();
2198 2198
 			$imapRangeFilter->charset('UTF-8');
2199 2199
 			$criteria = strtoupper($_criterias['range']);
2200
-			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since']==$_criterias['before'])
2200
+			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since'] == $_criterias['before'])
2201 2201
 			{
2202
-				$_criterias['date']=$_criterias['since'];
2202
+				$_criterias['date'] = $_criterias['since'];
2203 2203
 				unset($_criterias['since']);
2204 2204
 				unset($_criterias['before']);
2205
-				$criteria=$_criterias['range']='ON';
2205
+				$criteria = $_criterias['range'] = 'ON';
2206 2206
 			}
2207 2207
 			switch ($criteria) {
2208 2208
 				case 'BETWEEN':
@@ -2210,7 +2210,7 @@  discard block
 block discarded – undo
2210 2210
 					//enddate
2211 2211
 					if ($_criterias['since'])
2212 2212
 					{
2213
-						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2213
+						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2214 2214
 						$rangeValid = true;
2215 2215
 					}
2216 2216
 					//startdate
@@ -2219,28 +2219,28 @@  discard block
 block discarded – undo
2219 2219
 						$imapRangeFilter2 = new Horde_Imap_Client_Search_Query();
2220 2220
 						$imapRangeFilter2->charset('UTF-8');
2221 2221
 						//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2222
-						$_criterias['before'] = date("d-M-Y",DateTime::to($_criterias['before'],'ts')+(3600*24));
2223
-						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2222
+						$_criterias['before'] = date("d-M-Y", DateTime::to($_criterias['before'], 'ts') + (3600 * 24));
2223
+						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2224 2224
 						$imapRangeFilter->andSearch($imapRangeFilter2);
2225 2225
 						$rangeValid = true;
2226 2226
 					}
2227 2227
 					break;
2228 2228
 				case 'SINCE'://enddate
2229
-					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since']?$_criterias['since']:$_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2229
+					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since'] ? $_criterias['since'] : $_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2230 2230
 					$rangeValid = true;
2231 2231
 					break;
2232 2232
 				case 'BEFORE'://startdate
2233 2233
 					//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2234
-					$_criterias['before'] = date("d-M-Y",DateTime::to(($_criterias['before']?$_criterias['before']:$_criterias['date']),'ts')+(3600*24));
2235
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2234
+					$_criterias['before'] = date("d-M-Y", DateTime::to(($_criterias['before'] ? $_criterias['before'] : $_criterias['date']), 'ts') + (3600 * 24));
2235
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2236 2236
 					$rangeValid = true;
2237 2237
 					break;
2238 2238
 				case 'ON':
2239
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2239
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2240 2240
 					$rangeValid = true;
2241 2241
 					break;
2242 2242
 			}
2243
-			if ($rangeValid && !$queryValid) $queryValid=true;
2243
+			if ($rangeValid && !$queryValid) $queryValid = true;
2244 2244
 			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2245 2245
 		}
2246 2246
 		if (self::$debug)
@@ -2249,8 +2249,8 @@  discard block
 block discarded – undo
2249 2249
 			$query_str = $imapFilter->build();
2250 2250
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2251 2251
 		}
2252
-		if($queryValid==false) {
2253
-			$imapFilter->flag('DELETED', $set=false);
2252
+		if ($queryValid == false) {
2253
+			$imapFilter->flag('DELETED', $set = false);
2254 2254
 			return $imapFilter;
2255 2255
 		} else {
2256 2256
 			return $imapFilter;
@@ -2264,11 +2264,11 @@  discard block
 block discarded – undo
2264 2264
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2265 2265
 	 * @return mixed - based on the input type
2266 2266
 	 */
2267
-	static function decode_header($_string, $_tryIDNConversion=false)
2267
+	static function decode_header($_string, $_tryIDNConversion = false)
2268 2268
 	{
2269 2269
 		if (is_array($_string))
2270 2270
 		{
2271
-			foreach($_string as $k=>$v)
2271
+			foreach ($_string as $k=>$v)
2272 2272
 			{
2273 2273
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2274 2274
 			}
@@ -2276,18 +2276,18 @@  discard block
 block discarded – undo
2276 2276
 		}
2277 2277
 		else
2278 2278
 		{
2279
-			$_string = Mail\Html::decodeMailHeader($_string,self::$displayCharset);
2279
+			$_string = Mail\Html::decodeMailHeader($_string, self::$displayCharset);
2280 2280
 			$test = @json_encode($_string);
2281 2281
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2282
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2282
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2283 2283
 			{
2284 2284
 				// try to fix broken utf8
2285 2285
 				$x = utf8_encode($_string);
2286 2286
 				$test = @json_encode($x);
2287
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2287
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2288 2288
 				{
2289 2289
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2290
-					$_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));
2290
+					$_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));
2291 2291
 				}
2292 2292
 				else
2293 2293
 				{
@@ -2295,7 +2295,7 @@  discard block
 block discarded – undo
2295 2295
 				}
2296 2296
 			}
2297 2297
 
2298
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2298
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2299 2299
 			{
2300 2300
 				$rfcAddr = self::parseAddressList($_string);
2301 2301
 				$stringA = array();
@@ -2307,11 +2307,11 @@  discard block
 block discarded – undo
2307 2307
 						$stringA = array();
2308 2308
 						break; // skip idna conversion if we encounter an error here
2309 2309
 					}
2310
-					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2310
+					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, Horde_Idna::decode($_rfcAddr->host), $_rfcAddr->personal);
2311 2311
 				}
2312
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2312
+				if (!empty($stringA)) $_string = implode(',', $stringA);
2313 2313
 			}
2314
-			if ($_tryIDNConversion==='FORCE')
2314
+			if ($_tryIDNConversion === 'FORCE')
2315 2315
 			{
2316 2316
 				//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.Horde_Idna::decode($_string));
2317 2317
 				$_string = Horde_Idna::decode($_string);
@@ -2327,17 +2327,17 @@  discard block
 block discarded – undo
2327 2327
 	 * @param  boolean $decode try decoding
2328 2328
 	 * @return mixed - based on the input type
2329 2329
 	 */
2330
-	function decode_subject($_string,$decode=true)
2330
+	function decode_subject($_string, $decode = true)
2331 2331
 	{
2332 2332
 		#$string = $_string;
2333
-		if($_string=='NIL')
2333
+		if ($_string == 'NIL')
2334 2334
 		{
2335 2335
 			return 'No Subject';
2336 2336
 		}
2337 2337
 		if ($decode) $_string = self::decode_header($_string);
2338 2338
 		// make sure its utf-8
2339 2339
 		$test = @json_encode($_string);
2340
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2340
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2341 2341
 		{
2342 2342
 			$_string = utf8_encode($_string);
2343 2343
 		}
@@ -2389,18 +2389,18 @@  discard block
 block discarded – undo
2389 2389
 	function createFolder($_parent, $_folderName, &$_error)
2390 2390
 	{
2391 2391
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2392
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2393
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2392
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2393
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2394 2394
 
2395
-		if(empty($parent)) {
2395
+		if (empty($parent)) {
2396 2396
 			$newFolderName = $folderName;
2397 2397
 		} else {
2398 2398
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2399
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2399
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2400 2400
 		}
2401 2401
 		if (empty($newFolderName)) return false;
2402 2402
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2403
-		if ($this->folderExists($newFolderName,true))
2403
+		if ($this->folderExists($newFolderName, true))
2404 2404
 		{
2405 2405
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2406 2406
 			return $newFolderName;
@@ -2417,7 +2417,7 @@  discard block
 block discarded – undo
2417 2417
 		}
2418 2418
 		catch (\Exception $e)
2419 2419
 		{
2420
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2420
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2421 2421
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2422 2422
 			return false;
2423 2423
 		}
@@ -2446,15 +2446,15 @@  discard block
 block discarded – undo
2446 2446
 	 */
2447 2447
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2448 2448
 	{
2449
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2450
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2451
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2449
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2450
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2451
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2452 2452
 
2453
-		if(empty($parent)) {
2453
+		if (empty($parent)) {
2454 2454
 			$newFolderName = $folderName;
2455 2455
 		} else {
2456 2456
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2457
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2457
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2458 2458
 		}
2459 2459
 		if (self::$debug) error_log("create folder: $newFolderName");
2460 2460
 		try
@@ -2463,10 +2463,10 @@  discard block
 block discarded – undo
2463 2463
 		}
2464 2464
 		catch (\Exception $e)
2465 2465
 		{
2466
-			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2466
+			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2467 2467
 		}
2468 2468
 		// clear FolderExistsInfoCache
2469
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2469
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2470 2470
 
2471 2471
 		return $newFolderName;
2472 2472
 
@@ -2485,15 +2485,15 @@  discard block
 block discarded – undo
2485 2485
 		//$folderName = $this->_encodeFolderName($_folderName);
2486 2486
 		try
2487 2487
 		{
2488
-			$this->icServer->subscribeMailbox($_folderName,false);
2488
+			$this->icServer->subscribeMailbox($_folderName, false);
2489 2489
 			$this->icServer->deleteMailbox($_folderName);
2490 2490
 		}
2491 2491
 		catch (\Exception $e)
2492 2492
 		{
2493
-			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2493
+			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2494 2494
 		}
2495 2495
 		// clear FolderExistsInfoCache
2496
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2496
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2497 2497
 
2498 2498
 		return true;
2499 2499
 	}
@@ -2528,10 +2528,10 @@  discard block
 block discarded – undo
2528 2528
 	 *
2529 2529
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2530 2530
 	 */
2531
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2531
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2532 2532
 	{
2533 2533
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2534
-		if (self::$debugTimes) $starttime = microtime (true);
2534
+		if (self::$debugTimes) $starttime = microtime(true);
2535 2535
 		static $folders2return;
2536 2536
 		//$_subscribedOnly=false;
2537 2537
 		// always use static on single request if info is available;
@@ -2539,42 +2539,42 @@  discard block
 block discarded – undo
2539 2539
 		// set $_useCacheIfPossible to false !
2540 2540
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2541 2541
 		{
2542
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2542
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2543 2543
 			return $folders2return[$this->icServer->ImapServerId];
2544 2544
 		}
2545 2545
 
2546
-		if ($_subscribedOnly && $_getCounters===false)
2546
+		if ($_subscribedOnly && $_getCounters === false)
2547 2547
 		{
2548
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2548
+			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2549 2549
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2550 2550
 			{
2551 2551
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2552
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2552
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2553 2553
 				return $folders2return[$this->icServer->ImapServerId];
2554 2554
 			}
2555 2555
 		}
2556 2556
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2557 2557
 		static $folderBasicInfo;
2558
-		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);
2558
+		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);
2559 2559
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2560 2560
 
2561 2561
 		$delimiter = $this->getHierarchyDelimiter();
2562 2562
 
2563 2563
 		$inboxData = new \stdClass;
2564
-		$inboxData->name 		= 'INBOX';
2564
+		$inboxData->name = 'INBOX';
2565 2565
 		$inboxData->folderName		= 'INBOX';
2566
-		$inboxData->displayName		= lang('INBOX');
2566
+		$inboxData->displayName = lang('INBOX');
2567 2567
 		$inboxData->delimiter 		= $delimiter;
2568
-		$inboxData->shortFolderName	= 'INBOX';
2569
-		$inboxData->shortDisplayName	= lang('INBOX');
2568
+		$inboxData->shortFolderName = 'INBOX';
2569
+		$inboxData->shortDisplayName = lang('INBOX');
2570 2570
 		$inboxData->subscribed = true;
2571
-		if($_getCounters == true) {
2571
+		if ($_getCounters == true) {
2572 2572
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2573 2573
 		}
2574 2574
 		// force unsubscribed by preference showAllFoldersInFolderPane
2575 2575
 		if ($_subscribedOnly == true &&
2576 2576
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2577
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2577
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2578 2578
 		{
2579 2579
 			$_subscribedOnly = false;
2580 2580
 		}
@@ -2587,12 +2587,12 @@  discard block
 block discarded – undo
2587 2587
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2588 2588
 		if (is_array($nameSpace))
2589 2589
 		{
2590
-			foreach($nameSpace as $k => $singleNameSpace) {
2590
+			foreach ($nameSpace as $k => $singleNameSpace) {
2591 2591
 				$type = $singleNameSpace['type'];
2592 2592
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2593
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2593
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2594 2594
 
2595
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2595
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2596 2596
 					// fetch and sort the subscribed folders
2597 2597
 					// we alway fetch the subscribed, as this provides the only way to tell
2598 2598
 					// if a folder is subscribed or not
@@ -2600,22 +2600,22 @@  discard block
 block discarded – undo
2600 2600
 					{
2601 2601
 						try
2602 2602
 						{
2603
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2603
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2604 2604
 							if (!empty($subscribedMailboxes))
2605 2605
 							{
2606 2606
 								$fetchedAllInOneGo = true;
2607 2607
 							}
2608 2608
 							else
2609 2609
 							{
2610
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2610
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2611 2611
 							}
2612 2612
 						}
2613
-						catch(Exception $e)
2613
+						catch (Exception $e)
2614 2614
 						{
2615 2615
 							continue;
2616 2616
 						}
2617 2617
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2618
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2618
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ? array_keys($subscribedMailboxes) : array());
2619 2619
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2620 2620
 						//_debug_array($foldersNameSpace);
2621 2621
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2625,18 +2625,18 @@  discard block
 block discarded – undo
2625 2625
 							foreach ($subscribedMailboxes as $k => $finfo)
2626 2626
 							{
2627 2627
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2628
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2629
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2628
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2629
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2630 2630
 									'MAILBOX'=>$finfo['MAILBOX'],
2631 2631
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2632
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2633
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2632
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2633
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2634 2634
 								);
2635
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2635
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2636 2636
 								{
2637 2637
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2638 2638
 								}
2639
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2639
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2640 2640
 								{
2641 2641
 									$foldersNameSpace[$type]['all'][] = $k;
2642 2642
 								}
@@ -2659,7 +2659,7 @@  discard block
 block discarded – undo
2659 2659
 						// that may produce problems, when encountering recursions probably
2660 2660
 						// horde is handling that, so we do not; keep that in mind!
2661 2661
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2662
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2662
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2663 2663
 					}
2664 2664
 					catch (\Exception $e)
2665 2665
 					{
@@ -2677,26 +2677,26 @@  discard block
 block discarded – undo
2677 2677
 					foreach ($allMailboxesExt as $mbx) {
2678 2678
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2679 2679
 						{
2680
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2680
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2681 2681
 								'MAILBOX'=>$mbx['MAILBOX'],
2682 2682
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2683
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2684
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2683
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2684
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2685 2685
 							);
2686 2686
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2687 2687
 							{
2688 2688
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2689 2689
 							}
2690 2690
 						}
2691
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2691
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2692 2692
 						{
2693 2693
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2694 2694
 						}
2695 2695
 						//echo __METHOD__;_debug_array($mbx);
2696 2696
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2697
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2698
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2699
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2697
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2698
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2699
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2700 2700
 						) continue;
2701 2701
 
2702 2702
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2706,7 +2706,7 @@  discard block
 block discarded – undo
2706 2706
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2707 2707
 					$allMailboxes = array();
2708 2708
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2709
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2709
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2710 2710
 						//echo "Result:";_debug_array($allMailboxes);
2711 2711
 					}
2712 2712
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2715,57 +2715,57 @@  discard block
 block discarded – undo
2715 2715
 			}
2716 2716
 		}
2717 2717
 		//subscribed folders may be used in getFolderStatus
2718
-		Cache::setCache(Cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2718
+		Cache::setCache(Cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2719 2719
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2720 2720
 		$autoFolderObjects = $folders = array();
2721 2721
 		$autofolder_exists = array();
2722
-		foreach( array('personal', 'others', 'shared') as $type) {
2723
-			if(isset($foldersNameSpace[$type])) {
2724
-				if($_subscribedOnly) {
2725
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2722
+		foreach (array('personal', 'others', 'shared') as $type) {
2723
+			if (isset($foldersNameSpace[$type])) {
2724
+				if ($_subscribedOnly) {
2725
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2726 2726
 				} else {
2727
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2727
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2728 2728
 				}
2729
-				foreach((array)$listOfFolders as $folderName) {
2729
+				foreach ((array)$listOfFolders as $folderName) {
2730 2730
 					//echo "<br>FolderToCheck:$folderName<br>";
2731 2731
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2732
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2733
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2732
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2733
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2734 2734
 						#echo "$folderName failed to be here <br>";
2735 2735
 						continue;
2736 2736
 					}
2737 2737
 					if (isset($folders[$folderName])) continue;
2738 2738
 					if (isset($autoFolderObjects[$folderName])) continue;
2739
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2739
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2740 2740
 					$folderParts = explode($delimiter, $folderName);
2741 2741
 					$shortName = array_pop($folderParts);
2742 2742
 
2743 2743
 					$folderObject = new \stdClass;
2744
-					$folderObject->delimiter	= $delimiter;
2745
-					$folderObject->folderName	= $folderName;
2746
-					$folderObject->shortFolderName	= $shortName;
2747
-					if(!$_subscribedOnly) {
2744
+					$folderObject->delimiter = $delimiter;
2745
+					$folderObject->folderName = $folderName;
2746
+					$folderObject->shortFolderName = $shortName;
2747
+					if (!$_subscribedOnly) {
2748 2748
 						#echo $folderName."->".$type."<br>";
2749 2749
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2750 2750
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2751 2751
 					}
2752 2752
 
2753
-					if($_getCounters == true) {
2753
+					if ($_getCounters == true) {
2754 2754
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2755 2755
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2756 2756
 					}
2757
-					if(strtoupper($folderName) == 'INBOX') {
2757
+					if (strtoupper($folderName) == 'INBOX') {
2758 2758
 						$folderName = 'INBOX';
2759
-						$folderObject->folderName	= 'INBOX';
2760
-						$folderObject->shortFolderName	= 'INBOX';
2761
-						$folderObject->displayName	= lang('INBOX');
2759
+						$folderObject->folderName = 'INBOX';
2760
+						$folderObject->shortFolderName = 'INBOX';
2761
+						$folderObject->displayName = lang('INBOX');
2762 2762
 						$folderObject->shortDisplayName = lang('INBOX');
2763
-						$folderObject->subscribed	= true;
2763
+						$folderObject->subscribed = true;
2764 2764
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2765
-					} elseif (in_array($shortName,self::$autoFolders)) {
2766
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2765
+					} elseif (in_array($shortName, self::$autoFolders)) {
2766
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2767 2767
 						array_pop($tmpfolderparts);
2768
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2768
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2769 2769
 						$folderObject->shortDisplayName = lang($shortName);
2770 2770
 						unset($tmpfolderparts);
2771 2771
 					} else {
@@ -2773,13 +2773,13 @@  discard block
 block discarded – undo
2773 2773
 						$folderObject->shortDisplayName = $shortName;
2774 2774
 					}
2775 2775
 					//$folderName = $folderName;
2776
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2776
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2777 2777
 						$autoFolderObjects[$folderName] = $folderObject;
2778 2778
 					} else {
2779 2779
 						$folders[$folderName] = $folderObject;
2780 2780
 					}
2781 2781
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2782
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2782
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2783 2783
 					if (isset(self::$specialUseFolders[$folderName]))
2784 2784
 					{
2785 2785
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2788,27 +2788,27 @@  discard block
 block discarded – undo
2788 2788
 			}
2789 2789
 		}
2790 2790
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2791
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2791
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2792 2792
 		}
2793 2793
 		// check if some standard folders are missing and need to be created
2794 2794
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2795 2795
 		{
2796 2796
 			// if new folders have been created, re-read folders ignoring the cache
2797
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2797
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2798 2798
 		}
2799
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2799
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2800 2800
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2801 2801
 		//_debug_array($folders2return); #exit;
2802
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2803
-		if (($_subscribedOnly && $_getCounters===false) ||
2804
-			($_subscribedOnly == false && $_getCounters===false &&
2802
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2803
+		if (($_subscribedOnly && $_getCounters === false) ||
2804
+			($_subscribedOnly == false && $_getCounters === false &&
2805 2805
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2806
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2806
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2807 2807
 		{
2808
-			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2808
+			Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2809 2809
 		}
2810
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2811
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2810
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2811
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2812 2812
 		return $folders2return[$this->icServer->ImapServerId];
2813 2813
 	}
2814 2814
 
@@ -2829,21 +2829,21 @@  discard block
 block discarded – undo
2829 2829
 	 *
2830 2830
 	 * @return array arrays of folders
2831 2831
 	 */
2832
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2832
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2833 2833
 	{
2834 2834
 		// delimiter
2835 2835
 		$delimiter = $this->getHierarchyDelimiter();
2836 2836
 
2837
-		$folders = $nameSpace =  array();
2837
+		$folders = $nameSpace = array();
2838 2838
 		$nameSpaceTmp = $this->_getNameSpaces();
2839
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2840
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2839
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2840
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2841 2841
 		}
2842 2842
 		unset($nameSpaceTmp);
2843 2843
 
2844 2844
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2845 2845
 		// Get special use folders
2846
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2846
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2847 2847
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2848 2848
 		if ($_onlyTopLevel) // top level leaves
2849 2849
 		{
@@ -2854,20 +2854,20 @@  discard block
 block discarded – undo
2854 2854
 			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
2855 2855
 			if (self::$mailConfig['examineNamespace'])
2856 2856
 			{
2857
-				$prefixes=array();
2857
+				$prefixes = array();
2858 2858
 				if (is_array($nameSpace))
2859 2859
 				{
2860
-					foreach($nameSpace as $k => $singleNameSpace) {
2860
+					foreach ($nameSpace as $k => $singleNameSpace) {
2861 2861
 						$type = $singleNameSpace['type'];
2862 2862
 
2863
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2863
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2864 2864
 							$prefixes[$type] = $singleNameSpace['prefix'];
2865 2865
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2866
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2866
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2867 2867
 							if (is_array($result))
2868 2868
 							{
2869 2869
 								ksort($result);
2870
-								$topFolders = array_merge($topFolders,$result);
2870
+								$topFolders = array_merge($topFolders, $result);
2871 2871
 							}
2872 2872
 						}
2873 2873
 					}
@@ -2876,7 +2876,7 @@  discard block
 block discarded – undo
2876 2876
 
2877 2877
 			$autofolders = array();
2878 2878
 
2879
-			foreach(self::$specialUseFolders as $path => $folder)
2879
+			foreach (self::$specialUseFolders as $path => $folder)
2880 2880
 			{
2881 2881
 				if ($this->folderExists($path))
2882 2882
 				{
@@ -2884,9 +2884,9 @@  discard block
 block discarded – undo
2884 2884
 				}
2885 2885
 			}
2886 2886
 			// Check if the special use folders are there, otherwise try to create them
2887
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2887
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2888 2888
 			{
2889
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2889
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2890 2890
 			}
2891 2891
 
2892 2892
 			// now process topFolders for next level
@@ -2894,13 +2894,13 @@  discard block
 block discarded – undo
2894 2894
 			{
2895 2895
 				$pattern = "/\\".$delimiter."/";
2896 2896
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2897
-				if(!empty($prefixes))
2897
+				if (!empty($prefixes))
2898 2898
 				{
2899 2899
 					$reference = '';
2900
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2901
-					foreach($tmpArray as $p)
2900
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2901
+					foreach ($tmpArray as $p)
2902 2902
 					{
2903
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2903
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2904 2904
 					}
2905 2905
 				}
2906 2906
 				$mainFolder = $subFolders = array();
@@ -2936,19 +2936,19 @@  discard block
 block discarded – undo
2936 2936
 							$nFolders [$path] = $folder;
2937 2937
 						}
2938 2938
 					}
2939
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2939
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2940 2940
 					//ksort($aFolders);
2941 2941
 
2942 2942
 					// Sort none auto folders base on mailbox name
2943
-					uasort($nFolders,array($this,'sortByMailbox'));
2943
+					uasort($nFolders, array($this, 'sortByMailbox'));
2944 2944
 
2945
-					$subFolders = array_merge($aFolders,$nFolders);
2945
+					$subFolders = array_merge($aFolders, $nFolders);
2946 2946
 				}
2947 2947
 				else
2948 2948
 				{
2949 2949
 					if (is_array($subFolders)) ksort($subFolders);
2950 2950
 				}
2951
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2951
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2952 2952
 			}
2953 2953
 		}
2954 2954
 		elseif ($_nodePath) // single node
@@ -2975,9 +2975,9 @@  discard block
 block discarded – undo
2975 2975
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
2976 2976
 			}
2977 2977
 
2978
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2978
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2979 2979
 		}
2980
-		elseif(!$_nodePath) // all
2980
+		elseif (!$_nodePath) // all
2981 2981
 		{
2982 2982
 			if ($_subscribedOnly)
2983 2983
 			{
@@ -2993,101 +2993,101 @@  discard block
 block discarded – undo
2993 2993
 		{
2994 2994
 			// SORTING FOLDERS
2995 2995
 			//self::$debugTimes=true;
2996
-			if (self::$debugTimes) $starttime = microtime (true);
2996
+			if (self::$debugTimes) $starttime = microtime(true);
2997 2997
 			// Merge of all auto folders and specialusefolders
2998 2998
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2999
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2999
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
3000 3000
 			$tmpFolders = $folders;
3001
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
3002
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
3003
-			$isGoogleMail=false;
3004
-			foreach($autoFoldersTmp as $afk=>$aF)
3001
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
3002
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
3003
+			$isGoogleMail = false;
3004
+			foreach ($autoFoldersTmp as $afk=>$aF)
3005 3005
 			{
3006
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3006
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
3007 3007
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3008 3008
 			}
3009 3009
 			//error_log(array2string($mySpecialUseFolders));
3010 3010
 			foreach ($tmpFolders as $k => $f) {
3011
-				$sorted=false;
3012
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3013
-					if (strtoupper($k)=='INBOX') {
3011
+				$sorted = false;
3012
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
3013
+					if (strtoupper($k) == 'INBOX') {
3014 3014
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3015
-						$inboxFolderObject[$k]=$f;
3015
+						$inboxFolderObject[$k] = $f;
3016 3016
 						unset($folders[$k]);
3017
-						$sorted=true;
3017
+						$sorted = true;
3018 3018
 					} else {
3019
-						$isAutoFolder=false;
3020
-						foreach($autoFoldersTmp as $afk=>$aF)
3019
+						$isAutoFolder = false;
3020
+						foreach ($autoFoldersTmp as $afk=>$aF)
3021 3021
 						{
3022 3022
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3023
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3024
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3025
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3023
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3024
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3025
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3026 3026
 							{
3027 3027
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3028
-								$isAutoFolder=true;
3029
-								$autoFolderObjects[$k]=$f;
3028
+								$isAutoFolder = true;
3029
+								$autoFolderObjects[$k] = $f;
3030 3030
 								break;
3031 3031
 							}
3032 3032
 						}
3033
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3033
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
3034 3034
 						unset($folders[$k]);
3035
-						$sorted=true;
3035
+						$sorted = true;
3036 3036
 					}
3037
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3038
-					$isGoogleMail=true;
3039
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3040
-						$googleMailFolderObject[$k]=$f;
3037
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
3038
+					$isGoogleMail = true;
3039
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
3040
+						$googleMailFolderObject[$k] = $f;
3041 3041
 						unset($folders[$k]);
3042
-						$sorted=true;
3042
+						$sorted = true;
3043 3043
 					} else {
3044
-						$isAutoFolder=false;
3045
-						foreach($autoFoldersTmp as $afk=>$aF)
3044
+						$isAutoFolder = false;
3045
+						foreach ($autoFoldersTmp as $afk=>$aF)
3046 3046
 						{
3047 3047
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3048
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3049
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3050
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3048
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3049
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3050
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3051 3051
 							{
3052 3052
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3053
-								$isAutoFolder=true;
3054
-								$googleAutoFolderObjects[$k]=$f;
3053
+								$isAutoFolder = true;
3054
+								$googleAutoFolderObjects[$k] = $f;
3055 3055
 								break;
3056 3056
 							}
3057 3057
 						}
3058
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3058
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
3059 3059
 						unset($folders[$k]);
3060
-						$sorted=true;
3060
+						$sorted = true;
3061 3061
 					}
3062 3062
 				} else {
3063
-					$isAutoFolder=false;
3064
-					foreach($autoFoldersTmp as $afk=>$aF)
3063
+					$isAutoFolder = false;
3064
+					foreach ($autoFoldersTmp as $afk=>$aF)
3065 3065
 					{
3066 3066
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3067
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3068
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3069
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3067
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3068
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3069
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3070 3070
 						{
3071 3071
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3072
-							$isAutoFolder=true;
3073
-							$autoFolderObjects[$k]=$f;
3072
+							$isAutoFolder = true;
3073
+							$autoFolderObjects[$k] = $f;
3074 3074
 							unset($folders[$k]);
3075
-							$sorted=true;
3075
+							$sorted = true;
3076 3076
 							break;
3077 3077
 						}
3078 3078
 					}
3079 3079
 				}
3080 3080
 
3081
-				if ($sorted==false)
3081
+				if ($sorted == false)
3082 3082
 				{
3083
-					foreach(array('others','shared') as $type)
3083
+					foreach (array('others', 'shared') as $type)
3084 3084
 					{
3085
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3085
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
3086 3086
 						{
3087
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3088
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3087
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
3088
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
3089 3089
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3090
-								$typeFolderObject[$type][$k]=$f;
3090
+								$typeFolderObject[$type][$k] = $f;
3091 3091
 								unset($folders[$k]);
3092 3092
 							}
3093 3093
 						}
@@ -3098,40 +3098,40 @@  discard block
 block discarded – undo
3098 3098
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
3099 3099
 			$autoFolderObjectsTmp = $autoFolderObjects;
3100 3100
 			unset($autoFolderObjects);
3101
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
3102
-			foreach($autoFoldersTmp as $afk=>$aF)
3101
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
3102
+			foreach ($autoFoldersTmp as $afk=>$aF)
3103 3103
 			{
3104
-				foreach($autoFolderObjectsTmp as $k => $f)
3104
+				foreach ($autoFolderObjectsTmp as $k => $f)
3105 3105
 				{
3106
-					if($aF && ($mySpecialUseFolders[$aF]==$k ||
3107
-						substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter ||
3108
-						stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3106
+					if ($aF && ($mySpecialUseFolders[$aF] == $k ||
3107
+						substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter ||
3108
+						stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false))
3109 3109
 					{
3110
-						$autoFolderObjects[$k]=$f;
3110
+						$autoFolderObjects[$k] = $f;
3111 3111
 					}
3112 3112
 				}
3113 3113
 			}
3114 3114
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3115 3115
 			if (!$isGoogleMail) {
3116
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3116
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3117 3117
 			} else {
3118 3118
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3119 3119
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3120 3120
 				unset($googleAutoFolderObjects);
3121
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
3122
-				foreach($autoFoldersTmp as $afk=>$aF)
3121
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
3122
+				foreach ($autoFoldersTmp as $afk=>$aF)
3123 3123
 				{
3124
-					foreach($gAutoFolderObjectsTmp as $k => $f)
3124
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
3125 3125
 					{
3126
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
3126
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
3127 3127
 						{
3128
-							$googleAutoFolderObjects[$k]=$f;
3128
+							$googleAutoFolderObjects[$k] = $f;
3129 3129
 						}
3130 3130
 					}
3131 3131
 				}
3132
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3132
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3133 3133
 			}
3134
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3134
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
3135 3135
 			//self::$debugTimes=false;
3136 3136
 		}
3137 3137
 		// Get counter information and add them to each fetched folders array
@@ -3153,10 +3153,10 @@  discard block
 block discarded – undo
3153 3153
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
3154 3154
 	 * @return int number of new folders created
3155 3155
 	 */
3156
-	function check_create_autofolders(array $autofolders_exists=array())
3156
+	function check_create_autofolders(array $autofolders_exists = array())
3157 3157
 	{
3158 3158
 		$num_created = 0;
3159
-		foreach(self::$autoFolders as $folder)
3159
+		foreach (self::$autoFolders as $folder)
3160 3160
 		{
3161 3161
 			$created = false;
3162 3162
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -3181,7 +3181,7 @@  discard block
 block discarded – undo
3181 3181
 		$rv = false;
3182 3182
 		foreach ($haystack as $k => $v)
3183 3183
 		{
3184
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3184
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
3185 3185
 		}
3186 3186
 		return $rv;
3187 3187
 	}
@@ -3194,9 +3194,9 @@  discard block
 block discarded – undo
3194 3194
 	 * @param array $b array of folders
3195 3195
 	 * @return int expect values (0, 1 or -1)
3196 3196
 	 */
3197
-	function sortByMailbox($a,$b)
3197
+	function sortByMailbox($a, $b)
3198 3198
 	{
3199
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
3199
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
3200 3200
 	}
3201 3201
 
3202 3202
 	/**
@@ -3206,13 +3206,13 @@  discard block
 block discarded – undo
3206 3206
 	 * @param string $_hDelimiter hierarchy delimiter
3207 3207
 	 * @return array returns an array of data extracted from given node path
3208 3208
 	 */
3209
-	static function pathToFolderData ($_path, $_hDelimiter)
3209
+	static function pathToFolderData($_path, $_hDelimiter)
3210 3210
 	{
3211 3211
 		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3212 3212
 		list(,$path) = explode(self::DELIMITER, $_path);
3213 3213
 		$path_chain = $parts = explode($_hDelimiter, $path);
3214 3214
 		$name = array_pop($parts);
3215
-		return array (
3215
+		return array(
3216 3216
 			'name' => $name,
3217 3217
 			'mailbox' => $path,
3218 3218
 			'parent' => implode($_hDelimiter, $parts),
@@ -3235,8 +3235,8 @@  discard block
 block discarded – undo
3235 3235
 		// 0, 1 und -1
3236 3236
 		$a = self::pathToFolderData($_a['MAILBOX'], $_a['delimiter']);
3237 3237
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3238
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3239
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3238
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
3239
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3240 3240
 		if ($pos1 == $pos2) return 0;
3241 3241
 		return ($pos1 < $pos2) ? -1 : 1;
3242 3242
 	}
@@ -3249,10 +3249,10 @@  discard block
 block discarded – undo
3249 3249
 	 * @param object $b array of folderobjects
3250 3250
 	 * @return int expect values (0, 1 or -1)
3251 3251
 	 */
3252
-	function sortByDisplayName($a,$b)
3252
+	function sortByDisplayName($a, $b)
3253 3253
 	{
3254 3254
 		// 0, 1 und -1
3255
-		return strcasecmp($a->displayName,$b->displayName);
3255
+		return strcasecmp($a->displayName, $b->displayName);
3256 3256
 	}
3257 3257
 
3258 3258
 	/**
@@ -3263,11 +3263,11 @@  discard block
 block discarded – undo
3263 3263
 	 * @param object $b array of folderobjects
3264 3264
 	 * @return int expect values (0, 1 or -1)
3265 3265
 	 */
3266
-	function sortByAutoFolderPos($a,$b)
3266
+	function sortByAutoFolderPos($a, $b)
3267 3267
 	{
3268 3268
 		// 0, 1 und -1
3269
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3270
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3269
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3270
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3271 3271
 		if ($pos1 == $pos2) return 0;
3272 3272
 		return ($pos1 < $pos2) ? -1 : 1;
3273 3273
 	}
@@ -3280,7 +3280,7 @@  discard block
 block discarded – undo
3280 3280
 	 * @param boolean $_returnObject return the counters as object rather than an array
3281 3281
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3282 3282
 	 */
3283
-	function getMailBoxCounters($folderName,$_returnObject=true)
3283
+	function getMailBoxCounters($folderName, $_returnObject = true)
3284 3284
 	{
3285 3285
 		try
3286 3286
 		{
@@ -3292,9 +3292,9 @@  discard block
 block discarded – undo
3292 3292
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3293 3293
 			return false;
3294 3294
 		}
3295
-		if(is_array($folderStatus)) {
3296
-			if ($_returnObject===false) return $folderStatus;
3297
-			$status =  new \stdClass;
3295
+		if (is_array($folderStatus)) {
3296
+			if ($_returnObject === false) return $folderStatus;
3297
+			$status = new \stdClass;
3298 3298
 			$status->messages   = $folderStatus['MESSAGES'];
3299 3299
 			$status->unseen     = $folderStatus['UNSEEN'];
3300 3300
 			$status->recent     = $folderStatus['RECENT'];
@@ -3316,42 +3316,42 @@  discard block
 block discarded – undo
3316 3316
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3317 3317
 	 * @return array of mailboxes
3318 3318
 	 */
3319
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3319
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3320 3320
 	{
3321 3321
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3322
-		$maxreclevel=25;
3322
+		$maxreclevel = 25;
3323 3323
 		if ($reclevel > $maxreclevel) {
3324
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3324
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3325 3325
 			return array();
3326 3326
 		}
3327 3327
 		$reclevel++;
3328 3328
 		// clean up double delimiters
3329
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3329
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3330 3330
 		//get that mailbox in question
3331
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3331
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3332 3332
 		$mbxkeys = array_keys($mbx);
3333 3333
 		#_debug_array($mbx);
3334 3334
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3335 3335
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3336 3336
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3337
-		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"]))) {
3337
+		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"]))) {
3338 3338
 			// if there are children fetch them
3339 3339
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3340 3340
 
3341
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3341
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3342 3342
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3343 3343
 			//_debug_array($buff);
3344 3344
 			$allMailboxes = array();
3345 3345
 			foreach ($buff as $mbxname) {
3346 3346
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3347
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3347
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3348 3348
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3349
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3349
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3350 3350
 				{
3351 3351
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3352 3352
 				}
3353 3353
 			}
3354
-			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'];
3354
+			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'];
3355 3355
 			return $allMailboxes;
3356 3356
 		} else {
3357 3357
 			return array($_mailbox);
@@ -3366,18 +3366,18 @@  discard block
 block discarded – undo
3366 3366
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3367 3367
 	 * @return mixed string or false
3368 3368
 	 */
3369
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3369
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3370 3370
 	{
3371 3371
 		static $types = array(
3372
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3373
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3374
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3375
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3376
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3377
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3378
-			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3372
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3373
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3374
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3375
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3376
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3377
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3378
+			'Archive'   => array('profileKey'=>'acc_folder_archive', 'autoFolderName'=>'Archive'),
3379 3379
 		);
3380
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3380
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3381 3381
 		$created = false;
3382 3382
 		if (!isset($types[$_type]))
3383 3383
 		{
@@ -3399,7 +3399,7 @@  discard block
 block discarded – undo
3399 3399
 		}
3400 3400
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3401 3401
 		if ($_type == 'Archive') {
3402
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3402
+			if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3403 3403
 				return false;
3404 3404
 			} else {
3405 3405
 				return $_folderName;
@@ -3407,38 +3407,38 @@  discard block
 block discarded – undo
3407 3407
 
3408 3408
 		}
3409 3409
 		// does the folder exist??? (is configured/preset, but non-existent)
3410
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3410
+		if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3411 3411
 			try
3412 3412
 			{
3413 3413
 				$error = null;
3414 3414
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3415 3415
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3416 3416
 			}
3417
-			catch(Exception $e)
3417
+			catch (Exception $e)
3418 3418
 			{
3419 3419
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3420 3420
 				$_folderName = false;
3421 3421
 			}
3422 3422
 		}
3423 3423
 		// not sure yet if false is the correct behavior on none
3424
-		if ($_folderName =='none') return 'none' ; //false;
3424
+		if ($_folderName == 'none') return 'none'; //false;
3425 3425
 		//no (valid) folder found yet; try specialUseFolders
3426
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3426
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3427 3427
 		//no specialUseFolder; try some Defaults
3428 3428
 		if (empty($_folderName) && isset($types[$_type]))
3429 3429
 		{
3430 3430
 			$nameSpace = $this->_getNameSpaces();
3431
-			$prefix='';
3431
+			$prefix = '';
3432 3432
 			foreach ($nameSpace as $nSp)
3433 3433
 			{
3434
-				if ($nSp['type']=='personal')
3434
+				if ($nSp['type'] == 'personal')
3435 3435
 				{
3436 3436
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3437 3437
 					$prefix = $nSp['prefix'];
3438 3438
 					break;
3439 3439
 				}
3440 3440
 			}
3441
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3441
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3442 3442
 			{
3443 3443
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3444 3444
 			}
@@ -3447,11 +3447,11 @@  discard block
 block discarded – undo
3447 3447
 				try
3448 3448
 				{
3449 3449
 					$error = null;
3450
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3450
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3451 3451
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3452 3452
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3453 3453
 				}
3454
-				catch(Exception $e)
3454
+				catch (Exception $e)
3455 3455
 				{
3456 3456
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3457 3457
 					$_folderName = false;
@@ -3467,7 +3467,7 @@  discard block
 block discarded – undo
3467 3467
 	 * @param boolean $_checkexistance trigger check for existance
3468 3468
 	 * @return mixed string or false
3469 3469
 	 */
3470
-	function getFolderByType($type, $_checkexistance=false)
3470
+	function getFolderByType($type, $_checkexistance = false)
3471 3471
 	{
3472 3472
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3473 3473
 	}
@@ -3477,7 +3477,7 @@  discard block
 block discarded – undo
3477 3477
 	 * @param boolean $_checkexistance trigger check for existance
3478 3478
 	 * @return mixed string or false
3479 3479
 	 */
3480
-	function getJunkFolder($_checkexistance=TRUE)
3480
+	function getJunkFolder($_checkexistance = TRUE)
3481 3481
 	{
3482 3482
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3483 3483
 	}
@@ -3487,7 +3487,7 @@  discard block
 block discarded – undo
3487 3487
 	 * @param boolean $_checkexistance trigger check for existance
3488 3488
 	 * @return mixed string or false
3489 3489
 	 */
3490
-	function getDraftFolder($_checkexistance=TRUE)
3490
+	function getDraftFolder($_checkexistance = TRUE)
3491 3491
 	{
3492 3492
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3493 3493
 	}
@@ -3497,7 +3497,7 @@  discard block
 block discarded – undo
3497 3497
 	 * @param boolean $_checkexistance trigger check for existance
3498 3498
 	 * @return mixed string or false
3499 3499
 	 */
3500
-	function getTemplateFolder($_checkexistance=TRUE)
3500
+	function getTemplateFolder($_checkexistance = TRUE)
3501 3501
 	{
3502 3502
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3503 3503
 	}
@@ -3507,7 +3507,7 @@  discard block
 block discarded – undo
3507 3507
 	 * @param boolean $_checkexistance trigger check for existance
3508 3508
 	 * @return mixed string or false
3509 3509
 	 */
3510
-	function getTrashFolder($_checkexistance=TRUE)
3510
+	function getTrashFolder($_checkexistance = TRUE)
3511 3511
 	{
3512 3512
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3513 3513
 	}
@@ -3517,7 +3517,7 @@  discard block
 block discarded – undo
3517 3517
 	 * @param boolean $_checkexistance trigger check for existance
3518 3518
 	 * @return mixed string or false
3519 3519
 	 */
3520
-	function getSentFolder($_checkexistance=TRUE)
3520
+	function getSentFolder($_checkexistance = TRUE)
3521 3521
 	{
3522 3522
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3523 3523
 	}
@@ -3527,7 +3527,7 @@  discard block
 block discarded – undo
3527 3527
 	 * @param boolean $_checkexistance trigger check for existance
3528 3528
 	 * @return mixed string or false
3529 3529
 	 */
3530
-	function getOutboxFolder($_checkexistance=TRUE)
3530
+	function getOutboxFolder($_checkexistance = TRUE)
3531 3531
 	{
3532 3532
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3533 3533
 	}
@@ -3537,7 +3537,7 @@  discard block
 block discarded – undo
3537 3537
 	 * @param boolean $_checkexistance trigger check for existance . We do no autocreation for configured Archive folder
3538 3538
 	 * @return mixed string or false
3539 3539
 	 */
3540
-	function getArchiveFolder($_checkexistance=TRUE)
3540
+	function getArchiveFolder($_checkexistance = TRUE)
3541 3541
 	{
3542 3542
 		return $this->_getSpecialUseFolder('Archive', $_checkexistance);
3543 3543
 	}
@@ -3548,10 +3548,10 @@  discard block
 block discarded – undo
3548 3548
 	 * @param boolean $_checkexistance trigger check for existance
3549 3549
 	 * @return boolean
3550 3550
 	 */
3551
-	function isSentFolder($_folderName, $_checkexistance=TRUE)
3551
+	function isSentFolder($_folderName, $_checkexistance = TRUE)
3552 3552
 	{
3553 3553
 		$sentFolder = $this->getSentFolder($_checkexistance);
3554
-		if(empty($sentFolder)) {
3554
+		if (empty($sentFolder)) {
3555 3555
 			return false;
3556 3556
 		}
3557 3557
 		// does the folder exist???
@@ -3559,7 +3559,7 @@  discard block
 block discarded – undo
3559 3559
 			return false;
3560 3560
 		}
3561 3561
 
3562
-		if(false !== stripos($_folderName, $sentFolder)) {
3562
+		if (false !== stripos($_folderName, $sentFolder)) {
3563 3563
 			return true;
3564 3564
 		} else {
3565 3565
 			return false;
@@ -3572,15 +3572,15 @@  discard block
 block discarded – undo
3572 3572
 	 * @param boolean $_checkexistance trigger check for existance
3573 3573
 	 * @return boolean
3574 3574
 	 */
3575
-	function isOutbox($_folderName, $_checkexistance=TRUE)
3575
+	function isOutbox($_folderName, $_checkexistance = TRUE)
3576 3576
 	{
3577
-		if (stripos($_folderName, 'Outbox')===false) {
3577
+		if (stripos($_folderName, 'Outbox') === false) {
3578 3578
 			return false;
3579 3579
 		}
3580 3580
 		// does the folder exist???
3581 3581
 		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
3582 3582
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3583
-			if(false !== stripos($_folderName, $outboxFolder)) {
3583
+			if (false !== stripos($_folderName, $outboxFolder)) {
3584 3584
 				return true;
3585 3585
 			} else {
3586 3586
 				return false;
@@ -3595,18 +3595,18 @@  discard block
 block discarded – undo
3595 3595
 	 * @param boolean $_checkexistance trigger check for existance
3596 3596
 	 * @return boolean
3597 3597
 	 */
3598
-	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3598
+	function isDraftFolder($_folderName, $_checkexistance = TRUE)
3599 3599
 	{
3600 3600
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3601
-		if(empty($draftFolder)) {
3601
+		if (empty($draftFolder)) {
3602 3602
 			return false;
3603 3603
 		}
3604 3604
 		// does the folder exist???
3605 3605
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3606 3606
 			return false;
3607 3607
 		}
3608
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3609
-		if(false !== stripos($_folderName, $draftFolder)) {
3608
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3609
+		if (false !== stripos($_folderName, $draftFolder)) {
3610 3610
 			return true;
3611 3611
 		} else {
3612 3612
 			return false;
@@ -3619,10 +3619,10 @@  discard block
 block discarded – undo
3619 3619
 	 * @param boolean $_checkexistance trigger check for existance
3620 3620
 	 * @return boolean
3621 3621
 	 */
3622
-	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3622
+	function isTrashFolder($_folderName, $_checkexistance = TRUE)
3623 3623
 	{
3624 3624
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3625
-		if(empty($trashFolder)) {
3625
+		if (empty($trashFolder)) {
3626 3626
 			return false;
3627 3627
 		}
3628 3628
 		// does the folder exist???
@@ -3630,7 +3630,7 @@  discard block
 block discarded – undo
3630 3630
 			return false;
3631 3631
 		}
3632 3632
 
3633
-		if(false !== stripos($_folderName, $trashFolder)) {
3633
+		if (false !== stripos($_folderName, $trashFolder)) {
3634 3634
 			return true;
3635 3635
 		} else {
3636 3636
 			return false;
@@ -3643,10 +3643,10 @@  discard block
 block discarded – undo
3643 3643
 	 * @param boolean $_checkexistance trigger check for existance
3644 3644
 	 * @return boolean
3645 3645
 	 */
3646
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3646
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE)
3647 3647
 	{
3648 3648
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3649
-		if(empty($templateFolder)) {
3649
+		if (empty($templateFolder)) {
3650 3650
 			return false;
3651 3651
 		}
3652 3652
 		// does the folder exist???
@@ -3654,7 +3654,7 @@  discard block
 block discarded – undo
3654 3654
 			return false;
3655 3655
 		}
3656 3656
 
3657
-		if(false !== stripos($_folderName, $templateFolder)) {
3657
+		if (false !== stripos($_folderName, $templateFolder)) {
3658 3658
 			return true;
3659 3659
 		} else {
3660 3660
 			return false;
@@ -3667,24 +3667,24 @@  discard block
 block discarded – undo
3667 3667
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3668 3668
 	 * @return mixed string or false
3669 3669
 	 */
3670
-	function folderExists($_folder, $_forceCheck=false)
3670
+	function folderExists($_folder, $_forceCheck = false)
3671 3671
 	{
3672 3672
 		static $folderInfo;
3673 3673
 		$forceCheck = $_forceCheck;
3674 3674
 		if (empty($_folder))
3675 3675
 		{
3676 3676
 			// this error is more or less without significance, unless we force the check
3677
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3677
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3678 3678
 			return false;
3679 3679
 		}
3680 3680
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3681
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3682
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3681
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3682
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3683 3683
 		// reduce traffic within the Instance per User; Expire every 5 hours
3684 3684
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3685
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3685
+		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3686 3686
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3687
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3687
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3688 3688
 		{
3689 3689
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3690 3690
 			return $folderInfo[$this->profileID][$_folder];
@@ -3700,7 +3700,7 @@  discard block
 block discarded – undo
3700 3700
 
3701 3701
 		// does the folder exist???
3702 3702
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3703
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3703
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3704 3704
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3705 3705
 			//return false;
3706 3706
 			//try to connect
@@ -3711,18 +3711,18 @@  discard block
 block discarded – undo
3711 3711
 		}
3712 3712
 		catch (\Exception $e)
3713 3713
 		{
3714
-			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:''));
3715
-			self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
3714
+			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details ? ', '.$e->details : ''));
3715
+			self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
3716 3716
 			$folderInfo[$this->profileID][$_folder] = false;
3717 3717
 		}
3718 3718
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3719 3719
 
3720
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3720
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3721 3721
 			$folderInfo[$this->profileID][$_folder] !== true)
3722 3722
 		{
3723 3723
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3724 3724
 		}
3725
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3725
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3726 3726
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3727 3727
 	}
3728 3728
 
@@ -3735,14 +3735,14 @@  discard block
 block discarded – undo
3735 3735
 	 */
3736 3736
 	function compressFolder($_folderName = false)
3737 3737
 	{
3738
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3739
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3740
-		$trashFolder	= $this->getTrashFolder();
3738
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3739
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3740
+		$trashFolder = $this->getTrashFolder();
3741 3741
 
3742 3742
 		$this->icServer->openMailbox($folderName);
3743 3743
 
3744
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3745
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3744
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3745
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3746 3746
 		} else {
3747 3747
 			$this->icServer->expunge($folderName);
3748 3748
 		}
@@ -3758,19 +3758,19 @@  discard block
 block discarded – undo
3758 3758
 	 * @return bool true, as we do not handle return values yet
3759 3759
 	 * @throws Exception
3760 3760
 	 */
3761
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3761
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3762 3762
 	{
3763 3763
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3764 3764
 		$oldMailbox = '';
3765 3765
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3766 3766
 		if (empty($_messageUID))
3767 3767
 		{
3768
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3768
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3769 3769
 			return false;
3770 3770
 		}
3771
-		elseif ($_messageUID==='all')
3771
+		elseif ($_messageUID === 'all')
3772 3772
 		{
3773
-			$_messageUID= null;
3773
+			$_messageUID = null;
3774 3774
 		}
3775 3775
 		else
3776 3776
 		{
@@ -3779,32 +3779,32 @@  discard block
 block discarded – undo
3779 3779
 			$uidsToDelete->add($_messageUID);
3780 3780
 		}
3781 3781
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3782
-		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");
3782
+		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");
3783 3783
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3784 3784
 		$trashFolder    = $this->getTrashFolder();
3785
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3785
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3786 3786
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3787
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3787
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3788 3788
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3789 3789
 			$deleteOptions = "remove_immediately";
3790 3790
 		}
3791
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3791
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3792 3792
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3793 3793
 			$this->icServer->openMailbox($_folder);
3794 3794
 		}
3795 3795
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3796 3796
 		$updateCache = false;
3797
-		switch($deleteOptions) {
3797
+		switch ($deleteOptions) {
3798 3798
 			case "move_to_trash":
3799 3799
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3800 3800
 				$updateCache = true;
3801
-				if(!empty($trashFolder)) {
3801
+				if (!empty($trashFolder)) {
3802 3802
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3803
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3803
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3804 3804
 					// copy messages
3805 3805
 					try
3806 3806
 					{
3807
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3807
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3808 3808
 					}
3809 3809
 					catch (\Exception $e)
3810 3810
 					{
@@ -3816,18 +3816,18 @@  discard block
 block discarded – undo
3816 3816
 			case "mark_as_deleted":
3817 3817
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3818 3818
 				// mark messages as deleted
3819
-				if (is_null($_messageUID)) $_messageUID='all';
3820
-				foreach((array)$_messageUID as $key =>$uid)
3819
+				if (is_null($_messageUID)) $_messageUID = 'all';
3820
+				foreach ((array)$_messageUID as $key =>$uid)
3821 3821
 				{
3822 3822
 					//flag messages, that are flagged for deletion as seen too
3823 3823
 					$this->flagMessages('read', $uid, $_folder);
3824 3824
 					$flags = $this->getFlags($uid);
3825 3825
 					$this->flagMessages('delete', $uid, $_folder);
3826 3826
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3827
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3827
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3828 3828
 					unset($flags);
3829 3829
 				}
3830
-				foreach((array)$undelete as $key =>$uid)
3830
+				foreach ((array)$undelete as $key =>$uid)
3831 3831
 				{
3832 3832
 					$this->flagMessages('undelete', $uid, $_folder);
3833 3833
 				}
@@ -3836,14 +3836,14 @@  discard block
 block discarded – undo
3836 3836
 			case "remove_immediately":
3837 3837
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3838 3838
 				$updateCache = true;
3839
-				if (is_null($_messageUID)) $_messageUID='all';
3839
+				if (is_null($_messageUID)) $_messageUID = 'all';
3840 3840
 				if (is_object($_messageUID))
3841 3841
 				{
3842 3842
 					$this->flagMessages('delete', $_messageUID, $_folder);
3843 3843
 				}
3844 3844
 				else
3845 3845
 				{
3846
-					foreach((array)$_messageUID as $key =>$uid)
3846
+					foreach ((array)$_messageUID as $key =>$uid)
3847 3847
 					{
3848 3848
 						//flag messages, that are flagged for deletion as seen too
3849 3849
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3853,7 +3853,7 @@  discard block
 block discarded – undo
3853 3853
 				$this->icServer->expunge($_folder);
3854 3854
 				break;
3855 3855
 		}
3856
-		if($oldMailbox != '') {
3856
+		if ($oldMailbox != '') {
3857 3857
 			$this->icServer->openMailbox($oldMailbox);
3858 3858
 		}
3859 3859
 
@@ -3867,7 +3867,7 @@  discard block
 block discarded – undo
3867 3867
 	 *
3868 3868
 	 * @return null/array flags
3869 3869
 	 */
3870
-	function getFlags ($_messageUID) {
3870
+	function getFlags($_messageUID) {
3871 3871
 		try
3872 3872
 		{
3873 3873
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3880,7 +3880,7 @@  discard block
 block discarded – undo
3880 3880
 				'ids' => $uidsToFetch,
3881 3881
 			));
3882 3882
 			if (is_object($headersNew)) {
3883
-				foreach($headersNew->ids() as $id) {
3883
+				foreach ($headersNew->ids() as $id) {
3884 3884
 					$_headerObject = $headersNew->get($id);
3885 3885
 					$flags = $_headerObject->getFlags();
3886 3886
 				}
@@ -3903,22 +3903,22 @@  discard block
 block discarded – undo
3903 3903
 	 *
3904 3904
 	 * @return null/boolean
3905 3905
 	 */
3906
-	function getNotifyFlags ($_messageUID, $flags=null)
3906
+	function getNotifyFlags($_messageUID, $flags = null)
3907 3907
 	{
3908 3908
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3909 3909
 		try
3910 3910
 		{
3911
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3911
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3912 3912
 		}
3913 3913
 		catch (\Exception $e)
3914 3914
 		{
3915 3915
 			return null;
3916 3916
 		}
3917 3917
 
3918
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3918
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3919 3919
 			return true;
3920 3920
 
3921
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3921
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
3922 3922
 			return false;
3923 3923
 
3924 3924
 		return null;
@@ -3935,45 +3935,45 @@  discard block
 block discarded – undo
3935 3935
 	 *
3936 3936
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
3937 3937
 	 */
3938
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
3938
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
3939 3939
 	{
3940 3940
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3941 3941
 		if (empty($_messageUID))
3942 3942
 		{
3943
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3943
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3944 3944
 			return false;
3945 3945
 		}
3946
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
3946
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
3947 3947
 		$folder = $this->icServer->getCurrentMailbox();
3948
-		if (is_array($_messageUID)&& count($_messageUID)>50)
3948
+		if (is_array($_messageUID) && count($_messageUID) > 50)
3949 3949
 		{
3950
-			$count = $this->getMailBoxCounters($folder,true);
3951
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
3950
+			$count = $this->getMailBoxCounters($folder, true);
3951
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
3952 3952
 		}
3953 3953
 
3954
-		if ($_messageUID==='all')
3954
+		if ($_messageUID === 'all')
3955 3955
 		{
3956 3956
 			$messageUIDs = array('all');
3957 3957
 		}
3958 3958
 		else
3959 3959
 		{
3960 3960
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
3961
-			$messageUIDs = array_chunk($_messageUID,50,true);
3961
+			$messageUIDs = array_chunk($_messageUID, 50, true);
3962 3962
 		}
3963 3963
 		try
3964 3964
 		{
3965
-			foreach($messageUIDs as &$uids)
3965
+			foreach ($messageUIDs as &$uids)
3966 3966
 			{
3967
-				if ($uids==='all')
3967
+				if ($uids === 'all')
3968 3968
 				{
3969
-					$uidsToModify=null;
3969
+					$uidsToModify = null;
3970 3970
 				}
3971 3971
 				else
3972 3972
 				{
3973 3973
 					$uidsToModify = new Horde_Imap_Client_Ids();
3974 3974
 					$uidsToModify->add($uids);
3975 3975
 				}
3976
-				switch($_flag) {
3976
+				switch ($_flag) {
3977 3977
 					case "delete":
3978 3978
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3979 3979
 						break;
@@ -3997,7 +3997,7 @@  discard block
 block discarded – undo
3997 3997
 						break;
3998 3998
 					case "unread":
3999 3999
 					case "unseen":
4000
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
4000
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
4001 4001
 						break;
4002 4002
 					case "mdnsent":
4003 4003
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -4055,13 +4055,13 @@  discard block
 block discarded – undo
4055 4055
 				}
4056 4056
 			}
4057 4057
 		}
4058
-		catch(Exception $e)
4058
+		catch (Exception $e)
4059 4059
 		{
4060 4060
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4061 4061
 		}
4062 4062
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4063 4063
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4064
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4064
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
4065 4065
 
4066 4066
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
4067 4067
 		return true; // as we do not catch/examine setFlags returnValue
@@ -4082,19 +4082,19 @@  discard block
 block discarded – undo
4082 4082
 	 * @return mixed/bool true,false or new uid
4083 4083
 	 * @throws Exception
4084 4084
 	 */
4085
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4085
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4086 4086
 	{
4087
-		$source = Mail\Account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
4087
+		$source = Mail\Account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
4088 4088
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4089 4089
 		if (empty($_messageUID))
4090 4090
 		{
4091
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4091
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
4092 4092
 			return false;
4093 4093
 		}
4094
-		elseif ($_messageUID==='all')
4094
+		elseif ($_messageUID === 'all')
4095 4095
 		{
4096 4096
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
4097
-			$uidsToMove= null;
4097
+			$uidsToMove = null;
4098 4098
 		}
4099 4099
 		else
4100 4100
 		{
@@ -4103,7 +4103,7 @@  discard block
 block discarded – undo
4103 4103
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4104 4104
 			$uidsToMove->add($_messageUID);
4105 4105
 		}
4106
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
4106
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
4107 4107
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
4108 4108
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
4109 4109
 		{
@@ -4123,19 +4123,19 @@  discard block
 block discarded – undo
4123 4123
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4124 4124
 
4125 4125
 			if (is_object($headersNew)) {
4126
-				$c=0;
4126
+				$c = 0;
4127 4127
 				$retUid = new Horde_Imap_Client_Ids();
4128 4128
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4129 4129
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4130
-				foreach($headersNew as &$_headerObject) {
4130
+				foreach ($headersNew as &$_headerObject) {
4131 4131
 					$c++;
4132 4132
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4133 4133
 					$date = $_headerObject->getImapDate();
4134
-					$currentDate =  new Horde_Imap_Client_DateTime();
4134
+					$currentDate = new Horde_Imap_Client_DateTime();
4135 4135
 					// if the internal Date of the message equals the current date; try using the header date
4136
-					if ($date==$currentDate)
4136
+					if ($date == $currentDate)
4137 4137
 					{
4138
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4138
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4139 4139
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
4140 4140
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
4141 4141
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -4144,20 +4144,20 @@  discard block
 block discarded – undo
4144 4144
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
4145 4145
 					$body = $_headerObject->getFullMsg();
4146 4146
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
4147
-					if ($c==1)
4147
+					if ($c == 1)
4148 4148
 					{
4149 4149
 						$target = Mail\Account::read($_targetProfileID)->imapServer();
4150 4150
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
4151 4151
 						$foldername = $target->getMailbox($_foldername);
4152 4152
 						// make sure the target folder is open and ready
4153 4153
 						$target->openMailbox($foldername);
4154
-						$ret = $target->append($foldername,$dataNflags);
4154
+						$ret = $target->append($foldername, $dataNflags);
4155 4155
 						$retUid->add($ret);
4156 4156
 						unset($dataNflags);
4157 4157
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
4158 4158
 						// inflicting in them. they "reply" with an unspecific IMAP Error
4159
-						time_nanosleep(0,500000);
4160
-						$c=0;
4159
+						time_nanosleep(0, 500000);
4160
+						$c = 0;
4161 4161
 					}
4162 4162
 				}
4163 4163
 				if (isset($dataNflags))
@@ -4167,7 +4167,7 @@  discard block
 block discarded – undo
4167 4167
 					$foldername = $target->getMailbox($_foldername);
4168 4168
 					// make sure the target folder is open and ready
4169 4169
 					$target->openMailbox($foldername);
4170
-					$ret = $target->append($foldername,$dataNflags);
4170
+					$ret = $target->append($foldername, $dataNflags);
4171 4171
 					$retUid->add($ret);
4172 4172
 					unset($dataNflags);
4173 4173
 				}
@@ -4178,7 +4178,7 @@  discard block
 block discarded – undo
4178 4178
 				{
4179 4179
 					$remember = $this->icServer;
4180 4180
 					$this->icServer = $source;
4181
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
4181
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
4182 4182
 					$this->icServer = $remember;
4183 4183
 				}
4184 4184
 			}
@@ -4187,7 +4187,7 @@  discard block
 block discarded – undo
4187 4187
 		{
4188 4188
 			try
4189 4189
 			{
4190
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
4190
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
4191 4191
 			}
4192 4192
 			catch (exception $e)
4193 4193
 			{
@@ -4207,19 +4207,19 @@  discard block
 block discarded – undo
4207 4207
 	 * @param string $format ='' if none is passed, use user prefs
4208 4208
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
4209 4209
 	 */
4210
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
4210
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
4211 4211
 	{
4212 4212
 		try {
4213
-			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4214
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4213
+			$date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable)
4214
+			if ($convert2usertime) $date->setUser(); // convert to user-time
4215 4215
 			$date2return = $date->format($format);
4216 4216
 		}
4217
-		catch(\Exception $e)
4217
+		catch (\Exception $e)
4218 4218
 		{
4219
-			unset($e);	// not used
4219
+			unset($e); // not used
4220 4220
 
4221 4221
 			// remove last space-separated part and retry
4222
-			$parts = explode(' ',$_date);
4222
+			$parts = explode(' ', $_date);
4223 4223
 			if (count($parts) > 1)
4224 4224
 			{
4225 4225
 				array_pop($parts);
@@ -4240,12 +4240,12 @@  discard block
 block discarded – undo
4240 4240
 	 * @param mixed $_charset false or string -> Target charset, if false Mail displayCharset will be used
4241 4241
 	 * @return string
4242 4242
 	 */
4243
-	static function htmlentities($_string, $_charset=false)
4243
+	static function htmlentities($_string, $_charset = false)
4244 4244
 	{
4245 4245
 		//setting the charset (if not given)
4246
-		if ($_charset===false) $_charset = self::$displayCharset;
4246
+		if ($_charset === false) $_charset = self::$displayCharset;
4247 4247
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4248
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4248
+		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string, Translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
4249 4249
 		return $string;
4250 4250
 	}
4251 4251
 
@@ -4262,21 +4262,21 @@  discard block
 block discarded – undo
4262 4262
 		//$_html = str_replace("\t",' ',$_html);
4263 4263
 		//error_log(__METHOD__.__LINE__.':'.$_html);
4264 4264
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4265
-		$_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>'),
4266
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4265
+		$_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>'),
4266
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4267 4267
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4268
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4269
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4268
+		if (stripos($_html, 'style') !== false) Mail\Html::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4269
+		if (stripos($_html, 'head') !== false) Mail\Html::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4270 4270
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4271 4271
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4272 4272
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4273 4273
 
4274 4274
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4275 4275
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4276
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4277
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4278
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4279
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4276
+		if (stripos($_html, '!doctype') !== false) Mail\Html::replaceTagsCompletley($_html, '!doctype');
4277
+		if (stripos($_html, '?xml:namespace') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4278
+		if (stripos($_html, '?xml version') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4279
+		if (strpos($_html, '!CURSOR') !== false) Mail\Html::replaceTagsCompletley($_html, '!CURSOR');
4280 4280
 		// htmLawed filter only the 'body'
4281 4281
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4282 4282
 		//if ($matches[2])
@@ -4287,16 +4287,16 @@  discard block
 block discarded – undo
4287 4287
 		// purify got switched to htmLawed
4288 4288
 		// some testcode to test purifying / htmlawed
4289 4289
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4290
-		$_html = Html\HtmLawed::purify($_html,self::$htmLawed_config,array(),true);
4290
+		$_html = Html\HtmLawed::purify($_html, self::$htmLawed_config, array(), true);
4291 4291
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4292 4292
 		// clean out comments , should not be needed as purify should do the job.
4293 4293
 		$search = array(
4294
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4295
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4294
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4295
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4296 4296
 		);
4297
-		$_html = preg_replace($search,"",$_html);
4297
+		$_html = preg_replace($search, "", $_html);
4298 4298
 		// remove non printable chars
4299
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4299
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4300 4300
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4301 4301
 	}
4302 4302
 
@@ -4313,12 +4313,12 @@  discard block
 block discarded – undo
4313 4313
 	function getMimePartCharset($_mimePartObject)
4314 4314
 	{
4315 4315
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4316
-		$CharsetFound=false;
4316
+		$CharsetFound = false;
4317 4317
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4318
-		if(is_array($_mimePartObject->parameters)) {
4319
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4318
+		if (is_array($_mimePartObject->parameters)) {
4319
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4320 4320
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4321
-				$CharsetFound=true;
4321
+				$CharsetFound = true;
4322 4322
 			}
4323 4323
 		}
4324 4324
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4337,7 +4337,7 @@  discard block
 block discarded – undo
4337 4337
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4338 4338
 	{
4339 4339
 		// decode the part
4340
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4340
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4341 4341
 		switch (strtoupper($_encoding))
4342 4342
 		{
4343 4343
 			case 'BASE64':
@@ -4377,10 +4377,10 @@  discard block
 block discarded – undo
4377 4377
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4378 4378
 		// as attachment AND as abstracted ical information (we use our notification style here).
4379 4379
 		$partText = $partCalendar = $partHTML = null;
4380
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4380
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4381 4381
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4382 4382
 		$ignore_first_part = true;
4383
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4383
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4384 4384
 		{
4385 4385
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4386 4386
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4388,15 +4388,15 @@  discard block
 block discarded – undo
4388 4388
 			if ($ignore_first_part)
4389 4389
 			{
4390 4390
 				$ignore_first_part = false;
4391
-				continue;	// ignore multipart/alternative itself
4391
+				continue; // ignore multipart/alternative itself
4392 4392
 			}
4393 4393
 
4394 4394
 			$mimePart = $_structure->getPart($mime_id);
4395 4395
 
4396
-			switch($mimePart->getPrimaryType())
4396
+			switch ($mimePart->getPrimaryType())
4397 4397
 			{
4398 4398
 				case 'text':
4399
-					switch($mimePart->getSubType())
4399
+					switch ($mimePart->getSubType())
4400 4400
 					{
4401 4401
 						case 'plain':
4402 4402
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4409,7 +4409,7 @@  discard block
 block discarded – undo
4409 4409
 					break;
4410 4410
 
4411 4411
 				case 'multipart':
4412
-					switch($mimePart->getSubType())
4412
+					switch ($mimePart->getSubType())
4413 4413
 					{
4414 4414
 						case 'related':
4415 4415
 						case 'mixed':
@@ -4431,13 +4431,13 @@  discard block
 block discarded – undo
4431 4431
 			}
4432 4432
 		}
4433 4433
 
4434
-		switch($_htmlMode)
4434
+		switch ($_htmlMode)
4435 4435
 		{
4436 4436
 			case 'html_only':
4437 4437
 			case 'always_display':
4438 4438
 				if ($partHTML)
4439 4439
 				{
4440
-					switch($partHTML->getSubType())
4440
+					switch ($partHTML->getSubType())
4441 4441
 					{
4442 4442
 						case 'related':
4443 4443
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4449,7 +4449,7 @@  discard block
 block discarded – undo
4449 4449
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4450 4450
 					}
4451 4451
 				}
4452
-				elseif ($partText && $_htmlMode=='always_display')
4452
+				elseif ($partText && $_htmlMode == 'always_display')
4453 4453
 				{
4454 4454
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4455 4455
 				}
@@ -4495,7 +4495,7 @@  discard block
 block discarded – undo
4495 4495
 	 * @param array	&$skipParts - passed by reference to have control/knowledge which parts are already fetched
4496 4496
 	 * @return array containing the desired part
4497 4497
 	 */
4498
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4498
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array())
4499 4499
 	{
4500 4500
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4501 4501
 		$bodyPart = array();
@@ -4504,7 +4504,7 @@  discard block
 block discarded – undo
4504 4504
 		$ignore_first_part = true;
4505 4505
 		//$skipParts = array();
4506 4506
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4507
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4507
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4508 4508
 		{
4509 4509
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4510 4510
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4512,9 +4512,9 @@  discard block
 block discarded – undo
4512 4512
 			{
4513 4513
 				$ignore_first_part = false;
4514 4514
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4515
-				continue;	// ignore multipart/mixed itself
4515
+				continue; // ignore multipart/mixed itself
4516 4516
 			}
4517
-			if (array_key_exists($mime_id,$skipParts))
4517
+			if (array_key_exists($mime_id, $skipParts))
4518 4518
 			{
4519 4519
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4520 4520
 				continue;
@@ -4522,11 +4522,11 @@  discard block
 block discarded – undo
4522 4522
 
4523 4523
 			$part = $_structure->getPart($mime_id);
4524 4524
 
4525
-			switch($part->getPrimaryType())
4525
+			switch ($part->getPrimaryType())
4526 4526
 			{
4527 4527
 				case 'multipart':
4528 4528
 					if ($part->getDisposition() == 'attachment') continue;
4529
-					switch($part->getSubType())
4529
+					switch ($part->getSubType())
4530 4530
 					{
4531 4531
 						case 'alternative':
4532 4532
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen));
@@ -4542,15 +4542,15 @@  discard block
 block discarded – undo
4542 4542
 					}
4543 4543
 					break;
4544 4544
 				case 'application':
4545
-					switch($part->getSubType())
4545
+					switch ($part->getSubType())
4546 4546
 					{
4547 4547
 						case 'pgp-encrypted':
4548
-							if (($part = $_structure->getPart($mime_id+1)) &&
4548
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4549 4549
 								$part->getType() == 'application/octet-stream')
4550 4550
 							{
4551 4551
 								$this->fetchPartContents($_uid, $part);
4552
-								$skipParts[$mime_id]=$mime_type;
4553
-								$skipParts[$mime_id+1]=$part->getType();
4552
+								$skipParts[$mime_id] = $mime_type;
4553
+								$skipParts[$mime_id + 1] = $part->getType();
4554 4554
 								$bodyPart[] = array(
4555 4555
 									'body'		=> $part->getContents(array(
4556 4556
 										'stream' => false,
@@ -4564,15 +4564,15 @@  discard block
 block discarded – undo
4564 4564
 					break;
4565 4565
 
4566 4566
 				case 'text':
4567
-					switch($part->getSubType())
4567
+					switch ($part->getSubType())
4568 4568
 					{
4569 4569
 						case 'plain':
4570 4570
 						case 'html':
4571 4571
 						case 'calendar': // inline ics/ical files
4572
-							if($part->getDisposition() != 'attachment')
4572
+							if ($part->getDisposition() != 'attachment')
4573 4573
 							{
4574 4574
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4575
-								$skipParts[$mime_id]=$mime_type;
4575
+								$skipParts[$mime_id] = $mime_type;
4576 4576
 							}
4577 4577
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4578 4578
 							break;
@@ -4581,16 +4581,16 @@  discard block
 block discarded – undo
4581 4581
 
4582 4582
 				case 'message':
4583 4583
 					//skip attachments
4584
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4584
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4585 4585
 					{
4586 4586
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4587
-						$skipParts[$mime_id]=$mime_type;
4587
+						$skipParts[$mime_id] = $mime_type;
4588 4588
 					}
4589 4589
 					// do not descend into attached Messages
4590
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4590
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4591 4591
 					{
4592 4592
 						$skipParts[$mime_id.'.0'] = $mime_type;
4593
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4593
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4594 4594
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4595 4595
 						//break 2;
4596 4596
 					}
@@ -4631,13 +4631,13 @@  discard block
 block discarded – undo
4631 4631
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4632 4632
 	 * @return string|resource
4633 4633
 	 */
4634
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4634
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4635 4635
 	{
4636
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4636
+		if (self::$debug) error_log(__METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4637 4637
 
4638 4638
 		if (empty($_folder))
4639 4639
 		{
4640
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4640
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4641 4641
 		}
4642 4642
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4643 4643
 		// querying contents of body part
@@ -4648,11 +4648,11 @@  discard block
 block discarded – undo
4648 4648
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4649 4649
 		$fetchParams = array(
4650 4650
 			'peek' => $_preserveSeen,
4651
-			'decode' => true,	// try decode on server, does NOT neccessary work
4651
+			'decode' => true, // try decode on server, does NOT neccessary work
4652 4652
 		);
4653
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4653
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4654 4654
 		{
4655
-			$_tryDecodingServerside=false;
4655
+			$_tryDecodingServerside = false;
4656 4656
 			$fetchParams = array(
4657 4657
 				'peek' => $_preserveSeen,
4658 4658
 			);
@@ -4672,12 +4672,12 @@  discard block
 block discarded – undo
4672 4672
 		}
4673 4673
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4674 4674
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4675
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4675
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4676 4676
 		{
4677 4677
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4678 4678
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4679 4679
 		}
4680
-		return ($partToReturn?$partToReturn:null);
4680
+		return ($partToReturn ? $partToReturn : null);
4681 4681
 	}
4682 4682
 
4683 4683
 	/**
@@ -4690,13 +4690,13 @@  discard block
 block discarded – undo
4690 4690
 	 * @param boolean $_stream = false true return a stream, false return string
4691 4691
 	 * @return array containing the desired text part, mimeType and charset
4692 4692
 	 */
4693
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4693
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4694 4694
 	{
4695 4695
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4696 4696
 		$bodyPart = array();
4697
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4697
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4698 4698
 
4699
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4699
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4700 4700
 		{
4701 4701
 			$bodyPart = array(
4702 4702
 				'error'		=> 1,
@@ -4742,10 +4742,10 @@  discard block
 block discarded – undo
4742 4742
 	 * @param string $_folder folder to work on
4743 4743
 	 * @return array containing the message body, mimeType and charset
4744 4744
 	 */
4745
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4745
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '')
4746 4746
 	{
4747 4747
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4748
-		if($_htmlOptions != '') {
4748
+		if ($_htmlOptions != '') {
4749 4749
 			$this->htmlOptions = $_htmlOptions;
4750 4750
 		}
4751 4751
 		if (empty($_folder))
@@ -4766,7 +4766,7 @@  discard block
 block discarded – undo
4766 4766
 			return array(
4767 4767
 				array(
4768 4768
 					'error'		=> 1,
4769
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4769
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4770 4770
 					'mimeType'	=> 'text/plain',
4771 4771
 					'charSet'	=> self::$displayCharset,
4772 4772
 				)
@@ -4779,7 +4779,7 @@  discard block
 block discarded – undo
4779 4779
 			//_debug_array($_structure->getMimeId()); exit;
4780 4780
 		}
4781 4781
 
4782
-		switch($_structure->getPrimaryType())
4782
+		switch ($_structure->getPrimaryType())
4783 4783
 		{
4784 4784
 			case 'application':
4785 4785
 				return array(
@@ -4791,7 +4791,7 @@  discard block
 block discarded – undo
4791 4791
 				);
4792 4792
 
4793 4793
 			case 'multipart':
4794
-				switch($_structure->getSubType())
4794
+				switch ($_structure->getSubType())
4795 4795
 				{
4796 4796
 					case 'alternative':
4797 4797
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
@@ -4825,7 +4825,7 @@  discard block
 block discarded – undo
4825 4825
 				$bodyPart = array();
4826 4826
 				if ($_structure->getDisposition() != 'attachment')
4827 4827
 				{
4828
-					switch($_structure->getSubType())
4828
+					switch ($_structure->getSubType())
4829 4829
 					{
4830 4830
 						case 'calendar':
4831 4831
 							// this is handeled in getTextPart
@@ -4841,11 +4841,11 @@  discard block
 block discarded – undo
4841 4841
 
4842 4842
 			case 'attachment':
4843 4843
 			case 'message':
4844
-				switch($_structure->getSubType())
4844
+				switch ($_structure->getSubType())
4845 4845
 				{
4846 4846
 					case 'rfc822':
4847 4847
 						$newStructure = $_structure->getParts();
4848
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4848
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4849 4849
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4850 4850
 				}
4851 4851
 				break;
@@ -4873,11 +4873,11 @@  discard block
 block discarded – undo
4873 4873
 	{
4874 4874
 		if (is_array($_bodyParts))
4875 4875
 		{
4876
-			foreach($_bodyParts as $singleBodyPart)
4876
+			foreach ($_bodyParts as $singleBodyPart)
4877 4877
 			{
4878 4878
 				if (!isset($singleBodyPart['body'])) {
4879 4879
 					$buff = self::normalizeBodyParts($singleBodyPart);
4880
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4880
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4881 4881
 					continue;
4882 4882
 				}
4883 4883
 				$body2return[] = $singleBodyPart;
@@ -4898,14 +4898,14 @@  discard block
 block discarded – undo
4898 4898
 	 * @param boolean $useTidy  switch to use tidy
4899 4899
 	 * @return string a preformatted string with the mails converted to text
4900 4900
 	 */
4901
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4901
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4902 4902
 	{
4903
-		$message='';
4904
-		for($i=0; $i<count($bodyParts); $i++)
4903
+		$message = '';
4904
+		for ($i = 0; $i < count($bodyParts); $i++)
4905 4905
 		{
4906 4906
 			if (!isset($bodyParts[$i]['body'])) {
4907 4907
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4908
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4908
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
4909 4909
 				continue;
4910 4910
 			}
4911 4911
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -4930,32 +4930,32 @@  discard block
 block discarded – undo
4930 4930
 				'(R)',
4931 4931
 			);
4932 4932
 
4933
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4933
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4934 4934
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
4935 4935
 			{
4936
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4936
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
4937 4937
 			}
4938 4938
 
4939
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4939
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4940 4940
 			// add line breaks to $bodyParts
4941 4941
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4942
-			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4942
+			$newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4943 4943
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4944 4944
 			$mailClass->activeMimeType = 'text/plain';
4945 4945
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
4946 4946
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4947 4947
 				if (!$preserveHTML)
4948 4948
 				{
4949
-					$alreadyHtmlLawed=false;
4949
+					$alreadyHtmlLawed = false;
4950 4950
 					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
4951
-					$newBody = str_replace("\n"," ",$newBody);
4951
+					$newBody = str_replace("\n", " ", $newBody);
4952 4952
 					// convert HTML to text, as we dont want HTML in infologs
4953 4953
 					if ($useTidy && extension_loaded('tidy'))
4954 4954
 					{
4955 4955
 						$tidy = new tidy();
4956
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
4956
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
4957 4957
 						// Found errors. Strip it all so there's some output
4958
-						if($tidy->getStatus() == 2)
4958
+						if ($tidy->getStatus() == 2)
4959 4959
 						{
4960 4960
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
4961 4961
 						}
@@ -4966,7 +4966,7 @@  discard block
 block discarded – undo
4966 4966
 						if (!$preserveHTML)
4967 4967
 						{
4968 4968
 							// filter only the 'body', as we only want that part, if we throw away the html
4969
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4969
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4970 4970
 							if ($matches[2])
4971 4971
 							{
4972 4972
 								$hasOther = true;
@@ -4977,7 +4977,7 @@  discard block
 block discarded – undo
4977 4977
 					else
4978 4978
 					{
4979 4979
 						// htmLawed filter only the 'body'
4980
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4980
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4981 4981
 						if ($matches[2])
4982 4982
 						{
4983 4983
 							$hasOther = true;
@@ -4986,17 +4986,17 @@  discard block
 block discarded – undo
4986 4986
 						$htmLawed = new Html\HtmLawed();
4987 4987
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
4988 4988
 						// as we switched off HTMLaweds tidy functionality
4989
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4990
-						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4991
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
4992
-						$alreadyHtmlLawed=true;
4989
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
4990
+						$newBody = $htmLawed->run($newBody, self::$htmLawed_config);
4991
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
4992
+						$alreadyHtmlLawed = true;
4993 4993
 					}
4994 4994
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4995
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
4995
+					if ($preserveHTML == false) $newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, true, true);
4996 4996
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4997
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4997
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4998 4998
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4999
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
4999
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
5000 5000
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5001 5001
 				}
5002 5002
 				$message .= $newBody;
@@ -5005,9 +5005,9 @@  discard block
 block discarded – undo
5005 5005
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
5006 5006
 			//use Mail\Html::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
5007 5007
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
5008
-			$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,false,false);
5008
+			$newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, false, false);
5009 5009
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
5010
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
5010
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
5011 5011
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
5012 5012
 			$message .= $newBody;
5013 5013
 			//continue;
@@ -5015,27 +5015,27 @@  discard block
 block discarded – undo
5015 5015
 		return $message;
5016 5016
 	}
5017 5017
 
5018
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
5018
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
5019 5019
 	{
5020 5020
 		$lines = explode("\n", $str);
5021 5021
 		$newStr = '';
5022
-		foreach($lines as $line)
5022
+		foreach ($lines as $line)
5023 5023
 		{
5024 5024
 			// replace tabs by 8 space chars, or any tab only counts one char
5025 5025
 			//$line = str_replace("\t","        ",$line);
5026 5026
 			//$newStr .= wordwrap($line, $cols, $cut);
5027
-			$allowedLength = $cols-strlen($cut);
5027
+			$allowedLength = $cols - strlen($cut);
5028 5028
 			//dont try to break lines with links, chance is we mess up the text is way too big
5029
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
5030
-				($dontbreaklinesstartingwith==false ||
5029
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
5030
+				($dontbreaklinesstartingwith == false ||
5031 5031
 				 ($dontbreaklinesstartingwith &&
5032
-				  strlen($dontbreaklinesstartingwith)>=1 &&
5033
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5032
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
5033
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5034 5034
 				 )
5035 5035
 				)
5036 5036
 			   )
5037 5037
 			{
5038
-				$s=explode(" ", $line);
5038
+				$s = explode(" ", $line);
5039 5039
 				$line = "";
5040 5040
 				$linecnt = 0;
5041 5041
 				foreach ($s as &$v) {
@@ -5043,22 +5043,22 @@  discard block
 block discarded – undo
5043 5043
 					// only break long words within the wordboundaries,
5044 5044
 					// but it may destroy links, so we check for href and dont do it if we find one
5045 5045
 					// we check for any html within the word, because we do not want to break html by accident
5046
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
5046
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
5047 5047
 					{
5048
-						$v=wordwrap($v, $allowedLength, $cut, true);
5048
+						$v = wordwrap($v, $allowedLength, $cut, true);
5049 5049
 					}
5050 5050
 					// the rest should be broken at the start of the new word that exceeds the limit
5051
-					if ($linecnt+$cnt > $allowedLength) {
5052
-						$v=$cut.$v;
5051
+					if ($linecnt + $cnt > $allowedLength) {
5052
+						$v = $cut.$v;
5053 5053
 						#$linecnt = 0;
5054
-						$linecnt =strlen($v)-strlen($cut);
5054
+						$linecnt = strlen($v) - strlen($cut);
5055 5055
 					} else {
5056 5056
 						$linecnt += $cnt;
5057 5057
 					}
5058 5058
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5059 5059
 				}
5060 5060
 			}
5061
-			$newStr .= $line . "\n";
5061
+			$newStr .= $line."\n";
5062 5062
 		}
5063 5063
 		return $newStr;
5064 5064
 	}
@@ -5073,12 +5073,12 @@  discard block
 block discarded – undo
5073 5073
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
5074 5074
 	 * @return array the message header
5075 5075
 	 */
5076
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5076
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
5077 5077
 	{
5078 5078
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5079
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5079
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5080 5080
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5081
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5081
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
5082 5082
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5083 5083
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5084 5084
 			$uidsToFetch->add($_uid);
@@ -5091,7 +5091,7 @@  discard block
 block discarded – undo
5091 5091
 				'ids' => $uidsToFetch,
5092 5092
 			));
5093 5093
 			if (is_object($headersNew)) {
5094
-				foreach($headersNew as &$_headerObject) {
5094
+				foreach ($headersNew as &$_headerObject) {
5095 5095
 					$env = $_headerObject->getEnvelope();
5096 5096
 					//_debug_array($envFields->singleFields());
5097 5097
 					$singleFields = $envFields->singleFields();
@@ -5106,34 +5106,34 @@  discard block
 block discarded – undo
5106 5106
 							case 'bcc':
5107 5107
 							case 'sender':
5108 5108
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5109
-								$envelope[$v]=$env->$v->addresses;
5109
+								$envelope[$v] = $env->$v->addresses;
5110 5110
 								$address = array();
5111 5111
 								if (!is_array($envelope[$v])) break;
5112 5112
 								foreach ($envelope[$v] as $k => $ad)
5113 5113
 								{
5114
-									if (stripos($ad,'@')===false)
5114
+									if (stripos($ad, '@') === false)
5115 5115
 									{
5116
-										$remember=$k;
5116
+										$remember = $k;
5117 5117
 									}
5118 5118
 									else
5119 5119
 									{
5120
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
5121
-										$remember=null;
5120
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
5121
+										$remember = null;
5122 5122
 									}
5123 5123
 								}
5124 5124
 								$envelope[$v] = $address;
5125 5125
 								break;
5126 5126
 							case 'date':
5127
-								$envelope[$v]=DateTime::to($env->$v);
5127
+								$envelope[$v] = DateTime::to($env->$v);
5128 5128
 								break;
5129 5129
 							default:
5130
-								$envelope[$v]=$env->$v;
5130
+								$envelope[$v] = $env->$v;
5131 5131
 						}
5132 5132
 					}
5133
-					$envelope['size']=$_headerObject->getSize();
5133
+					$envelope['size'] = $_headerObject->getSize();
5134 5134
 				}
5135 5135
 			}
5136
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
5136
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
5137 5137
 			//if ($decode) _debug_array($envelope);
5138 5138
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
5139 5139
 			if ($decode)
@@ -5141,19 +5141,19 @@  discard block
 block discarded – undo
5141 5141
 				foreach ($envelope as $key => $rvV)
5142 5142
 				{
5143 5143
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5144
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5144
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5145 5145
 				}
5146 5146
 			}
5147 5147
 			return $envelope;
5148 5148
 		} else {
5149 5149
 
5150
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5150
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
5151 5151
 
5152 5152
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
5153 5153
 			//_debug_array($headers);
5154 5154
 			$newData = array(
5155 5155
 				'DATE'		=> $headers['DATE'],
5156
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5156
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
5157 5157
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5158 5158
 			);
5159 5159
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -5164,11 +5164,11 @@  discard block
 block discarded – undo
5164 5164
 			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5165 5165
 			//_debug_array($newData);
5166 5166
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5167
-			foreach($recepientList as $recepientType) {
5168
-				if(isset($headers[$recepientType])) {
5169
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5167
+			foreach ($recepientList as $recepientType) {
5168
+				if (isset($headers[$recepientType])) {
5169
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
5170 5170
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5171
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5171
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5172 5172
 						$addressData = array(
5173 5173
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5174 5174
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5176,15 +5176,15 @@  discard block
 block discarded – undo
5176 5176
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5177 5177
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5178 5178
 						);
5179
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5179
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
5180 5180
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5181 5181
 						} else {
5182 5182
 							$addressData['RFC822_EMAIL'] = 'NIL';
5183 5183
 						}
5184
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5184
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
5185 5185
 					}
5186 5186
 				} else {
5187
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5187
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5188 5188
 						$newData[$recepientType] = $newData['FROM'];
5189 5189
 					} else {
5190 5190
 						$newData[$recepientType] = array();
@@ -5206,10 +5206,10 @@  discard block
 block discarded – undo
5206 5206
 	 * @param string $_folder folder to work on
5207 5207
 	 * @return array|Horde_Mime_Headers message header as array or object
5208 5208
 	 */
5209
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5209
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
5210 5210
 	{
5211 5211
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5212
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5212
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5213 5213
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5214 5214
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5215 5215
 		$uidsToFetch->add($_uid);
@@ -5217,7 +5217,7 @@  discard block
 block discarded – undo
5217 5217
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5218 5218
 		if ($_partID != '')
5219 5219
 		{
5220
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
5220
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
5221 5221
 			$fquery->structure();
5222 5222
 		}
5223 5223
 		else
@@ -5230,18 +5230,18 @@  discard block
 block discarded – undo
5230 5230
 			'ids' => $uidsToFetch,
5231 5231
 		));
5232 5232
 		if (is_object($headersNew)) {
5233
-			foreach($headersNew as $_fetchObject)
5233
+			foreach ($headersNew as $_fetchObject)
5234 5234
 			{
5235
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5235
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5236 5236
 				if ($_partID != '')
5237 5237
 				{
5238 5238
 					$mailStructureObject = $_fetchObject->getStructure();
5239 5239
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5240 5240
 					{
5241
-						if ($mime_id==$_partID)
5241
+						if ($mime_id == $_partID)
5242 5242
 						{
5243 5243
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
5244
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5244
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5245 5245
 							break;
5246 5246
 						}
5247 5247
 					}
@@ -5254,15 +5254,15 @@  discard block
 block discarded – undo
5254 5254
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5255 5255
 				return $headers;
5256 5256
 			}
5257
-			$retValue = is_object($headers) ? $headers->toArray():array();
5257
+			$retValue = is_object($headers) ? $headers->toArray() : array();
5258 5258
 			if ($size) $retValue['size'] = $size;
5259 5259
 		}
5260
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
5260
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
5261 5261
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
5262 5262
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
5263 5263
 		if (is_array($retValue['SUBJECT']))
5264 5264
 		{
5265
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
5265
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
5266 5266
 		}
5267 5267
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
5268 5268
 		if ($decode)
@@ -5270,7 +5270,7 @@  discard block
 block discarded – undo
5270 5270
 			foreach ($retValue as $key => $rvV)
5271 5271
 			{
5272 5272
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5273
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5273
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5274 5274
 			}
5275 5275
 		}
5276 5276
 		return $retValue;
@@ -5287,14 +5287,14 @@  discard block
 block discarded – undo
5287 5287
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5288 5288
 	{
5289 5289
 		static $rawHeaders;
5290
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5290
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5291 5291
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5292 5292
 
5293
-		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);
5294
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5293
+		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);
5294
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5295 5295
 		{
5296 5296
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5297
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5297
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5298 5298
 		}
5299 5299
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5300 5300
 		$uid = $_uid;
@@ -5304,7 +5304,7 @@  discard block
 block discarded – undo
5304 5304
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5305 5305
 		if ($_partID != '')
5306 5306
 		{
5307
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5307
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5308 5308
 			$fquery->structure();
5309 5309
 		}
5310 5310
 		else
@@ -5315,14 +5315,14 @@  discard block
 block discarded – undo
5315 5315
 			'ids' => $uidsToFetch,
5316 5316
 		));
5317 5317
 		if (is_object($headersNew)) {
5318
-			foreach($headersNew as &$_headerObject) {
5318
+			foreach ($headersNew as &$_headerObject) {
5319 5319
 				$retValue = $_headerObject->getHeaderText();
5320 5320
 				if ($_partID != '')
5321 5321
 				{
5322 5322
 					$mailStructureObject = $_headerObject->getStructure();
5323 5323
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5324 5324
 					{
5325
-						if ($mime_id==$_partID)
5325
+						if ($mime_id == $_partID)
5326 5326
 						{
5327 5327
 							$retValue = $_headerObject->getHeaderText($mime_id);
5328 5328
 						}
@@ -5330,8 +5330,8 @@  discard block
 block discarded – undo
5330 5330
 				}
5331 5331
 			}
5332 5332
 		}
5333
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5334
-		Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5333
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5334
+		Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5335 5335
 		return $retValue;
5336 5336
 	}
5337 5337
 
@@ -5344,25 +5344,25 @@  discard block
 block discarded – undo
5344 5344
 	{
5345 5345
 		$style = '';
5346 5346
 		if (empty($_bodyParts)) return "";
5347
-		foreach((array)$_bodyParts as $singleBodyPart) {
5347
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5348 5348
 			if (!isset($singleBodyPart['body'])) {
5349 5349
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5350 5350
 				$style .= $singleBodyPart['body'];
5351 5351
 				continue;
5352 5352
 			}
5353 5353
 
5354
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5354
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5355 5355
 			$singleBodyPart['body'] = Translation::convert(
5356 5356
 				$singleBodyPart['body'],
5357 5357
 				strtolower($singleBodyPart['charSet'])
5358 5358
 			);
5359 5359
 			$ct = 0;
5360
-			$newStyle=array();
5361
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5362
-			if ($ct>0)
5360
+			$newStyle = array();
5361
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5362
+			if ($ct > 0)
5363 5363
 			{
5364 5364
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5365
-				$style2buffer = implode('',$newStyle[0]);
5365
+				$style2buffer = implode('', $newStyle[0]);
5366 5366
 			}
5367 5367
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5368 5368
 			{
@@ -5370,7 +5370,7 @@  discard block
 block discarded – undo
5370 5370
 				$test = json_encode($style2buffer);
5371 5371
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5372 5372
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5373
-				if ($test=="null" && strlen($style2buffer)>0)
5373
+				if ($test == "null" && strlen($style2buffer) > 0)
5374 5374
 				{
5375 5375
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5376 5376
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.Translation::detect_encoding($style2buffer));
@@ -5381,19 +5381,19 @@  discard block
 block discarded – undo
5381 5381
 		}
5382 5382
 		// clean out comments and stuff
5383 5383
 		$search = array(
5384
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5384
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5385 5385
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5386 5386
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5387 5387
 		);
5388
-		$style = preg_replace($search,"",$style);
5388
+		$style = preg_replace($search, "", $style);
5389 5389
 
5390 5390
 		// CSS Security
5391 5391
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5392
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5393
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5392
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5393
+		if (stripos($css, 'script') !== false) Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5394 5394
 		// 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
5395 5395
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5396
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5396
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5397 5397
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5398 5398
 		// TODO: we may have to strip urls and maybe comments and ifs
5399 5399
 		return $css;
@@ -5407,16 +5407,16 @@  discard block
 block discarded – undo
5407 5407
 	 * @param string $_folder folder to work on
5408 5408
 	 * @return string the message body
5409 5409
 	 */
5410
-	function getMessageRawBody($_uid, $_partID = '', $_folder='')
5410
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '')
5411 5411
 	{
5412 5412
 		//TODO: caching einbauen static!
5413 5413
 		static $rawBody;
5414 5414
 		if (is_null($rawBody)) $rawBody = array();
5415
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5416
-		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5415
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5416
+		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5417 5417
 		{
5418 5418
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5419
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5419
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5420 5420
 		}
5421 5421
 
5422 5422
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5429,13 +5429,13 @@  discard block
 block discarded – undo
5429 5429
 		if ($_partID != '')
5430 5430
 		{
5431 5431
 			$fquery->structure();
5432
-			$fquery->bodyPart($_partID,array('peek'=>true));
5432
+			$fquery->bodyPart($_partID, array('peek'=>true));
5433 5433
 		}
5434 5434
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5435 5435
 			'ids' => $uidsToFetch,
5436 5436
 		));
5437 5437
 		if (is_object($headersNew)) {
5438
-			foreach($headersNew as &$_headerObject) {
5438
+			foreach ($headersNew as &$_headerObject) {
5439 5439
 				$body = $_headerObject->getFullMsg();
5440 5440
 				if ($_partID != '')
5441 5441
 				{
@@ -5443,7 +5443,7 @@  discard block
 block discarded – undo
5443 5443
 					//_debug_array($mailStructureObject->contentTypeMap());
5444 5444
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5445 5445
 					{
5446
-						if ($mime_id==$_partID)
5446
+						if ($mime_id == $_partID)
5447 5447
 						{
5448 5448
 							$body = $_headerObject->getBodyPart($mime_id);
5449 5449
 						}
@@ -5452,7 +5452,7 @@  discard block
 block discarded – undo
5452 5452
 			}
5453 5453
 		}
5454 5454
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5455
-		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5455
+		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5456 5456
 		return $body;
5457 5457
 	}
5458 5458
 
@@ -5466,13 +5466,13 @@  discard block
 block discarded – undo
5466 5466
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5467 5467
 	 * @return Horde_Mime_Part
5468 5468
 	 */
5469
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5469
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5470 5470
 	{
5471
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5471
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5472 5472
 
5473 5473
 		if (empty($_folder))
5474 5474
 		{
5475
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5475
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5476 5476
 		}
5477 5477
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5478 5478
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5490,7 +5490,7 @@  discard block
 block discarded – undo
5490 5490
 				'ids' => $uidsToFetch,
5491 5491
 			))->first();
5492 5492
 
5493
-			return is_object($mail)?$mail->getStructure():null;
5493
+			return is_object($mail) ? $mail->getStructure() : null;
5494 5494
 		}
5495 5495
 		catch (\Exception $e)
5496 5496
 		{
@@ -5513,14 +5513,14 @@  discard block
 block discarded – undo
5513 5513
 	 * @param string $_folder folder to work on
5514 5514
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5515 5515
 	 */
5516
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5516
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5517 5517
 	{
5518
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5519
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5518
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5519
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5520 5520
 		$attachments = array();
5521 5521
 		if (!isset($_structure))
5522 5522
 		{
5523
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5523
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5524 5524
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5525 5525
 		}
5526 5526
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5528,7 +5528,7 @@  discard block
 block discarded – undo
5528 5528
 		$skipParts = array();
5529 5529
 		$tnefParts = array();
5530 5530
 		$skip = 0;
5531
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5531
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5532 5532
 		{
5533 5533
 			// skip multipart/encrypted incl. its two sub-parts, as we show 2. sub-part as body to be decrypted client-side
5534 5534
 			if ($mime_type == 'multipart/encrypted')
@@ -5536,7 +5536,7 @@  discard block
 block discarded – undo
5536 5536
 				$skip = 2;
5537 5537
 				continue;
5538 5538
 			}
5539
-			elseif($skip)
5539
+			elseif ($skip)
5540 5540
 			{
5541 5541
 				$skip--;
5542 5542
 				continue;
@@ -5550,10 +5550,10 @@  discard block
 block discarded – undo
5550 5550
 			$partPrimaryType = $part->getPrimaryType();
5551 5551
 			// we only want to retrieve the attachments of the current mail, not those of possible
5552 5552
 			// attached mails
5553
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5553
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5554 5554
 			{
5555 5555
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5556
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5556
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5557 5557
 			}
5558 5558
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5559 5559
 			{
@@ -5561,27 +5561,27 @@  discard block
 block discarded – undo
5561 5561
 				// attachment with no link to show the attachment inline.
5562 5562
 				// Considering this: we "list" everything that matches the above criteria
5563 5563
 				// as attachment in order to not loose/miss information on our data
5564
-				$partDisposition='attachment';
5564
+				$partDisposition = 'attachment';
5565 5565
 			}
5566 5566
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5567
-			if (array_key_exists($mime_id,$skipParts)) continue;
5567
+			if (array_key_exists($mime_id, $skipParts)) continue;
5568 5568
 
5569 5569
 			if ($partDisposition == 'attachment' ||
5570
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5570
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5571 5571
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5572
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5572
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5573 5573
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5574 5574
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5575 5575
 			{
5576 5576
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5577 5577
 				// we attempt to fetch "ourselves"
5578
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5578
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5579 5579
 				$attachment = $part->getAllDispositionParameters();
5580 5580
 				$attachment['disposition'] = $part->getDisposition();
5581 5581
 				$attachment['mimeType'] = $mime_type;
5582 5582
 				$attachment['uid'] = $_uid;
5583 5583
 				$attachment['partID'] = $mime_id;
5584
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5584
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5585 5585
 				if ($fetchTextCalendar)
5586 5586
 				{
5587 5587
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5591,11 +5591,11 @@  discard block
 block discarded – undo
5591 5591
 				}
5592 5592
 				$attachment['size'] = $part->getBytes();
5593 5593
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5594
-				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);
5594
+				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);
5595 5595
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5596 5596
 				//typical winmail.dat attachment is
5597 5597
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5598
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5598
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5599 5599
 				{
5600 5600
 					$tnefParts[] = $attachment;
5601 5601
 				}
@@ -5610,31 +5610,31 @@  discard block
 block discarded – undo
5610 5610
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5611 5611
 			foreach ($tnefParts as $k => $tnp)
5612 5612
 			{
5613
-				$tnefResolved=false;
5614
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5613
+				$tnefResolved = false;
5614
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5615 5615
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5616 5616
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5617 5617
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5618 5618
 				// we need to build Something that meets the needs
5619 5619
 				if ($myTnef)
5620 5620
 				{
5621
-					foreach($myTnef->getParts() as $mime_id => $part)
5621
+					foreach ($myTnef->getParts() as $mime_id => $part)
5622 5622
 					{
5623
-						$tnefResolved=true;
5623
+						$tnefResolved = true;
5624 5624
 						$attachment = $part->getAllDispositionParameters();
5625 5625
 						$attachment['disposition'] = $part->getDisposition();
5626 5626
 						$attachment['mimeType'] = $part->getType();
5627 5627
 						$attachment['uid'] = $tnp['uid'];
5628 5628
 						$attachment['partID'] = $tnp['partID'];
5629 5629
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5630
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5630
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5631 5631
 						$attachment['size'] = $part->getBytes();
5632 5632
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5633
-						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']);
5633
+						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']);
5634 5634
 						$attachments[] = $attachment;
5635 5635
 					}
5636 5636
 				}
5637
-				if ($tnefResolved===false) $attachments[]=$tnp;
5637
+				if ($tnefResolved === false) $attachments[] = $tnp;
5638 5638
 			}
5639 5639
 		}
5640 5640
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5649,9 +5649,9 @@  discard block
 block discarded – undo
5649 5649
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5650 5650
 	 *	return false if there's no attachments or failure
5651 5651
 	 */
5652
-	public function tnef_decoder( $data )
5652
+	public function tnef_decoder($data)
5653 5653
 	{
5654
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5654
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5655 5655
 		{
5656 5656
 			if (!class_exists($class))
5657 5657
 			{
@@ -5683,7 +5683,7 @@  discard block
 block discarded – undo
5683 5683
 				$tmp_part->setContents($data['stream']);
5684 5684
 				$tmp_part->setDescription($data['name']);
5685 5685
 
5686
-				$type = $data['type'] . '/' . $data['subtype'];
5686
+				$type = $data['type'].'/'.$data['subtype'];
5687 5687
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5688 5688
 				{
5689 5689
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5726,24 +5726,24 @@  discard block
 block discarded – undo
5726 5726
 	 *
5727 5727
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5728 5728
 	 */
5729
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5729
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5730 5730
 	{
5731
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5731
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5732 5732
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5733 5733
 		$attachments = array();
5734 5734
 		if ($tnef_parts)
5735 5735
 		{
5736
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5736
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5737 5737
 			{
5738 5738
 
5739 5739
 				$attachment = $part->getAllDispositionParameters();
5740 5740
 				$attachment['mimeType'] = $part->getType();
5741
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5741
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5742 5742
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5743 5743
 				if (empty($attachment['filename']))
5744 5744
 				{
5745
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5746
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5745
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5746
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5747 5747
 				}
5748 5748
 
5749 5749
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5767,10 +5767,10 @@  discard block
 block discarded – undo
5767 5767
 	 *
5768 5768
 	 * @return array
5769 5769
 	 */
5770
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5770
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5771 5771
 	{
5772 5772
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5773
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5773
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5774 5774
 
5775 5775
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5776 5776
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5783,36 +5783,36 @@  discard block
 block discarded – undo
5783 5783
 			'ids' => $uidsToFetch,
5784 5784
 		));
5785 5785
 		if (is_object($headersNew)) {
5786
-			foreach($headersNew as $id=>$_headerObject) {
5786
+			foreach ($headersNew as $id=>$_headerObject) {
5787 5787
 				$body = $_headerObject->getFullMsg();
5788 5788
 				if ($_partID != '')
5789 5789
 				{
5790 5790
 					$mailStructureObject = $_headerObject->getStructure();
5791 5791
 					$mailStructureObject->contentTypeMap();
5792 5792
 					$part = $mailStructureObject->getPart($_partID);
5793
-					$partDisposition = ($part?$part->getDisposition():'failed');
5794
-					if ($partDisposition=='failed')
5793
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5794
+					if ($partDisposition == 'failed')
5795 5795
 					{
5796 5796
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5797 5797
 					}
5798 5798
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5799 5799
 					// itself is only triggered to fetch attachments
5800
-					if (empty($partDisposition)) $partDisposition='attachment';
5801
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5800
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5801
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5802 5802
 					{
5803 5803
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5804 5804
 						$structure_mime = $part->getType();
5805 5805
 						$filename = $part->getName();
5806 5806
 						$charset = $part->getContentTypeParameter('charset');
5807 5807
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5808
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5808
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5809 5809
 						if ($_returnPart) return $part;
5810 5810
 					}
5811 5811
 				}
5812 5812
 			}
5813 5813
 		}
5814 5814
 		$ext = MimeMagic::mime2ext($structure_mime);
5815
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5815
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5816 5816
 		if (!$part)
5817 5817
 		{
5818 5818
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5830,20 +5830,20 @@  discard block
 block discarded – undo
5830 5830
 		// try guessing the mimetype, if we get the application/octet-stream
5831 5831
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
5832 5832
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5833
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5833
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5834 5834
 		{
5835 5835
 			//by now _uid is of type array
5836
-			$tnefResolved=false;
5837
-			$wantedPart=$_uid[0].'@'.$_partID;
5836
+			$tnefResolved = false;
5837
+			$wantedPart = $_uid[0].'@'.$_partID;
5838 5838
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5839 5839
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5840 5840
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5841 5841
 			// we need to build Something that meets the needs
5842 5842
 			if ($myTnef)
5843 5843
 			{
5844
-				foreach($myTnef->getParts() as $mime_id => $part)
5844
+				foreach ($myTnef->getParts() as $mime_id => $part)
5845 5845
 				{
5846
-					$tnefResolved=true;
5846
+					$tnefResolved = true;
5847 5847
 					$attachment = $part->getAllDispositionParameters();
5848 5848
 					$attachment['mimeType'] = $part->getType();
5849 5849
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5851,9 +5851,9 @@  discard block
 block discarded – undo
5851 5851
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5852 5852
 					{
5853 5853
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5854
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5854
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5855 5855
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5856
-						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']);
5856
+						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']);
5857 5857
 						$wmattach = $attachment;
5858 5858
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5859 5859
 
@@ -5863,7 +5863,7 @@  discard block
 block discarded – undo
5863 5863
 			if ($tnefResolved)
5864 5864
 			{
5865 5865
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5866
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5866
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5867 5867
 				$attachmentData = array(
5868 5868
 					'type'       => $wmattach['mimeType'],
5869 5869
 					'filename'   => $wmattach['filename'],
@@ -5887,21 +5887,21 @@  discard block
 block discarded – undo
5887 5887
 	 *	true:
5888 5888
 	 * @return Horde_Mime_Part
5889 5889
 	 */
5890
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5890
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5891 5891
 	{
5892 5892
 		// some static variables to avoid fetching the same mail multiple times
5893
-		static $uid=null, $part=null, $structure=null;
5893
+		static $uid = null, $part = null, $structure = null;
5894 5894
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5895 5895
 
5896
-		if(empty($_cid)) return false;
5896
+		if (empty($_cid)) return false;
5897 5897
 
5898 5898
 		if ($_uid != $uid || $_part != $part)
5899 5899
 		{
5900
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5900
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5901 5901
 		}
5902 5902
 		/** @var Horde_Mime_Part */
5903 5903
 		$attachment = null;
5904
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5904
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
5905 5905
 		{
5906 5906
 			$part = $structure->getPart($mime_id);
5907 5907
 
@@ -5953,16 +5953,16 @@  discard block
 block discarded – undo
5953 5953
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
5954 5954
 	 * @return Horde_Mime_Part
5955 5955
 	 */
5956
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5956
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
5957 5957
 	{
5958
-		if (is_null($part)) return null;//new Horde_Mime_Part;
5958
+		if (is_null($part)) return null; //new Horde_Mime_Part;
5959 5959
 		$encoding = null;
5960 5960
 		$fetchAsBinary = true;
5961
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
5961
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
5962 5962
 		// we need to set content on structure to decode transfer encoding
5963 5963
 		$part->setContents(
5964 5964
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
5965
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
5965
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
5966 5966
 
5967 5967
 		return $part;
5968 5968
 	}
@@ -5980,17 +5980,17 @@  discard block
 block discarded – undo
5980 5980
 	 * @return the id of the message appended or exception
5981 5981
 	 * @throws Exception\WrongUserinput
5982 5982
 	 */
5983
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
5983
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
5984 5984
 	{
5985 5985
 		if (!is_resource($_header))
5986 5986
 		{
5987
-			if (stripos($_header,'message-id:')===false)
5987
+			if (stripos($_header, 'message-id:') === false)
5988 5988
 			{
5989 5989
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
5990 5990
 			}
5991 5991
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
5992
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
5993
-			$_header .= str_replace("\n","\r\n",$_body);
5992
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
5993
+			$_header .= str_replace("\n", "\r\n", $_body);
5994 5994
 		}
5995 5995
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5996 5996
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -6008,7 +6008,7 @@  discard block
 block discarded – undo
6008 6008
 			// searched for the message-id then returning the uid found
6009 6009
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
6010 6010
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
6011
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
6011
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
6012 6012
 		}
6013 6013
 		catch (\Exception $e)
6014 6014
 		{
@@ -6020,7 +6020,7 @@  discard block
 block discarded – undo
6020 6020
 		//$messageid = true; // for debug reasons only
6021 6021
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
6022 6022
 		{
6023
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
6023
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
6024 6024
 			if ($list)
6025 6025
 			{
6026 6026
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -6060,27 +6060,27 @@  discard block
 block discarded – undo
6060 6060
 	 *				'attachments'=>$attachments,
6061 6061
 	 *				'headers'=>$headers,; boolean false on failure
6062 6062
 	 */
6063
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
6063
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
6064 6064
 	{
6065 6065
 			//echo __METHOD__." called for $uid,$partid <br>";
6066
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6066
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
6067 6067
 			if (empty($headers)) return false;
6068 6068
 			// dont force retrieval of the textpart, let mailClass preferences decide
6069
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6069
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
6070 6070
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
6071
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
6071
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
6072 6072
 			{
6073
-				foreach($bodyParts as $i => $part)
6073
+				foreach ($bodyParts as $i => $part)
6074 6074
 				{
6075
-					if ($bodyParts[$i]['mimeType']=='text/html')
6075
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
6076 6076
 					{
6077
-						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
6078
-						$bodyParts[$i]['mimeType']='text/plain';
6077
+						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
6078
+						$bodyParts[$i]['mimeType'] = 'text/plain';
6079 6079
 					}
6080 6080
 				}
6081 6081
 			}
6082 6082
 			//error_log(array2string($bodyParts));
6083
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6083
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
6084 6084
 
6085 6085
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6086 6086
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -6091,7 +6091,7 @@  discard block
 block discarded – undo
6091 6091
 
6092 6092
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6093 6093
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6094
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6094
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
6095 6095
 			$message = $headdata.$message;
6096 6096
 			//echo __METHOD__.'<br>';
6097 6097
 			//_debug_array($attachments);
@@ -6107,25 +6107,25 @@  discard block
 block discarded – undo
6107 6107
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
6108 6108
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
6109 6109
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
6110
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
6111
-						$headdata ='';
6110
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
6111
+						$headdata = '';
6112 6112
 						if ($mailcontent['headers'])
6113 6113
 						{
6114
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
6114
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
6115 6115
 						}
6116 6116
 						if ($mailcontent['message'])
6117 6117
 						{
6118
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6118
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6119 6119
 							$attachedMessages[] = array(
6120 6120
 								'type' => 'TEXT/PLAIN',
6121 6121
 								'name' => $mailcontent['subject'].'.txt',
6122 6122
 								'tmp_name' => $tempname,
6123 6123
 							);
6124
-							$tmpfile = fopen($tempname,'w');
6125
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
6124
+							$tmpfile = fopen($tempname, 'w');
6125
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
6126 6126
 							fclose($tmpfile);
6127 6127
 						}
6128
-						foreach($mailcontent['attachments'] as &$tmpval)
6128
+						foreach ($mailcontent['attachments'] as &$tmpval)
6129 6129
 						{
6130 6130
 							$attachedMessages[] = $tmpval;
6131 6131
 						}
@@ -6133,36 +6133,36 @@  discard block
 block discarded – undo
6133 6133
 					}
6134 6134
 					else
6135 6135
 					{
6136
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
6136
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
6137 6137
 
6138
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
6138
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
6139 6139
 						{
6140
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
6140
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
6141 6141
 							$attachments[$num]['attachment'] = $c->getContents();
6142 6142
 						}
6143 6143
 						// no attempt to convert, if we dont know about the charset
6144
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6144
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
6145 6145
 							// we do not try guessing the charset, if it is not set
6146 6146
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6147
-							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
6147
+							Translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
6148 6148
 						}
6149
-						if(in_array($attachments[$num]['name'], $file_list))
6149
+						if (in_array($attachments[$num]['name'], $file_list))
6150 6150
 						{
6151 6151
 							$dupe_count[$attachments[$num]['name']]++;
6152
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
6153
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
6152
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
6153
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
6154 6154
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
6155 6155
 						}
6156 6156
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
6157
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6158
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
6159
-						fwrite($tmpfile,$attachments[$num]['attachment']);
6157
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6158
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
6159
+						fwrite($tmpfile, $attachments[$num]['attachment']);
6160 6160
 						fclose($tmpfile);
6161 6161
 						$file_list[] = $attachments[$num]['name'];
6162 6162
 						unset($attachments[$num]['attachment']);
6163 6163
 					}
6164 6164
 				}
6165
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6165
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
6166 6166
 			}
6167 6167
 			return array(
6168 6168
 					'mailaddress'=>$mailaddress,
@@ -6184,10 +6184,10 @@  discard block
 block discarded – undo
6184 6184
 	{
6185 6185
 		$c = 0;
6186 6186
 		// use the standardIdentity
6187
-		foreach($_identities as $key => $acc) {
6188
-			if ($c==0) $identity = $acc;
6187
+		foreach ($_identities as $key => $acc) {
6188
+			if ($c == 0) $identity = $acc;
6189 6189
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6190
-			if ($key==$_profile_id) $identity = $acc;
6190
+			if ($key == $_profile_id) $identity = $acc;
6191 6191
 			$c++;
6192 6192
 		}
6193 6193
 		return $identity;
@@ -6199,29 +6199,29 @@  discard block
 block discarded – undo
6199 6199
 	 * @param bool createHTML do it with HTML breaks
6200 6200
 	 * @return string a preformatted string with the information of the header worked into it
6201 6201
 	 */
6202
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
6202
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
6203 6203
 	{
6204 6204
 		$headdata = null;
6205 6205
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6206
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6207
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6208
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6209
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6210
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6211
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6212
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6213
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6214
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
6206
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
6207
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
6208
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
6209
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
6210
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
6211
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
6212
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
6213
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
6214
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
6215 6215
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6216 6216
 		if (!empty($headdata))
6217 6217
 		{
6218
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6219
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
6220
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6218
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
6219
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
6220
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6221 6221
 		}
6222 6222
 		else
6223 6223
 		{
6224
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6224
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6225 6225
 		}
6226 6226
 		return $headdata;
6227 6227
 	}
@@ -6234,8 +6234,8 @@  discard block
 block discarded – undo
6234 6234
 	 */
6235 6235
 	static function adaptSubjectForImport($subject)
6236 6236
 	{
6237
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
6238
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
6237
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
6238
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
6239 6239
 		return $subject;
6240 6240
 	}
6241 6241
 
@@ -6247,15 +6247,15 @@  discard block
 block discarded – undo
6247 6247
 	static function convertAddressArrayToString($rfcAddressArray)
6248 6248
 	{
6249 6249
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
6250
-		$returnAddr ='';
6250
+		$returnAddr = '';
6251 6251
 		if (is_array($rfcAddressArray))
6252 6252
 		{
6253
-			foreach((array)$rfcAddressArray as $addressData) {
6253
+			foreach ((array)$rfcAddressArray as $addressData) {
6254 6254
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6255
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
6255
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
6256 6256
 					continue;
6257 6257
 				}
6258
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6258
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6259 6259
 					continue;
6260 6260
 				}
6261 6261
 				if ($addressData['RFC822_EMAIL'])
@@ -6264,7 +6264,7 @@  discard block
 block discarded – undo
6264 6264
 				}
6265 6265
 				else
6266 6266
 				{
6267
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
6267
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
6268 6268
 					$addressObjectA = self::parseAddressList($emailaddress);
6269 6269
 				}
6270 6270
 				$addressObject = $addressObjectA[0];
@@ -6273,10 +6273,10 @@  discard block
 block discarded – undo
6273 6273
 				//$mb =(string)$addressObject->mailbox;
6274 6274
 				//$h = (string)$addressObject->host;
6275 6275
 				//$p = (string)$addressObject->personal;
6276
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
6276
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
6277 6277
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
6278 6278
 				$buff = imap_rfc822_write_address($addressObject->mailbox, Horde_Idna::decode($addressObject->host), $addressObject->personal);
6279
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
6279
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
6280 6280
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6281 6281
 				$returnAddr .= $buff;
6282 6282
 			}
@@ -6284,8 +6284,8 @@  discard block
 block discarded – undo
6284 6284
 		else
6285 6285
 		{
6286 6286
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6287
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6288
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6287
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6288
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6289 6289
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6290 6290
 		}
6291 6291
 		return $returnAddr;
@@ -6299,12 +6299,12 @@  discard block
 block discarded – undo
6299 6299
 	 * @param string &$err error-message on error
6300 6300
 	 * @return string/boolean merged content or false on error
6301 6301
 	 */
6302
-	static function merge($content,$ids,$mimetype='')
6302
+	static function merge($content, $ids, $mimetype = '')
6303 6303
 	{
6304 6304
 		$mergeobj = new Contacts\Merge();
6305 6305
 
6306
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6307
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6306
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6307
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6308 6308
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6309 6309
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6310 6310
 		return $rv;
@@ -6346,12 +6346,12 @@  discard block
 block discarded – undo
6346 6346
 		else
6347 6347
 			settype($bytes, 'integer');
6348 6348
 
6349
-		return $bytes . ' ' . $type ;
6349
+		return $bytes.' '.$type;
6350 6350
 	}
6351 6351
 
6352 6352
 	static function detect_qp(&$sting) {
6353 6353
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6354
-		return preg_match("$needle",$string);
6354
+		return preg_match("$needle", $string);
6355 6355
 	}
6356 6356
 
6357 6357
 	/**
@@ -6364,11 +6364,11 @@  discard block
 block discarded – undo
6364 6364
 	 * @param string $_methodNline - Information where the log was taken
6365 6365
 	 * @return void
6366 6366
 	 */
6367
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6367
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6368 6368
 	{
6369 6369
 		if (is_null($_endtime)) $_endtime = microtime(true);
6370 6370
 		$usagetime = microtime(true) - $_starttime;
6371
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6371
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6372 6372
 	}
6373 6373
 
6374 6374
 	/**
@@ -6381,9 +6381,9 @@  discard block
 block discarded – undo
6381 6381
 	 *
6382 6382
 	 * @throws Exception\WrongUserinput
6383 6383
 	 */
6384
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6384
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6385 6385
 	{
6386
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6386
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6387 6387
 
6388 6388
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6389 6389
 		$importfailed = $tmpFileName = false;
@@ -6393,7 +6393,7 @@  discard block
 block discarded – undo
6393 6393
 			$importfailed = true;
6394 6394
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6395 6395
 		}
6396
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6396
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6397 6397
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6398 6398
 		{
6399 6399
 			// ensure existance of eGW temp dir
@@ -6401,7 +6401,7 @@  discard block
 block discarded – undo
6401 6401
 			// and different from any other temp file location set in php.ini
6402 6402
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6403 6403
 			{
6404
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6404
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6405 6405
 			}
6406 6406
 
6407 6407
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6428,14 +6428,14 @@  discard block
 block discarded – undo
6428 6428
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6429 6429
 			// so we check for the suffix too
6430 6430
 			// trust vfs mime-types, trust the mimetype if it contains a method
6431
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6431
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6432 6432
 			{
6433
-				$buff = explode('.',$_formData['name']);
6433
+				$buff = explode('.', $_formData['name']);
6434 6434
 				$suffix = '';
6435 6435
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6436 6436
 				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
6437 6437
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6438
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6438
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6439 6439
 				{
6440 6440
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6441 6441
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6450,13 +6450,13 @@  discard block
 block discarded – undo
6450 6450
 			if ($reqMimeType)
6451 6451
 			{
6452 6452
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6453
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6453
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6454 6454
 				{
6455 6455
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6456 6456
 					{
6457 6457
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6458 6458
 						$importfailed = true;
6459
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6459
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6460 6460
 					}
6461 6461
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6462 6462
 					{
@@ -6465,17 +6465,17 @@  discard block
 block discarded – undo
6465 6465
 				}
6466 6466
 			}
6467 6467
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6468
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6468
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6469 6469
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6470 6470
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6471 6471
 
6472
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6472
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6473 6473
 			{
6474
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6474
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6475 6475
 			}
6476 6476
 			elseif (is_uploaded_file($_formData['file']))
6477 6477
 			{
6478
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);	// requirement for safe_mode!
6478
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); // requirement for safe_mode!
6479 6479
 			}
6480 6480
 			else
6481 6481
 			{
@@ -6484,7 +6484,7 @@  discard block
 block discarded – undo
6484 6484
 		} else {
6485 6485
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6486 6486
 			$importfailed = true;
6487
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6487
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6488 6488
 		}
6489 6489
 		if ($importfailed == true)
6490 6490
 		{
@@ -6492,7 +6492,7 @@  discard block
 block discarded – undo
6492 6492
 		}
6493 6493
 		else
6494 6494
 		{
6495
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6495
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6496 6496
 			{
6497 6497
 				Vfs::load_wrapper('vfs');
6498 6498
 			}
@@ -6517,7 +6517,7 @@  discard block
 block discarded – undo
6517 6517
 		$images = null;
6518 6518
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6519 6519
 		{
6520
-			foreach($images[2] as $i => $url)
6520
+			foreach ($images[2] as $i => $url)
6521 6521
 			{
6522 6522
 				//$isData = false;
6523 6523
 				$basedir = $data = '';
@@ -6529,20 +6529,20 @@  discard block
 block discarded – undo
6529 6529
 					$filename = basename($url);
6530 6530
 					if (($directory = dirname($url)) == '.') $directory = '';
6531 6531
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6532
-					$mimeType  = MimeMagic::ext2mime($ext);
6533
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6532
+					$mimeType = MimeMagic::ext2mime($ext);
6533
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6534 6534
 					$myUrl = $directory.$filename;
6535
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6535
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6536 6536
 					{
6537
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6537
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6538 6538
 					}
6539 6539
 					// use vfs instead of url containing webdav.php
6540 6540
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6541 6541
 					// webdav.php urls as vfs
6542
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6542
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6543 6543
 					{
6544 6544
 						Vfs::load_wrapper('vfs');
6545
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6545
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6546 6546
 						$basedir = 'vfs://default';
6547 6547
 						$needTempFile = false;
6548 6548
 					}
@@ -6555,11 +6555,11 @@  discard block
 block discarded – undo
6555 6555
 						// Strips the url and store it into a temp for further procss
6556 6556
 						$tmp_url = html_entity_decode($myUrl);
6557 6557
 
6558
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6558
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6559 6559
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6560 6560
 						{
6561 6561
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6562
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6562
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6563 6563
 							$mail_bo->closeConnection();
6564 6564
 							if ($attachment)
6565 6565
 							{
@@ -6570,32 +6570,32 @@  discard block
 block discarded – undo
6570 6570
 						}
6571 6571
 					}
6572 6572
 
6573
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6574
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6573
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6574
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6575 6575
 				}
6576
-				if (substr($url,0,strlen('data:'))=='data:')
6576
+				if (substr($url, 0, strlen('data:')) == 'data:')
6577 6577
 				{
6578 6578
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6579 6579
 					// we only support base64 encoded data
6580
-					$tmp = substr($url,strlen('data:'));
6581
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6580
+					$tmp = substr($url, strlen('data:'));
6581
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6582 6582
 					$data = base64_decode($data_base64);
6583 6583
 					// FF currently does NOT add any mime-type
6584 6584
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6585 6585
 					{
6586 6586
 						$mimeType = MimeMagic::analyze_data($data);
6587 6587
 					}
6588
-					list($what,$exactly) = explode('/',$mimeType);
6588
+					list($what, $exactly) = explode('/', $mimeType);
6589 6589
 					$needTempFile = true;
6590
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6590
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6591 6591
 				}
6592 6592
 				if ($data || $needTempFile === false)
6593 6593
 				{
6594 6594
 					if ($needTempFile)
6595 6595
 					{
6596
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6597
-						$tmpfile = fopen($attachment_file,'w');
6598
-						fwrite($tmpfile,$data);
6596
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6597
+						$tmpfile = fopen($attachment_file, 'w');
6598
+						fwrite($tmpfile, $data);
6599 6599
 						fclose($tmpfile);
6600 6600
 					}
6601 6601
 					else
@@ -6606,7 +6606,7 @@  discard block
 block discarded – undo
6606 6606
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6607 6607
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6608 6608
 					// on upload. filename itself is not sufficient to determine the sameness of images
6609
-					$cid = 'cid:' . md5($attachment_file);
6609
+					$cid = 'cid:'.md5($attachment_file);
6610 6610
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), urldecode($filename), $mimeType) !== null)
6611 6611
 					{
6612 6612
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6628,10 +6628,10 @@  discard block
 block discarded – undo
6628 6628
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6629 6629
 	 * @return mixed array of messages with success and failed messages or exception
6630 6630
 	 */
6631
-	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6631
+	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6632 6632
 	{
6633 6633
 		$importfailed = false;
6634
-		$processStats = array('success'=>array(),'failed'=>array());
6634
+		$processStats = array('success'=>array(), 'failed'=>array());
6635 6635
 		if (empty($SendAndMergeTocontacts))
6636 6636
 		{
6637 6637
 			$importfailed = true;
@@ -6672,7 +6672,7 @@  discard block
 block discarded – undo
6672 6672
 				$_folder = $this->getSentFolder();
6673 6673
 			}
6674 6674
 			$delimiter = $this->getHierarchyDelimiter();
6675
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6675
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6676 6676
 			if ($importfailed === false)
6677 6677
 			{
6678 6678
 				$Subject = $mailObject->getHeader('Subject');
@@ -6690,9 +6690,9 @@  discard block
 block discarded – undo
6690 6690
 				{
6691 6691
 					$mailObject->clearReplyTos();
6692 6692
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6693
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6693
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6694 6694
 
6695
-					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']),Mail::generateIdentityString($activeMailProfile,false));
6695
+					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']), Mail::generateIdentityString($activeMailProfile, false));
6696 6696
 				}
6697 6697
 				foreach ($SendAndMergeTocontacts as $k => $val)
6698 6698
 				{
@@ -6706,12 +6706,12 @@  discard block
 block discarded – undo
6706 6706
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6707 6707
 
6708 6708
 						// Parse destinations for placeholders
6709
-						foreach(Mailer::$type2header as $type => $h)
6709
+						foreach (Mailer::$type2header as $type => $h)
6710 6710
 						{
6711 6711
 							//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));
6712
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6713
-							$mailObject->addAddress($merged,'',$type);
6714
-							if($type == 'to')
6712
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6713
+							$mailObject->addAddress($merged, '', $type);
6714
+							if ($type == 'to')
6715 6715
 							{
6716 6716
 								$email = $merged;
6717 6717
 							}
@@ -6724,26 +6724,26 @@  discard block
 block discarded – undo
6724 6724
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6725 6725
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6726 6726
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6727
-							if($email)
6727
+							if ($email)
6728 6728
 							{
6729 6729
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6730 6730
 							}
6731 6731
 						}
6732 6732
 
6733 6733
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6734
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6734
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6735 6735
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6736 6736
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6737
-							self::generateIdentityString($activeMailProfile,false));
6737
+							self::generateIdentityString($activeMailProfile, false));
6738 6738
 
6739 6739
 						$mailObject->removeHeader('Message-ID');
6740 6740
 						$mailObject->removeHeader('Date');
6741 6741
 						$mailObject->clearCustomHeaders();
6742 6742
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6743 6743
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6744
-						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));
6744
+						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));
6745 6745
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6746
-						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));
6746
+						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));
6747 6747
 
6748 6748
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6749 6749
 						// set a higher timeout for big messages
@@ -6752,7 +6752,7 @@  discard block
 block discarded – undo
6752 6752
 						try {
6753 6753
 							$mailObject->send();
6754 6754
 						}
6755
-						catch(Exception $e) {
6755
+						catch (Exception $e) {
6756 6756
 							$sendOK = false;
6757 6757
 							$errorInfo = $e->getMessage();
6758 6758
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6766,41 +6766,41 @@  discard block
 block discarded – undo
6766 6766
 						$mailObject->clearCustomHeaders();
6767 6767
 
6768 6768
 						// Parse destinations for placeholders
6769
-						foreach(Mailer::$type2header as $type => $h)
6769
+						foreach (Mailer::$type2header as $type => $h)
6770 6770
 						{
6771
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6771
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6772 6772
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6773
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6773
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6774 6774
 						}
6775 6775
 
6776 6776
 						// No addresses from placeholders?  Treat it as just a contact ID
6777
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6777
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6778 6778
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6779 6779
 						{
6780 6780
 							$contact = $bo_merge->contacts->read($val);
6781 6781
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6782 6782
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6783 6783
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6784
-							if($email)
6784
+							if ($email)
6785 6785
 							{
6786 6786
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6787 6787
 							}
6788 6788
 						}
6789 6789
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6790 6790
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6791
-						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));
6791
+						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));
6792 6792
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6793
-						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));
6793
+						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));
6794 6794
 						$_folder = $this->getDraftFolder();
6795 6795
 					}
6796 6796
 					if ($sendOK || $openAsDraft)
6797 6797
 					{
6798
-						if ($this->folderExists($_folder,true))
6798
+						if ($this->folderExists($_folder, true))
6799 6799
 						{
6800
-						    if($this->isSentFolder($_folder))
6800
+						    if ($this->isSentFolder($_folder))
6801 6801
 							{
6802 6802
 						        $flags = '\\Seen';
6803
-						    } elseif($this->isDraftFolder($_folder)) {
6803
+						    } elseif ($this->isDraftFolder($_folder)) {
6804 6804
 						        $flags = '\\Draft';
6805 6805
 						    } else {
6806 6806
 						        $flags = '';
@@ -6808,7 +6808,7 @@  discard block
 block discarded – undo
6808 6808
 							$savefailed = false;
6809 6809
 							try
6810 6810
 							{
6811
-								$messageUid =$this->appendMessage($_folder,
6811
+								$messageUid = $this->appendMessage($_folder,
6812 6812
 									$mailObject->getRaw(),
6813 6813
 									null,
6814 6814
 									$flags);
@@ -6816,10 +6816,10 @@  discard block
 block discarded – undo
6816 6816
 							catch (\Exception\WrongUserinput $e)
6817 6817
 							{
6818 6818
 								$savefailed = true;
6819
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6819
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6820 6820
 							}
6821 6821
 							// no send, save successful, and message_uid present
6822
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6822
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6823 6823
 							{
6824 6824
 								$importID = $messageUid;
6825 6825
 								$openComposeWindow = true;
@@ -6828,20 +6828,20 @@  discard block
 block discarded – undo
6828 6828
 						else
6829 6829
 						{
6830 6830
 							$savefailed = true;
6831
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6831
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6832 6832
 						}
6833 6833
 						if ($sendOK)
6834 6834
 						{
6835
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6835
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6836 6836
 						}
6837 6837
 						else
6838 6838
 						{
6839
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6839
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6840 6840
 						}
6841 6841
 					}
6842
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6842
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6843 6843
 					{
6844
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6844
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6845 6845
 					}
6846 6846
 				}
6847 6847
 			}
@@ -6911,19 +6911,18 @@  discard block
 block discarded – undo
6911 6911
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
6912 6912
 
6913 6913
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
6914
-			$start = is_string($message) ? substr($message, 0, 8192) :
6915
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6914
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6916 6915
 
6917 6916
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6918
-			if ($length===false) $length = strlen($start);
6919
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6917
+			if ($length === false) $length = strlen($start);
6918
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
6920 6919
 
6921
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
6920
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
6922 6921
 			{
6923
-				foreach((array)$value as $n => $val)
6922
+				foreach ((array)$value as $n => $val)
6924 6923
 				{
6925 6924
 					$overwrite = !$n;
6926
-					switch($header)
6925
+					switch ($header)
6927 6926
 					{
6928 6927
 						case 'Content-Transfer-Encoding':
6929 6928
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -6944,7 +6943,7 @@  discard block
 block discarded – undo
6944 6943
 		}
6945 6944
 		else
6946 6945
 		{
6947
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
6946
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
6948 6947
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6949 6948
 		}
6950 6949
 	}
@@ -6958,50 +6957,50 @@  discard block
 block discarded – undo
6958 6957
 	 * @param string $default_domain
6959 6958
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
6960 6959
 	 */
6961
-	public static function parseAddressList($addresses, $default_domain=null)
6960
+	public static function parseAddressList($addresses, $default_domain = null)
6962 6961
 	{
6963 6962
 		$rfc822 = new Horde_Mail_Rfc822();
6964 6963
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6965 6964
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
6966
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
6965
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
6967 6966
 		{
6968 6967
 			$matches = array();
6969
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6968
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
6970 6969
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6971
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
6972
-			$addresses = implode(',',$matches[0]);
6970
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
6971
+			$addresses = implode(',', $matches[0]);
6973 6972
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6974 6973
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6975 6974
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
6976 6975
 		}
6977
-		$previousFailed=false;
6976
+		$previousFailed = false;
6978 6977
 		$ret2 = new Horde_Mail_Rfc822_List();
6979 6978
 		// handle known problems on emailaddresses
6980
-		foreach($ret as $i => $adr)
6979
+		foreach ($ret as $i => $adr)
6981 6980
 		{
6982 6981
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
6983
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
6984
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
6982
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
6983
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
6985 6984
 			{
6986
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
6987
-				$adr->host = str_replace("'","",$adr->host);
6985
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
6986
+				$adr->host = str_replace("'", "", $adr->host);
6988 6987
 			}
6989 6988
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
6990 6989
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
6991 6990
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
6992 6991
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
6993 6992
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
6994
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
6993
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
6995 6994
 			{
6996
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
6997
-				$previousFailed=true;
6995
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
6996
+				$previousFailed = true;
6998 6997
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6999 6998
 			}
7000 6999
 			else
7001 7000
 			{
7002
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
7001
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
7003 7002
 				$remember = '';
7004
-				$previousFailed=false;
7003
+				$previousFailed = false;
7005 7004
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
7006 7005
 				$ret2->add($adr);
7007 7006
 			}
@@ -7017,7 +7016,7 @@  discard block
 block discarded – undo
7017 7016
 	 * @param string $_folder
7018 7017
 	 * @return boolean
7019 7018
 	 */
7020
-	function sendMDN($uid,$_folder)
7019
+	function sendMDN($uid, $_folder)
7021 7020
 	{
7022 7021
 		$acc = Mail\Account::read($this->profileID);
7023 7022
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
@@ -7047,7 +7046,7 @@  discard block
 block discarded – undo
7047 7046
 	 */
7048 7047
 	function addAccount($_hookValues)
7049 7048
 	{
7050
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7049
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7051 7050
 
7052 7051
 	}
7053 7052
 
@@ -7061,7 +7060,7 @@  discard block
 block discarded – undo
7061 7060
 	 */
7062 7061
 	function deleteAccount($_hookValues)
7063 7062
 	{
7064
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7063
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7065 7064
 
7066 7065
 	}
7067 7066
 
@@ -7075,7 +7074,7 @@  discard block
 block discarded – undo
7075 7074
 	 */
7076 7075
 	function updateAccount($_hookValues)
7077 7076
 	{
7078
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7077
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7079 7078
 
7080 7079
 	}
7081 7080
 }
Please login to merge, or discard this patch.
Braces   +1771 added lines, -523 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
 		self::$profileDefunct = Cache::getCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),5*1);
@@ -230,9 +233,15 @@  discard block
 block discarded – undo
230 233
 			{
231 234
 				$profileID = Mail\Account::get_default_acc_id();
232 235
 			}
233
-			if ($profileID!=$_profileID) $_restoreSession==false;
236
+			if ($profileID!=$_profileID)
237
+			{
238
+				$_restoreSession==false;
239
+			}
234 240
 			$_profileID=$profileID;
235
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
241
+			if (self::$debug)
242
+			{
243
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
244
+			}
236 245
 		}
237 246
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
238 247
 		if ($_oldImapServerObject===true)
@@ -271,7 +280,8 @@  discard block
 block discarded – undo
271 280
 				// TODO: merge mailprefs into userprefs, for easy treatment
272 281
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
273 282
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
274
-			} catch (\Exception $e)
283
+			}
284
+			catch (\Exception $e)
275 285
 			{
276 286
 				$newprofileID = Mail\Account::get_default_acc_id();
277 287
 				// try loading the default profile for the user
@@ -289,9 +299,15 @@  discard block
 block discarded – undo
289 299
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
290 300
 		}
291 301
 		self::$instances[$_profileID]->profileID = $_profileID;
292
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
302
+		if (!isset(self::$instances[$_profileID]->idna2))
303
+		{
304
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
305
+		}
293 306
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
294
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
307
+		if (is_null(self::$mailConfig))
308
+		{
309
+			self::$mailConfig = Config::read('mail');
310
+		}
295 311
 		return self::$instances[$_profileID];
296 312
 	}
297 313
 
@@ -316,14 +332,20 @@  discard block
 block discarded – undo
316 332
 			}
317 333
 			catch (\Exception $e)
318 334
 			{
319
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
335
+				if ($_profileID != Mail\Account::get_default_acc_id())
336
+				{
337
+					$_profileID = Mail\Account::get_default_acc_id();
338
+				}
320 339
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
321 340
 				return false;
322 341
 			}
323 342
 		}
324 343
 		if ($oldProfileID != $_profileID)
325 344
 		{
326
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
345
+			if ($oldProfileID && $_profileID==0)
346
+			{
347
+				$_profileID = $oldProfileID;
348
+			}
327 349
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
328 350
 			// save prefs
329 351
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -353,11 +375,17 @@  discard block
 block discarded – undo
353 375
 				{
354 376
 					return $_acc_id;
355 377
 				}
356
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
378
+				if (self::$debug)
379
+				{
380
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
381
+				}
357 382
 			}
358 383
 			catch (\Exception $e) {
359 384
 				unset($e);
360
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
385
+				if (self::$debug)
386
+				{
387
+					error_log(__METHOD__."($_acc_id) account NOT found!");
388
+				}
361 389
 			}
362 390
 		}
363 391
 		// no account specified or specified account not found or not valid
@@ -366,11 +394,17 @@  discard block
 block discarded – undo
366 394
 		{
367 395
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
368 396
 			{
369
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
397
+				if (self::$debug && $_acc_id)
398
+				{
399
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
400
+				}
370 401
 				return $acc_id;
371 402
 			}
372 403
 		}
373
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
404
+		if (self::$debug)
405
+		{
406
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
407
+		}
374 408
 		return 0;
375 409
 	}
376 410
 
@@ -386,10 +420,19 @@  discard block
 block discarded – undo
386 420
 	 */
387 421
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
388 422
 	{
389
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
390
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
423
+		if (is_null($_reuseCache))
424
+		{
425
+			$_reuseCache = $_restoreSession;
426
+		}
427
+		if (!empty($_displayCharset))
428
+		{
429
+			self::$displayCharset = $_displayCharset;
430
+		}
391 431
 		// not nummeric, we assume we only want an empty class object
392
-		if (!is_numeric($_profileID)) return true;
432
+		if (!is_numeric($_profileID))
433
+		{
434
+			return true;
435
+		}
393 436
 		if ($_restoreSession)
394 437
 		{
395 438
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -404,7 +447,10 @@  discard block
 block discarded – undo
404 447
 			$firstMessage = $this->sessionData['previewMessage'];
405 448
 			$this->sessionData = array();
406 449
 		}
407
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
450
+		if (!$_reuseCache)
451
+		{
452
+			$this->forcePrefReload($_profileID,!$_reuseCache);
453
+		}
408 454
 		try
409 455
 		{
410 456
 			$this->profileID = self::validateProfileID($_profileID);
@@ -428,7 +474,10 @@  discard block
 block discarded – undo
428 474
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
429 475
 		}
430 476
 
431
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
477
+		if (is_null(self::$mailConfig))
478
+		{
479
+			self::$mailConfig = Config::read('mail');
480
+		}
432 481
 	}
433 482
 
434 483
 	/**
@@ -457,7 +506,10 @@  discard block
 block discarded – undo
457 506
 		// unset the mail_preferences session object, to force the reload/rebuild
458 507
 		Cache::setSession('mail','mail_preferences',serialize(array()));
459 508
 		Cache::setSession('emailadmin','session_data',serialize(array()));
460
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
509
+		if ($_resetFolderObjects)
510
+		{
511
+			self::resetFolderObjectCache($_profile_id);
512
+		}
461 513
 	}
462 514
 
463 515
 	/**
@@ -467,7 +519,10 @@  discard block
 block discarded – undo
467 519
 	{
468 520
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
469 521
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
470
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
522
+		if (!empty(self::$activeFolderCache[$this->profileID]))
523
+		{
524
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
525
+		}
471 526
 	}
472 527
 
473 528
 	/**
@@ -476,7 +531,10 @@  discard block
 block discarded – undo
476 531
 	function saveSessionData()
477 532
 	{
478 533
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
479
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
534
+		if (!empty($this->sessionData['mailbox']))
535
+		{
536
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
537
+		}
480 538
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
481 539
 		{
482 540
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -497,8 +555,14 @@  discard block
 block discarded – undo
497 555
 	 */
498 556
 	static function unsetCachedObjects($_profileID=null)
499 557
 	{
500
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
501
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
558
+		if (is_null($_profileID))
559
+		{
560
+			$_profileID = Mail\Account::get_default_acc_id();
561
+		}
562
+		if (is_array($_profileID) && $_profileID['account_id'])
563
+		{
564
+			$account_id = $_profileID['account_id'];
565
+		}
502 566
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
503 567
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
504 568
 		{
@@ -531,7 +595,10 @@  discard block
 block discarded – undo
531 595
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
532 596
 			}
533 597
 
534
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
598
+			if (isset(self::$instances[$_profileID]))
599
+			{
600
+				unset(self::$instances[$_profileID]);
601
+			}
535 602
 		}
536 603
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
537 604
 		{
@@ -560,7 +627,10 @@  discard block
 block discarded – undo
560 627
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
561 628
 	{
562 629
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
563
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
630
+		if (is_null($account_id))
631
+		{
632
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
633
+		}
564 634
 		if (is_array($_ImapServerId))
565 635
 		{
566 636
 			// called via hook
@@ -599,7 +669,10 @@  discard block
 block discarded – undo
599 669
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
600 670
 	{
601 671
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
602
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
672
+		if (is_null($account_id))
673
+		{
674
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
675
+		}
603 676
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
604 677
 		// or treat it as not given. we try that path
605 678
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -673,10 +746,14 @@  discard block
 block discarded – undo
673 746
 
674 747
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
675 748
 
676
-		foreach($identities as $ik => $ident) {
749
+		foreach($identities as $ik => $ident)
750
+		{
677 751
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
678 752
 			$identity = Mail\Account::read_identity($ik);
679
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
753
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
754
+			{
755
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
756
+			}
680 757
 		}
681 758
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
682 759
 		return $userEMailAdresses;
@@ -694,13 +771,20 @@  discard block
 block discarded – undo
694 771
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
695 772
 		{
696 773
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
697
-			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']);
774
+			if (!$resolve_placeholders)
775
+			{
776
+				$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']);
777
+			}
698 778
 
699
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
779
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
780
+			{
700 781
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
701 782
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
702 783
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
703
-				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']);
784
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
785
+				{
786
+					$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']);
787
+				}
704 788
 			}
705 789
 		}
706 790
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -720,12 +804,16 @@  discard block
 block discarded – undo
720 804
 			$account = Mail\Account::read($account);
721 805
 		}
722 806
 		$userEMailAdresses = array();
723
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
807
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
808
+		{
724 809
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
725 810
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
726 811
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
727 812
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
728
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
813
+			if (empty($identity['ident_id']))
814
+			{
815
+				$identity['ident_id'] = $identity['acc_id'];
816
+			}
729 817
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
730 818
 			{
731 819
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -768,15 +856,25 @@  discard block
 block discarded – undo
768 856
 		// account select box
769 857
 		$selectedID = $this->profileID;
770 858
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
771
-		if ($allAccountData) {
859
+		if ($allAccountData)
860
+		{
772 861
 			$rememberFirst=$selectedFound=null;
773 862
 			foreach ($allAccountData as $tmpkey => $icServers)
774 863
 			{
775
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
776
-				if ($tmpkey == $selectedID) $selectedFound=true;
864
+				if (is_null($rememberFirst))
865
+				{
866
+					$rememberFirst = $tmpkey;
867
+				}
868
+				if ($tmpkey == $selectedID)
869
+				{
870
+					$selectedFound=true;
871
+				}
777 872
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
778 873
 				$host = $icServers->acc_imap_host;
779
-				if (empty($host)) continue;
874
+				if (empty($host))
875
+				{
876
+					continue;
877
+				}
780 878
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
781 879
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
782 880
 			}
@@ -836,7 +934,10 @@  discard block
 block discarded – undo
836 934
 	 */
837 935
 	function reopen($_foldername)
838 936
 	{
839
-		if (self::$debugTimes) $starttime = microtime (true);
937
+		if (self::$debugTimes)
938
+		{
939
+			$starttime = microtime (true);
940
+		}
840 941
 
841 942
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
842 943
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -846,12 +947,16 @@  discard block
 block discarded – undo
846 947
 		//{
847 948
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
848 949
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
849
-			if ($this->folderIsSelectable($_foldername)) {
950
+			if ($this->folderIsSelectable($_foldername))
951
+			{
850 952
 				$this->icServer->openMailbox($_foldername);
851 953
 			}
852 954
 			$folderOpened = $_foldername;
853 955
 		//}
854
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
956
+		if (self::$debugTimes)
957
+		{
958
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
959
+		}
855 960
 	}
856 961
 
857 962
 
@@ -866,13 +971,22 @@  discard block
 block discarded – undo
866 971
 	{
867 972
 		//error_log( "-------------------------->open connection ".function_backtrace());
868 973
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
869
-		if (self::$debugTimes) $starttime = microtime (true);
974
+		if (self::$debugTimes)
975
+		{
976
+			$starttime = microtime (true);
977
+		}
870 978
 		$mailbox=null;
871 979
 		try
872 980
 		{
873
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
874
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
875
-/*
981
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
982
+			{
983
+				$mailbox = $this->sessionData['mailbox'];
984
+			}
985
+			if (empty($mailbox))
986
+			{
987
+				$mailbox = $this->icServer->getCurrentMailbox();
988
+			}
989
+			/*
876 990
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
877 991
 			{
878 992
 				$this->icServer->openMailbox($mailbox);
@@ -897,7 +1011,10 @@  discard block
 block discarded – undo
897 1011
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
898 1012
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
899 1013
 		}
900
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1014
+		if (self::$debugTimes)
1015
+		{
1016
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1017
+		}
901 1018
 	}
902 1019
 
903 1020
 	/**
@@ -909,7 +1026,10 @@  discard block
 block discarded – undo
909 1026
 	function getQuotaRoot()
910 1027
 	{
911 1028
 		static $quota;
912
-		if (isset($quota)) return $quota;
1029
+		if (isset($quota))
1030
+		{
1031
+			return $quota;
1032
+		}
913 1033
 		if (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID]))
914 1034
 		{
915 1035
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -918,7 +1038,8 @@  discard block
 block discarded – undo
918 1038
 		try
919 1039
 		{
920 1040
 			$this->icServer->getCurrentMailbox();
921
-			if(!$this->icServer->hasCapability('QUOTA')) {
1041
+			if(!$this->icServer->hasCapability('QUOTA'))
1042
+			{
922 1043
 				$quota = false;
923 1044
 				return false;
924 1045
 			}
@@ -936,12 +1057,15 @@  discard block
 block discarded – undo
936 1057
 			}
937 1058
 		}
938 1059
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
939
-		if(is_array($quota)) {
1060
+		if(is_array($quota))
1061
+		{
940 1062
 			$quota = array(
941 1063
 				'usage'	=> $quota['USED'],
942 1064
 				'limit'	=> $quota['QMAX'],
943 1065
 			);
944
-		} else {
1066
+		}
1067
+		else
1068
+		{
945 1069
 			$quota = false;
946 1070
 		}
947 1071
 		return $quota;
@@ -957,7 +1081,11 @@  discard block
 block discarded – undo
957 1081
 	static function getTimeOut($_use='IMAP')
958 1082
 	{
959 1083
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
960
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1084
+		if (empty($timeout))
1085
+		{
1086
+			$timeout = ($_use=='SIEVE'?10:20);
1087
+		}
1088
+		// this is the default value
961 1089
 		return $timeout;
962 1090
 	}
963 1091
 
@@ -975,9 +1103,13 @@  discard block
 block discarded – undo
975 1103
 		$foldersNameSpace = array();
976 1104
 		$delimiter = $this->getHierarchyDelimiter();
977 1105
 		// TODO: cache by $this->icServer->ImapServerId
978
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1106
+		if (is_null($nameSpace))
1107
+		{
1108
+			$nameSpace = $this->icServer->getNameSpaceArray();
1109
+		}
979 1110
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
980
-		if (is_array($nameSpace)) {
1111
+		if (is_array($nameSpace))
1112
+		{
981 1113
 			foreach($nameSpace as $type => $singleNameSpaceArray)
982 1114
 			{
983 1115
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -994,7 +1126,9 @@  discard block
 block discarded – undo
994 1126
 						$_foldersNameSpace['prefix_present'] = 'forced';
995 1127
 						// uw-imap server with mailbox prefix or dovecot maybe
996 1128
 						$_foldersNameSpace['prefix'] = 'mail';
997
-					} else {
1129
+					}
1130
+					else
1131
+					{
998 1132
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
999 1133
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
1000 1134
 					}
@@ -1021,7 +1155,10 @@  discard block
 block discarded – undo
1021 1155
 		foreach($nameSpace as &$singleNameSpace)
1022 1156
 		{
1023 1157
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1024
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1158
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1159
+			{
1160
+				return $singleNameSpace['prefix'];
1161
+			}
1025 1162
 		}
1026 1163
 		return "";
1027 1164
 	}
@@ -1035,8 +1172,14 @@  discard block
 block discarded – undo
1035 1172
 	function getHierarchyDelimiter($_useCache=true)
1036 1173
 	{
1037 1174
 		static $HierarchyDelimiter = null;
1038
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1039
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1175
+		if (is_null($HierarchyDelimiter))
1176
+		{
1177
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1178
+		}
1179
+		if ($_useCache===false)
1180
+		{
1181
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1182
+		}
1040 1183
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1041 1184
 		{
1042 1185
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1070,14 +1213,19 @@  discard block
 block discarded – undo
1070 1213
 	{
1071 1214
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1072 1215
 		static $_specialUseFolders = null;
1073
-		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);
1216
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1217
+		{
1218
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1219
+		}
1074 1220
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1075 1221
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1076 1222
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1077 1223
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1078 1224
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1079 1225
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1080
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1226
+		{
1227
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1228
+		}
1081 1229
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1082 1230
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1083 1231
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1105,7 +1253,8 @@  discard block
 block discarded – undo
1105 1253
 	function folderIsSelectable($folderToSelect)
1106 1254
 	{
1107 1255
 		$retval = true;
1108
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1256
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1257
+		{
1109 1258
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1110 1259
 			{
1111 1260
 				$retval = false;
@@ -1158,7 +1307,10 @@  discard block
 block discarded – undo
1158 1307
 	 */
1159 1308
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1160 1309
 	{
1161
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1310
+		if (self::$debug)
1311
+		{
1312
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1313
+		}
1162 1314
 		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1163 1315
 		{
1164 1316
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -1170,7 +1322,10 @@  discard block
 block discarded – undo
1170 1322
 		{
1171 1323
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1172 1324
 		}
1173
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1325
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1326
+		{
1327
+			return $folderInfoCache[$_folderName];
1328
+		}
1174 1329
 		$retValue = array();
1175 1330
 		$retValue['subscribed'] = false;
1176 1331
 /*
@@ -1199,7 +1354,10 @@  discard block
 block discarded – undo
1199 1354
 			if (is_array($ret))
1200 1355
 			{
1201 1356
 				$retkeys = array_keys($ret);
1202
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1357
+				if ($retkeys[0]==$_folderName)
1358
+				{
1359
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1360
+				}
1203 1361
 			}
1204 1362
 			else
1205 1363
 			{
@@ -1208,7 +1366,8 @@  discard block
 block discarded – undo
1208 1366
 		}
1209 1367
 		$folderInfo = $folderInfoCache[$_folderName];
1210 1368
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1211
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1369
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1370
+		{
1212 1371
 			try
1213 1372
 			{
1214 1373
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1243,7 +1402,8 @@  discard block
 block discarded – undo
1243 1402
 		$retValue['shortName']		= array_pop($shortNameParts);
1244 1403
 		$retValue['displayName']	= $_folderName;
1245 1404
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1246
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1405
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1406
+		{
1247 1407
 			$retValue['displayName']	= lang('INBOX');
1248 1408
 			$retValue['shortDisplayName']	= lang('INBOX');
1249 1409
 		}
@@ -1252,7 +1412,10 @@  discard block
 block discarded – undo
1252 1412
 		{
1253 1413
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1254 1414
 		}
1255
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1415
+		if ($folderInfo)
1416
+		{
1417
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1418
+		}
1256 1419
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1257 1420
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1258 1421
 		{
@@ -1264,24 +1427,34 @@  discard block
 block discarded – undo
1264 1427
 		static $subscribedFolders = null;
1265 1428
 		static $nameSpace = null;
1266 1429
 		static $prefix = null;
1267
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1430
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1431
+		{
1432
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1433
+		}
1268 1434
 		if (!empty($nameSpace[$this->profileID]))
1269 1435
 		{
1270 1436
 			$nsNoPersonal=array();
1271 1437
 			foreach($nameSpace[$this->profileID] as &$ns)
1272 1438
 			{
1273
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1439
+				if ($ns['type']!='personal')
1440
+				{
1441
+					$nsNoPersonal[]=$ns;
1442
+				}
1274 1443
 			}
1275 1444
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1276 1445
 		}
1277
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1446
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1447
+		{
1448
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1449
+		}
1278 1450
 
1279 1451
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1280 1452
 		{
1281 1453
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1282 1454
 		}
1283 1455
 
1284
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1456
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1457
+		{
1285 1458
 			$retValue['subscribed'] = true;
1286 1459
 		}
1287 1460
 
@@ -1300,8 +1473,7 @@  discard block
 block discarded – undo
1300 1473
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1301 1474
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1302 1475
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1303
-			)
1304
-			{
1476
+			) {
1305 1477
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1306 1478
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1307 1479
 				try
@@ -1312,13 +1484,19 @@  discard block
 block discarded – undo
1312 1484
 				}
1313 1485
 				catch (\Exception $ee)
1314 1486
 				{
1315
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1487
+					if (self::$debug)
1488
+					{
1489
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1490
+					}
1316 1491
 				}
1317 1492
 			}
1318 1493
 		}
1319 1494
 		catch (\Exception $e)
1320 1495
 		{
1321
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1496
+			if (self::$debug)
1497
+			{
1498
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1499
+			}
1322 1500
 		}
1323 1501
 
1324 1502
 		return $retValue;
@@ -1343,8 +1521,14 @@  discard block
 block discarded – undo
1343 1521
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1344 1522
 	{
1345 1523
 		//self::$debug=true;
1346
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1347
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1524
+		if (self::$debug)
1525
+		{
1526
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1527
+		}
1528
+		if (self::$debug)
1529
+		{
1530
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1531
+		}
1348 1532
 		$reverse = (bool)$_reverse;
1349 1533
 		// get the list of messages to fetch
1350 1534
 		$this->reopen($_folderName);
@@ -1365,21 +1549,34 @@  discard block
 block discarded – undo
1365 1549
 				//$_filter['range'] ="$start:$end";
1366 1550
 				//$_filter['range'] ="$_startMessage:*";
1367 1551
 			}
1368
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1369
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1552
+			if (self::$debug)
1553
+			{
1554
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1555
+			}
1556
+			if (self::$debug||self::$debugTimes)
1557
+			{
1558
+				$starttime = microtime (true);
1559
+			}
1370 1560
 			//see this example below for a 12 week datefilter (since)
1371 1561
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1372 1562
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1373 1563
 			$sortResult = $_sortResult['match']->ids;
1374 1564
 			//$modseq = $_sortResult['modseq'];
1375 1565
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1376
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1566
+			if (self::$debug||self::$debugTimes)
1567
+			{
1568
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1569
+			}
1377 1570
 
1378
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1571
+			if (self::$debug)
1572
+			{
1573
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1574
+			}
1379 1575
 			#$this->icServer->setDebug(false);
1380 1576
 			#print "</pre>";
1381 1577
 			// nothing found
1382
-			if(!is_array($sortResult) || empty($sortResult)) {
1578
+			if(!is_array($sortResult) || empty($sortResult))
1579
+			{
1383 1580
 				$retValue = array();
1384 1581
 				$retValue['info']['total']	= 0;
1385 1582
 				$retValue['info']['first']	= 0;
@@ -1391,7 +1588,8 @@  discard block
 block discarded – undo
1391 1588
 			#_debug_array($sortResult);
1392 1589
 			#_debug_array(array_slice($sortResult, -5, -2));
1393 1590
 			//error_log("REVERSE: $reverse");
1394
-			if($reverse === true) {
1591
+			if($reverse === true)
1592
+			{
1395 1593
 				if  ($_startMessage<=$total)
1396 1594
 				{
1397 1595
 					$startMessage = $_startMessage-1;
@@ -1403,7 +1601,10 @@  discard block
 block discarded – undo
1403 1601
 					{
1404 1602
 						$numberOfMessages = $total%$_numberOfMessages;
1405 1603
 						//$numberOfMessages = abs($_startMessage-$total-1);
1406
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1604
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1605
+						{
1606
+							$_numberOfMessages = $numberOfMessages;
1607
+						}
1407 1608
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1408 1609
 					}
1409 1610
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1417,19 +1618,36 @@  discard block
 block discarded – undo
1417 1618
 					//$retValue['info']['first'] = $startMessage;
1418 1619
 					//$retValue['info']['last'] = $total;
1419 1620
 				}
1420
-				if($startMessage > 0) {
1421
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1621
+				if($startMessage > 0)
1622
+				{
1623
+					if (self::$debug)
1624
+					{
1625
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1626
+					}
1422 1627
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1423
-				} else {
1424
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1628
+				}
1629
+				else
1630
+				{
1631
+					if (self::$debug)
1632
+					{
1633
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1634
+					}
1425 1635
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1426 1636
 				}
1427 1637
 				$sortResult = array_reverse($sortResult);
1428
-			} else {
1429
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1638
+			}
1639
+			else
1640
+			{
1641
+				if (self::$debug)
1642
+				{
1643
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1644
+				}
1430 1645
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1431 1646
 			}
1432
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1647
+			if (self::$debug)
1648
+			{
1649
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1650
+			}
1433 1651
 		}
1434 1652
 		else
1435 1653
 		{
@@ -1438,7 +1656,10 @@  discard block
 block discarded – undo
1438 1656
 
1439 1657
 
1440 1658
 		// fetch the data for the selected messages
1441
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1659
+		if (self::$debug||self::$debugTimes)
1660
+		{
1661
+			$starttime = microtime(true);
1662
+		}
1442 1663
 		try
1443 1664
 		{
1444 1665
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1462,7 +1683,10 @@  discard block
 block discarded – undo
1462 1683
 			$fquery->flags();
1463 1684
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1464 1685
 			// if $_fetchPreviews is activated fetch part of the messages too
1465
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1686
+			if ($_fetchPreviews)
1687
+			{
1688
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1689
+			}
1466 1690
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1467 1691
 				'ids' => $uidsToFetch,
1468 1692
 			));
@@ -1485,14 +1709,20 @@  discard block
 block discarded – undo
1485 1709
 
1486 1710
 		$cnt = 0;
1487 1711
 
1488
-		foreach((array)$sortResult as $uid) {
1712
+		foreach((array)$sortResult as $uid)
1713
+		{
1489 1714
 			$sortOrder[$uid] = $cnt++;
1490 1715
 		}
1491 1716
 
1492 1717
 		$count = 0;
1493
-		if (is_object($headersNew)) {
1494
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1495
-			foreach($headersNew->ids() as $id) {
1718
+		if (is_object($headersNew))
1719
+		{
1720
+			if (self::$debug||self::$debugTimes)
1721
+			{
1722
+				$starttime = microtime(true);
1723
+			}
1724
+			foreach($headersNew->ids() as $id)
1725
+			{
1496 1726
 				$_headerObject = $headersNew->get($id);
1497 1727
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1498 1728
 				$headerObject = array();
@@ -1505,7 +1735,10 @@  discard block
 block discarded – undo
1505 1735
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1506 1736
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1507 1737
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1508
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1738
+				if (empty($headerForPrio))
1739
+				{
1740
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1741
+				}
1509 1742
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1510 1743
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1511 1744
 				if ($_fetchPreviews)
@@ -1516,12 +1749,16 @@  discard block
 block discarded – undo
1516 1749
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1517 1750
 					{
1518 1751
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1519
-						if ($length===false) $length = strlen($bodyPreview);
1752
+						if ($length===false)
1753
+						{
1754
+							$length = strlen($bodyPreview);
1755
+						}
1520 1756
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1521 1757
 					}
1522 1758
 				}
1523 1759
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1524
-				if (self::$debug) {
1760
+				if (self::$debug)
1761
+				{
1525 1762
 					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'));
1526 1763
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1527 1764
 				}
@@ -1531,11 +1768,16 @@  discard block
 block discarded – undo
1531 1768
 					$total--;
1532 1769
 					continue;
1533 1770
 				}
1534
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1771
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1772
+				{
1535 1773
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1536
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1774
+				}
1775
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1776
+				{
1537 1777
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1538
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1778
+				}
1779
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1780
+				{
1539 1781
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1540 1782
 				} /*else $sent_not = "";*/
1541 1783
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1566,7 +1808,11 @@  discard block
 block discarded – undo
1566 1808
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1567 1809
 						foreach ($rfcAddr as $_rfcAddr)
1568 1810
 						{
1569
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1811
+							if (!$_rfcAddr->valid)
1812
+							{
1813
+								continue;
1814
+							}
1815
+							// skip. not a valid address
1570 1816
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1571 1817
 						}
1572 1818
 					}
@@ -1582,7 +1828,10 @@  discard block
 block discarded – undo
1582 1828
 				{
1583 1829
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1584 1830
 					// needed to parse the Headers of the Message
1585
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1831
+					if (empty($bodyPreview))
1832
+					{
1833
+						$bodyPreview = $_headerObject->getFullMsg();
1834
+					}
1586 1835
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1587 1836
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1588 1837
 					foreach($base->partIterator() as $part)
@@ -1595,7 +1844,8 @@  discard block
 block discarded – undo
1595 1844
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1596 1845
 											)), $charset, 'utf-8');
1597 1846
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1598
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1847
+						}
1848
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1599 1849
 						{
1600 1850
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1601 1851
 						}
@@ -1611,7 +1861,10 @@  discard block
 block discarded – undo
1611 1861
 				$messageMimeType='';
1612 1862
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1613 1863
 				{
1614
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1864
+					if ($mime_id==0 || $messageMimeType==='')
1865
+					{
1866
+						$messageMimeType = $mime_type;
1867
+					}
1615 1868
 					$part = $mailStructureObject->getPart($mime_id);
1616 1869
 					$partdisposition = $part->getDisposition();
1617 1870
 					$partPrimaryType = $part->getPrimaryType();
@@ -1621,7 +1874,8 @@  discard block
 block discarded – undo
1621 1874
 					// bodypreview could be found (multipart/....)
1622 1875
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1623 1876
 						((intval($mime_id) === 1) || !$mime_id) &&
1624
-						($partdisposition !== 'attachment')) {
1877
+						($partdisposition !== 'attachment'))
1878
+					{
1625 1879
 							$_structure=$part;
1626 1880
 							$this->fetchPartContents($uid, $_structure, false,true);
1627 1881
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1643,10 +1897,19 @@  discard block
 block discarded – undo
1643 1897
 					if ($mime_type=='message/rfc822')
1644 1898
 					{
1645 1899
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1646
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1900
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1901
+						{
1902
+if ($sub_id != $mime_id)
1903
+						{
1904
+							$skipParts[$sub_id] = $sub_type;
1905
+						}
1906
+						}
1647 1907
 					}
1648 1908
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1649
-					if (array_key_exists($mime_id,$skipParts)) continue;
1909
+					if (array_key_exists($mime_id,$skipParts))
1910
+					{
1911
+						continue;
1912
+					}
1650 1913
 					if ($partdisposition=='attachment' ||
1651 1914
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1652 1915
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1657,7 +1920,10 @@  discard block
 block discarded – undo
1657 1920
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1658 1921
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1659 1922
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1660
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1923
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1924
+						{
1925
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1926
+						}
1661 1927
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1662 1928
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1663 1929
 						{
@@ -1671,18 +1937,27 @@  discard block
 block discarded – undo
1671 1937
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1672 1938
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1673 1939
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1674
-				if (empty($headerObject['UID'])) continue;
1940
+				if (empty($headerObject['UID']))
1941
+				{
1942
+					continue;
1943
+				}
1675 1944
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1676 1945
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1677
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1946
+				if(substr($headerObject['DATE'],-2) === 'UT')
1947
+				{
1678 1948
 					$headerObject['DATE'] .= 'C';
1679 1949
 				}
1680
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1950
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1951
+				{
1681 1952
 					$headerObject['INTERNALDATE'] .= 'C';
1682 1953
 				}
1683 1954
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1684 1955
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1685
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1956
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1957
+				{
1958
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1959
+				}
1960
+				}
1686 1961
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1687 1962
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1688 1963
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1693,22 +1968,31 @@  discard block
 block discarded – undo
1693 1968
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1694 1969
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1695 1970
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1696
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1697
-				if (is_array($headerObject['FLAGS'])) {
1971
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1972
+				{
1973
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1974
+				}
1975
+				if (is_array($headerObject['FLAGS']))
1976
+				{
1698 1977
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1699 1978
 				}
1700 1979
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1701
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1980
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1981
+				{
1702 1982
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1703 1983
 				}
1704
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1984
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1985
+				{
1705 1986
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1706 1987
 					if (count($headerObject['TO'])>1)
1707 1988
 					{
1708 1989
 						$ki=0;
1709 1990
 						foreach($headerObject['TO'] as $k => $add)
1710 1991
 						{
1711
-							if ($k==0) continue;
1992
+							if ($k==0)
1993
+							{
1994
+								continue;
1995
+							}
1712 1996
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1713 1997
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1714 1998
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1716,7 +2000,8 @@  discard block
 block discarded – undo
1716 2000
 						}
1717 2001
 					}
1718 2002
 				}
1719
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
2003
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
2004
+				{
1720 2005
 					$ki=0;
1721 2006
 					foreach($headerObject['CC'] as $k => $add)
1722 2007
 					{
@@ -1730,27 +2015,41 @@  discard block
 block discarded – undo
1730 2015
 
1731 2016
 				$count++;
1732 2017
 			}
1733
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2018
+			if (self::$debug||self::$debugTimes)
2019
+			{
2020
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2021
+			}
1734 2022
 			//self::$debug=false;
1735 2023
 			// sort the messages to the requested displayorder
1736
-			if(is_array($retValue['header'])) {
2024
+			if(is_array($retValue['header']))
2025
+			{
1737 2026
 				$countMessages = $total;
1738
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2027
+				if (isset($_filter['range']))
2028
+				{
2029
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2030
+				}
1739 2031
 				ksort($retValue['header']);
1740 2032
 				$retValue['info']['total']	= $total;
1741 2033
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1742 2034
 				$retValue['info']['first']	= $_startMessage;
1743 2035
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1744 2036
 				return $retValue;
1745
-			} else {
2037
+			}
2038
+			else
2039
+			{
1746 2040
 				$retValue = array();
1747 2041
 				$retValue['info']['total']	= 0;
1748 2042
 				$retValue['info']['first']	= 0;
1749 2043
 				$retValue['info']['last']	= 0;
1750 2044
 				return $retValue;
1751 2045
 			}
1752
-		} else {
1753
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2046
+		}
2047
+		else
2048
+		{
2049
+			if ($headersNew == null && empty($_thisUIDOnly))
2050
+			{
2051
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2052
+			}
1754 2053
 			$retValue = array();
1755 2054
 			$retValue['info']['total']  = 0;
1756 2055
 			$retValue['info']['first']  = 0;
@@ -1767,7 +2066,10 @@  discard block
 block discarded – undo
1767 2066
 	 */
1768 2067
 	static function prepareFlagsArray($headerObject)
1769 2068
 	{
1770
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2069
+		if (is_array($headerObject['FLAGS']))
2070
+		{
2071
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2072
+		}
1771 2073
 		$retValue = array();
1772 2074
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1773 2075
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1818,25 +2120,44 @@  discard block
 block discarded – undo
1818 2120
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1819 2121
 		$try2useCache = true;
1820 2122
 		static $eMailListContainsDeletedMessages = null;
1821
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2123
+		if (is_null($eMailListContainsDeletedMessages))
2124
+		{
2125
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2126
+		}
1822 2127
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1823 2128
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1824 2129
 		{
1825
-			if (self::$debugTimes) $starttime = microtime(true);
1826
-			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);
2130
+			if (self::$debugTimes)
2131
+			{
2132
+				$starttime = microtime(true);
2133
+			}
2134
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2135
+			{
2136
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2137
+			}
1827 2138
 			$five=true;
1828 2139
 			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
1829
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2140
+			if (self::$debug)
2141
+			{
2142
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2143
+			}
1830 2144
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1831 2145
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1832
-			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']);
2146
+			if (self::$debugTimes)
2147
+			{
2148
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2149
+			}
2150
+			//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']);
1833 2151
 		}
1834 2152
 		$try2useCache = false;
1835 2153
 		//self::$supportsORinQuery[$this->profileID]=true;
1836 2154
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1837 2155
 		{
1838 2156
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1839
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2157
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2158
+			{
2159
+				self::$supportsORinQuery[$this->profileID]=true;
2160
+			}
1840 2161
 		}
1841 2162
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1842 2163
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1847,15 +2168,26 @@  discard block
 block discarded – undo
1847 2168
 		}
1848 2169
 		//_debug_array($filter);
1849 2170
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1850
-		if($this->icServer->hasCapability('SORT')) {
2171
+		if($this->icServer->hasCapability('SORT'))
2172
+		{
1851 2173
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1852 2174
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1853 2175
 			// there is no messing with the dates)
1854 2176
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1855
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2177
+			if (self::$debug)
2178
+			{
2179
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2180
+			}
1856 2181
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1857
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1858
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2182
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2183
+			{
2184
+				$_reverse=false;
2185
+			}
2186
+			// as we reversed the result already
2187
+			if (self::$debug)
2188
+			{
2189
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2190
+			}
1859 2191
 			try
1860 2192
 			{
1861 2193
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1867,7 +2199,10 @@  discard block
 block discarded – undo
1867 2199
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1868 2200
 				$resultByUid = false;
1869 2201
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1870
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2202
+				if ($_reverse)
2203
+				{
2204
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2205
+				}
1871 2206
 				try
1872 2207
 				{
1873 2208
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1879,9 +2214,17 @@  discard block
 block discarded – undo
1879 2214
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1880 2215
 				}
1881 2216
 			}
1882
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1883
-		} else {
1884
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2217
+			if (self::$debug)
2218
+			{
2219
+				error_log(__METHOD__.print_r($sortResult,true));
2220
+			}
2221
+		}
2222
+		else
2223
+		{
2224
+			if (self::$debug)
2225
+			{
2226
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2227
+			}
1885 2228
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1886 2229
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1887 2230
 			try
@@ -1895,7 +2238,10 @@  discard block
 block discarded – undo
1895 2238
 				// possible error OR Query. But Horde gives no detailed Info :-(
1896 2239
 				self::$supportsORinQuery[$this->profileID]=false;
1897 2240
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1898
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2241
+				if (self::$debug)
2242
+				{
2243
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2244
+				}
1899 2245
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1900 2246
 				try
1901 2247
 				{
@@ -1906,11 +2252,15 @@  discard block
 block discarded – undo
1906 2252
 				{
1907 2253
 				}
1908 2254
 			}
1909
-			if(is_array($sortResult['match'])) {
2255
+			if(is_array($sortResult['match']))
2256
+			{
1910 2257
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1911 2258
 					sort($sortResult['match'], SORT_NUMERIC);
1912 2259
 			}
1913
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2260
+			if (self::$debug)
2261
+			{
2262
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2263
+			}
1914 2264
 		}
1915 2265
 		if ($setSession)
1916 2266
 		{
@@ -1939,7 +2289,8 @@  discard block
 block discarded – undo
1939 2289
 		$_reverse=false;
1940 2290
 		if (is_numeric($_sort))
1941 2291
 		{
1942
-			switch($_sort) {
2292
+			switch($_sort)
2293
+			{
1943 2294
 				case 2:
1944 2295
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1945 2296
 					break;
@@ -1961,7 +2312,8 @@  discard block
 block discarded – undo
1961 2312
 		}
1962 2313
 		else
1963 2314
 		{
1964
-			switch(strtoupper($_sort)) {
2315
+			switch(strtoupper($_sort))
2316
+			{
1965 2317
 				case 'FROMADDRESS':
1966 2318
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1967 2319
 					break;
@@ -1987,7 +2339,10 @@  discard block
 block discarded – undo
1987 2339
 					break;
1988 2340
 			}
1989 2341
 		}
1990
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2342
+		if ($_reverse)
2343
+		{
2344
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2345
+		}
1991 2346
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1992 2347
 		return $retValue;
1993 2348
 	}
@@ -2006,7 +2361,10 @@  discard block
 block discarded – undo
2006 2361
 		$imapFilter->charset('UTF-8');
2007 2362
 
2008 2363
 		//_debug_array($_criterias);
2009
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2364
+		if (self::$debug)
2365
+		{
2366
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2367
+		}
2010 2368
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2011 2369
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2012 2370
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -2021,11 +2379,13 @@  discard block
 block discarded – undo
2021 2379
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2022 2380
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2023 2381
 		$statusQueryValid = false;
2024
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2382
+		foreach((array)$_criterias['status'] as $k => $criteria)
2383
+		{
2025 2384
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2026 2385
 			$imapStatusFilter->charset('UTF-8');
2027 2386
 			$criteria = strtoupper($criteria);
2028
-			switch ($criteria) {
2387
+			switch ($criteria)
2388
+			{
2029 2389
 				case 'ANSWERED':
2030 2390
 				case 'DELETED':
2031 2391
 				case 'FLAGGED':
@@ -2108,9 +2468,11 @@  discard block
 block discarded – undo
2108 2468
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2109 2469
 		$imapSearchFilter->charset('UTF-8');
2110 2470
 
2111
-		if(!empty($_criterias['string'])) {
2471
+		if(!empty($_criterias['string']))
2472
+		{
2112 2473
 			$criteria = strtoupper($_criterias['type']);
2113
-			switch ($criteria) {
2474
+			switch ($criteria)
2475
+			{
2114 2476
 				case 'BYDATE':
2115 2477
 				case 'QUICK':
2116 2478
 				case 'QUICKWITHCC':
@@ -2118,9 +2480,12 @@  discard block
 block discarded – undo
2118 2480
 					//$imapSearchFilter->charset('UTF-8');
2119 2481
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2120 2482
 					$imapFilter2->charset('UTF-8');
2121
-					if($this->isSentFolder($_folder)) {
2483
+					if($this->isSentFolder($_folder))
2484
+					{
2122 2485
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2123
-					} else {
2486
+					}
2487
+					else
2488
+					{
2124 2489
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2125 2490
 					}
2126 2491
 					if ($_supportsOrInQuery)
@@ -2151,7 +2516,10 @@  discard block
 block discarded – undo
2151 2516
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2152 2517
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2153 2518
 						$numberinBytes=(float)$_criterias['string'];
2154
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2519
+						if (isset($multipleBy[$unit]))
2520
+						{
2521
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2522
+						}
2155 2523
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2156 2524
 						$_criterias['string']=$numberinBytes;
2157 2525
 					}
@@ -2188,8 +2556,14 @@  discard block
 block discarded – undo
2188 2556
 					break;
2189 2557
 			}
2190 2558
 		}
2191
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2192
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2559
+		if ($statusQueryValid && !$queryValid)
2560
+		{
2561
+			$queryValid=true;
2562
+		}
2563
+		if ($queryValid)
2564
+		{
2565
+			$imapFilter->andSearch($imapSearchFilter);
2566
+		}
2193 2567
 
2194 2568
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2195 2569
 		{
@@ -2204,7 +2578,8 @@  discard block
 block discarded – undo
2204 2578
 				unset($_criterias['before']);
2205 2579
 				$criteria=$_criterias['range']='ON';
2206 2580
 			}
2207
-			switch ($criteria) {
2581
+			switch ($criteria)
2582
+			{
2208 2583
 				case 'BETWEEN':
2209 2584
 					//try to be smart about missing
2210 2585
 					//enddate
@@ -2240,8 +2615,14 @@  discard block
 block discarded – undo
2240 2615
 					$rangeValid = true;
2241 2616
 					break;
2242 2617
 			}
2243
-			if ($rangeValid && !$queryValid) $queryValid=true;
2244
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2618
+			if ($rangeValid && !$queryValid)
2619
+			{
2620
+				$queryValid=true;
2621
+			}
2622
+			if ($rangeValid)
2623
+			{
2624
+				$imapFilter->andSearch($imapRangeFilter);
2625
+			}
2245 2626
 		}
2246 2627
 		if (self::$debug)
2247 2628
 		{
@@ -2249,10 +2630,13 @@  discard block
 block discarded – undo
2249 2630
 			$query_str = $imapFilter->build();
2250 2631
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2251 2632
 		}
2252
-		if($queryValid==false) {
2633
+		if($queryValid==false)
2634
+		{
2253 2635
 			$imapFilter->flag('DELETED', $set=false);
2254 2636
 			return $imapFilter;
2255
-		} else {
2637
+		}
2638
+		else
2639
+		{
2256 2640
 			return $imapFilter;
2257 2641
 		}
2258 2642
 	}
@@ -2309,7 +2693,10 @@  discard block
 block discarded – undo
2309 2693
 					}
2310 2694
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2311 2695
 				}
2312
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2696
+				if (!empty($stringA))
2697
+				{
2698
+					$_string = implode(',',$stringA);
2699
+				}
2313 2700
 			}
2314 2701
 			if ($_tryIDNConversion==='FORCE')
2315 2702
 			{
@@ -2334,7 +2721,10 @@  discard block
 block discarded – undo
2334 2721
 		{
2335 2722
 			return 'No Subject';
2336 2723
 		}
2337
-		if ($decode) $_string = self::decode_header($_string);
2724
+		if ($decode)
2725
+		{
2726
+			$_string = self::decode_header($_string);
2727
+		}
2338 2728
 		// make sure its utf-8
2339 2729
 		$test = @json_encode($_string);
2340 2730
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2372,7 +2762,8 @@  discard block
 block discarded – undo
2372 2762
 	 * @param string _parent the parent foldername
2373 2763
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2374 2764
 	 */
2375
-	function _encodeFolderName($_folderName) {
2765
+	function _encodeFolderName($_folderName)
2766
+	{
2376 2767
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2377 2768
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2378 2769
 	}
@@ -2388,21 +2779,36 @@  discard block
 block discarded – undo
2388 2779
 	 */
2389 2780
 	function createFolder($_parent, $_folderName, &$_error)
2390 2781
 	{
2391
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2782
+		if (self::$debug)
2783
+		{
2784
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2785
+		}
2392 2786
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2393 2787
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2394 2788
 
2395
-		if(empty($parent)) {
2789
+		if(empty($parent))
2790
+		{
2396 2791
 			$newFolderName = $folderName;
2397
-		} else {
2792
+		}
2793
+		else
2794
+		{
2398 2795
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2399 2796
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2400 2797
 		}
2401
-		if (empty($newFolderName)) return false;
2402
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2798
+		if (empty($newFolderName))
2799
+		{
2800
+			return false;
2801
+		}
2802
+		if (self::$debug)
2803
+		{
2804
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2805
+		}
2403 2806
 		if ($this->folderExists($newFolderName,true))
2404 2807
 		{
2405
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2808
+			if (self::$debug)
2809
+			{
2810
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2811
+			}
2406 2812
 			return $newFolderName;
2407 2813
 		}
2408 2814
 		try
@@ -2450,13 +2856,19 @@  discard block
 block discarded – undo
2450 2856
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2451 2857
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2452 2858
 
2453
-		if(empty($parent)) {
2859
+		if(empty($parent))
2860
+		{
2454 2861
 			$newFolderName = $folderName;
2455
-		} else {
2862
+		}
2863
+		else
2864
+		{
2456 2865
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2457 2866
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2458 2867
 		}
2459
-		if (self::$debug) error_log("create folder: $newFolderName");
2868
+		if (self::$debug)
2869
+		{
2870
+			error_log("create folder: $newFolderName");
2871
+		}
2460 2872
 		try
2461 2873
 		{
2462 2874
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2530,8 +2942,14 @@  discard block
 block discarded – undo
2530 2942
 	 */
2531 2943
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2532 2944
 	{
2533
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2534
-		if (self::$debugTimes) $starttime = microtime (true);
2945
+		if (self::$debug)
2946
+		{
2947
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2948
+		}
2949
+		if (self::$debugTimes)
2950
+		{
2951
+			$starttime = microtime (true);
2952
+		}
2535 2953
 		static $folders2return;
2536 2954
 		//$_subscribedOnly=false;
2537 2955
 		// always use static on single request if info is available;
@@ -2539,23 +2957,35 @@  discard block
 block discarded – undo
2539 2957
 		// set $_useCacheIfPossible to false !
2540 2958
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2541 2959
 		{
2542
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2960
+			if (self::$debugTimes)
2961
+			{
2962
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2963
+			}
2543 2964
 			return $folders2return[$this->icServer->ImapServerId];
2544 2965
 		}
2545 2966
 
2546 2967
 		if ($_subscribedOnly && $_getCounters===false)
2547 2968
 		{
2548
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2969
+			if (is_null($folders2return))
2970
+			{
2971
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2972
+			}
2549 2973
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2550 2974
 			{
2551 2975
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2552
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2976
+				if (self::$debugTimes)
2977
+				{
2978
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2979
+				}
2553 2980
 				return $folders2return[$this->icServer->ImapServerId];
2554 2981
 			}
2555 2982
 		}
2556 2983
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2557 2984
 		static $folderBasicInfo;
2558
-		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);
2985
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2986
+		{
2987
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2988
+		}
2559 2989
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2560 2990
 
2561 2991
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2568,7 +2998,8 @@  discard block
 block discarded – undo
2568 2998
 		$inboxData->shortFolderName	= 'INBOX';
2569 2999
 		$inboxData->shortDisplayName	= lang('INBOX');
2570 3000
 		$inboxData->subscribed = true;
2571
-		if($_getCounters == true) {
3001
+		if($_getCounters == true)
3002
+		{
2572 3003
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2573 3004
 		}
2574 3005
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2587,12 +3018,14 @@  discard block
 block discarded – undo
2587 3018
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2588 3019
 		if (is_array($nameSpace))
2589 3020
 		{
2590
-			foreach($nameSpace as $k => $singleNameSpace) {
3021
+			foreach($nameSpace as $k => $singleNameSpace)
3022
+			{
2591 3023
 				$type = $singleNameSpace['type'];
2592 3024
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2593 3025
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2594 3026
 
2595
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
3027
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
3028
+				{
2596 3029
 					// fetch and sort the subscribed folders
2597 3030
 					// we alway fetch the subscribed, as this provides the only way to tell
2598 3031
 					// if a folder is subscribed or not
@@ -2643,8 +3076,12 @@  discard block
 block discarded – undo
2643 3076
 							}
2644 3077
 						}
2645 3078
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2646
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2647
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3079
+						if (!is_array($foldersNameSpace[$type]['all']))
3080
+						{
3081
+							$foldersNameSpace[$type]['all'] = array();
3082
+						}
3083
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3084
+						{
2648 3085
 							continue;
2649 3086
 						}
2650 3087
 
@@ -2674,7 +3111,8 @@  discard block
 block discarded – undo
2674 3111
 					}
2675 3112
 
2676 3113
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2677
-					foreach ($allMailboxesExt as $mbx) {
3114
+					foreach ($allMailboxesExt as $mbx)
3115
+					{
2678 3116
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2679 3117
 						{
2680 3118
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2697,20 +3135,33 @@  discard block
 block discarded – undo
2697 3135
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2698 3136
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2699 3137
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2700
-						) continue;
3138
+						)
3139
+						{
3140
+							continue;
3141
+						}
2701 3142
 
2702 3143
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2703 3144
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2704 3145
 					}
2705
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3146
+					if (is_array($allMailBoxesExtSorted))
3147
+					{
3148
+						ksort($allMailBoxesExtSorted);
3149
+					}
2706 3150
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2707 3151
 					$allMailboxes = array();
2708
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2709
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3152
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3153
+					{
3154
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3155
+						{
3156
+							$allMailboxes[] = $mbx['MAILBOX'];
3157
+						}
2710 3158
 						//echo "Result:";_debug_array($allMailboxes);
2711 3159
 					}
2712 3160
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2713
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3161
+					if (is_array($foldersNameSpace[$type]['all']))
3162
+					{
3163
+						sort($foldersNameSpace[$type]['all']);
3164
+					}
2714 3165
 				}
2715 3166
 			}
2716 3167
 		}
@@ -2719,24 +3170,50 @@  discard block
 block discarded – undo
2719 3170
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2720 3171
 		$autoFolderObjects = $folders = array();
2721 3172
 		$autofolder_exists = array();
2722
-		foreach( array('personal', 'others', 'shared') as $type) {
2723
-			if(isset($foldersNameSpace[$type])) {
2724
-				if($_subscribedOnly) {
2725
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2726
-				} else {
2727
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2728
-				}
2729
-				foreach((array)$listOfFolders as $folderName) {
3173
+		foreach( array('personal', 'others', 'shared') as $type)
3174
+		{
3175
+			if(isset($foldersNameSpace[$type]))
3176
+			{
3177
+				if($_subscribedOnly)
3178
+				{
3179
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3180
+					{
3181
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3182
+					}
3183
+				}
3184
+				else
3185
+				{
3186
+					if( !empty($foldersNameSpace[$type]['all']))
3187
+					{
3188
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3189
+					}
3190
+				}
3191
+				foreach((array)$listOfFolders as $folderName)
3192
+				{
2730 3193
 					//echo "<br>FolderToCheck:$folderName<br>";
2731 3194
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2732
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2733
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3195
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3196
+					{
3197
+						continue;
3198
+					}
3199
+					//when subscribedonly, we fetch all folders in one go.
3200
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3201
+					{
2734 3202
 						#echo "$folderName failed to be here <br>";
2735 3203
 						continue;
2736 3204
 					}
2737
-					if (isset($folders[$folderName])) continue;
2738
-					if (isset($autoFolderObjects[$folderName])) continue;
2739
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3205
+					if (isset($folders[$folderName]))
3206
+					{
3207
+						continue;
3208
+					}
3209
+					if (isset($autoFolderObjects[$folderName]))
3210
+					{
3211
+						continue;
3212
+					}
3213
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3214
+					{
3215
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3216
+					}
2740 3217
 					$folderParts = explode($delimiter, $folderName);
2741 3218
 					$shortName = array_pop($folderParts);
2742 3219
 
@@ -2744,17 +3221,20 @@  discard block
 block discarded – undo
2744 3221
 					$folderObject->delimiter	= $delimiter;
2745 3222
 					$folderObject->folderName	= $folderName;
2746 3223
 					$folderObject->shortFolderName	= $shortName;
2747
-					if(!$_subscribedOnly) {
3224
+					if(!$_subscribedOnly)
3225
+					{
2748 3226
 						#echo $folderName."->".$type."<br>";
2749 3227
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2750 3228
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2751 3229
 					}
2752 3230
 
2753
-					if($_getCounters == true) {
3231
+					if($_getCounters == true)
3232
+					{
2754 3233
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2755 3234
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2756 3235
 					}
2757
-					if(strtoupper($folderName) == 'INBOX') {
3236
+					if(strtoupper($folderName) == 'INBOX')
3237
+					{
2758 3238
 						$folderName = 'INBOX';
2759 3239
 						$folderObject->folderName	= 'INBOX';
2760 3240
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2762,24 +3242,34 @@  discard block
 block discarded – undo
2762 3242
 						$folderObject->shortDisplayName = lang('INBOX');
2763 3243
 						$folderObject->subscribed	= true;
2764 3244
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2765
-					} elseif (in_array($shortName,self::$autoFolders)) {
3245
+					}
3246
+					elseif (in_array($shortName,self::$autoFolders))
3247
+					{
2766 3248
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2767 3249
 						array_pop($tmpfolderparts);
2768 3250
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2769 3251
 						$folderObject->shortDisplayName = lang($shortName);
2770 3252
 						unset($tmpfolderparts);
2771
-					} else {
3253
+					}
3254
+					else
3255
+					{
2772 3256
 						$folderObject->displayName = $folderObject->folderName;
2773 3257
 						$folderObject->shortDisplayName = $shortName;
2774 3258
 					}
2775 3259
 					//$folderName = $folderName;
2776
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3260
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3261
+					{
2777 3262
 						$autoFolderObjects[$folderName] = $folderObject;
2778
-					} else {
3263
+					}
3264
+					else
3265
+					{
2779 3266
 						$folders[$folderName] = $folderObject;
2780 3267
 					}
2781 3268
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2782
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3269
+					if (!isset(self::$specialUseFolders))
3270
+					{
3271
+						$this->getSpecialUseFolders ();
3272
+					}
2783 3273
 					if (isset(self::$specialUseFolders[$folderName]))
2784 3274
 					{
2785 3275
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2787,7 +3277,8 @@  discard block
 block discarded – undo
2787 3277
 				}
2788 3278
 			}
2789 3279
 		}
2790
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3280
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3281
+		{
2791 3282
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2792 3283
 		}
2793 3284
 		// check if some standard folders are missing and need to be created
@@ -2796,7 +3287,10 @@  discard block
 block discarded – undo
2796 3287
 			// if new folders have been created, re-read folders ignoring the cache
2797 3288
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2798 3289
 		}
2799
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3290
+		if (is_array($folders))
3291
+		{
3292
+			uasort($folders,array($this,"sortByDisplayName"));
3293
+		}
2800 3294
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2801 3295
 		//_debug_array($folders2return); #exit;
2802 3296
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2808,7 +3302,10 @@  discard block
 block discarded – undo
2808 3302
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2809 3303
 		}
2810 3304
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2811
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3305
+		if (self::$debugTimes)
3306
+		{
3307
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3308
+		}
2812 3309
 		return $folders2return[$this->icServer->ImapServerId];
2813 3310
 	}
2814 3311
 
@@ -2836,31 +3333,44 @@  discard block
 block discarded – undo
2836 3333
 
2837 3334
 		$folders = $nameSpace =  array();
2838 3335
 		$nameSpaceTmp = $this->_getNameSpaces();
2839
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3336
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3337
+		{
2840 3338
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2841 3339
 		}
2842 3340
 		unset($nameSpaceTmp);
2843 3341
 
2844 3342
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2845 3343
 		// Get special use folders
2846
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3344
+		if (!isset(self::$specialUseFolders))
3345
+		{
3346
+			$this->getSpecialUseFolders ();
3347
+		}
3348
+		// Set self::$specialUseFolders
2847 3349
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2848
-		if ($_onlyTopLevel) // top level leaves
3350
+		if ($_onlyTopLevel)
3351
+		{
3352
+			// top level leaves
2849 3353
 		{
2850 3354
 			// Get top mailboxes of icServer
2851 3355
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3356
+		}
2852 3357
 			// Trigger examination of namespace to retrieve
2853 3358
 			// folders located in other and shared; needed only for some servers
2854
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3359
+			if (is_null(self::$mailConfig))
3360
+			{
3361
+				self::$mailConfig = Config::read('mail');
3362
+			}
2855 3363
 			if (self::$mailConfig['examineNamespace'])
2856 3364
 			{
2857 3365
 				$prefixes=array();
2858 3366
 				if (is_array($nameSpace))
2859 3367
 				{
2860
-					foreach($nameSpace as $k => $singleNameSpace) {
3368
+					foreach($nameSpace as $k => $singleNameSpace)
3369
+					{
2861 3370
 						$type = $singleNameSpace['type'];
2862 3371
 
2863
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3372
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3373
+						{
2864 3374
 							$prefixes[$type] = $singleNameSpace['prefix'];
2865 3375
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2866 3376
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2936,7 +3446,10 @@  discard block
 block discarded – undo
2936 3446
 							$nFolders [$path] = $folder;
2937 3447
 						}
2938 3448
 					}
2939
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3449
+					if (is_array($aFolders))
3450
+					{
3451
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3452
+					}
2940 3453
 					//ksort($aFolders);
2941 3454
 
2942 3455
 					// Sort none auto folders base on mailbox name
@@ -2946,12 +3459,17 @@  discard block
 block discarded – undo
2946 3459
 				}
2947 3460
 				else
2948 3461
 				{
2949
-					if (is_array($subFolders)) ksort($subFolders);
3462
+					if (is_array($subFolders))
3463
+					{
3464
+						ksort($subFolders);
3465
+					}
2950 3466
 				}
2951 3467
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2952 3468
 			}
2953 3469
 		}
2954
-		elseif ($_nodePath) // single node
3470
+		elseif ($_nodePath)
3471
+		{
3472
+			// single node
2955 3473
 		{
2956 3474
 			switch ($_search)
2957 3475
 			{
@@ -2959,6 +3477,7 @@  discard block
 block discarded – undo
2959 3477
 				case 0:
2960 3478
 				case 2:
2961 3479
 					$path = $_nodePath.''.$delimiter;
3480
+		}
2962 3481
 					break;
2963 3482
 				// Node itself
2964 3483
 				// shouldn't contain next level delimiter
@@ -2977,11 +3496,14 @@  discard block
 block discarded – undo
2977 3496
 
2978 3497
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2979 3498
 		}
2980
-		elseif(!$_nodePath) // all
3499
+		elseif(!$_nodePath)
3500
+		{
3501
+			// all
2981 3502
 		{
2982 3503
 			if ($_subscribedOnly)
2983 3504
 			{
2984 3505
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3506
+		}
2985 3507
 			}
2986 3508
 			else
2987 3509
 			{
@@ -2993,7 +3515,10 @@  discard block
 block discarded – undo
2993 3515
 		{
2994 3516
 			// SORTING FOLDERS
2995 3517
 			//self::$debugTimes=true;
2996
-			if (self::$debugTimes) $starttime = microtime (true);
3518
+			if (self::$debugTimes)
3519
+			{
3520
+				$starttime = microtime (true);
3521
+			}
2997 3522
 			// Merge of all auto folders and specialusefolders
2998 3523
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2999 3524
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -3003,73 +3528,103 @@  discard block
 block discarded – undo
3003 3528
 			$isGoogleMail=false;
3004 3529
 			foreach($autoFoldersTmp as $afk=>$aF)
3005 3530
 			{
3006
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3531
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3532
+				{
3533
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3534
+				}
3007 3535
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3008 3536
 			}
3009 3537
 			//error_log(array2string($mySpecialUseFolders));
3010
-			foreach ($tmpFolders as $k => $f) {
3538
+			foreach ($tmpFolders as $k => $f)
3539
+			{
3011 3540
 				$sorted=false;
3012
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3013
-					if (strtoupper($k)=='INBOX') {
3541
+				if (strtoupper(substr($k,0,5))=='INBOX')
3542
+				{
3543
+					if (strtoupper($k)=='INBOX')
3544
+					{
3014 3545
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3015 3546
 						$inboxFolderObject[$k]=$f;
3016 3547
 						unset($folders[$k]);
3017 3548
 						$sorted=true;
3018
-					} else {
3549
+					}
3550
+					else
3551
+					{
3019 3552
 						$isAutoFolder=false;
3020 3553
 						foreach($autoFoldersTmp as $afk=>$aF)
3021 3554
 						{
3022 3555
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3023 3556
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3024 3557
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3025
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3558
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3559
+							{
3560
+								// k is parent of an autofolder
3026 3561
 							{
3027 3562
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3028 3563
 								$isAutoFolder=true;
3564
+							}
3029 3565
 								$autoFolderObjects[$k]=$f;
3030 3566
 								break;
3031 3567
 							}
3032 3568
 						}
3033
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3569
+						if ($isAutoFolder==false)
3570
+						{
3571
+							$inboxSubFolderObjects[$k]=$f;
3572
+						}
3034 3573
 						unset($folders[$k]);
3035 3574
 						$sorted=true;
3036 3575
 					}
3037
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3576
+				}
3577
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3578
+				{
3038 3579
 					$isGoogleMail=true;
3039
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3580
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3581
+					{
3040 3582
 						$googleMailFolderObject[$k]=$f;
3041 3583
 						unset($folders[$k]);
3042 3584
 						$sorted=true;
3043
-					} else {
3585
+					}
3586
+					else
3587
+					{
3044 3588
 						$isAutoFolder=false;
3045 3589
 						foreach($autoFoldersTmp as $afk=>$aF)
3046 3590
 						{
3047 3591
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3048 3592
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3049 3593
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3050
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3594
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3595
+							{
3596
+								// k is parent of an autofolder
3051 3597
 							{
3052 3598
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3053 3599
 								$isAutoFolder=true;
3600
+							}
3054 3601
 								$googleAutoFolderObjects[$k]=$f;
3055 3602
 								break;
3056 3603
 							}
3057 3604
 						}
3058
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3605
+						if ($isAutoFolder==false)
3606
+						{
3607
+							$googleSubFolderObjects[$k]=$f;
3608
+						}
3059 3609
 						unset($folders[$k]);
3060 3610
 						$sorted=true;
3061 3611
 					}
3062
-				} else {
3612
+				}
3613
+				else
3614
+				{
3063 3615
 					$isAutoFolder=false;
3064 3616
 					foreach($autoFoldersTmp as $afk=>$aF)
3065 3617
 					{
3066 3618
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3067 3619
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3068 3620
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3069
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3621
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3622
+						{
3623
+							// k is parent of an autofolder
3070 3624
 						{
3071 3625
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3072 3626
 							$isAutoFolder=true;
3627
+						}
3073 3628
 							$autoFolderObjects[$k]=$f;
3074 3629
 							unset($folders[$k]);
3075 3630
 							$sorted=true;
@@ -3085,7 +3640,8 @@  discard block
 block discarded – undo
3085 3640
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3086 3641
 						{
3087 3642
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3088
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3643
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3644
+							{
3089 3645
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3090 3646
 								$typeFolderObject[$type][$k]=$f;
3091 3647
 								unset($folders[$k]);
@@ -3112,9 +3668,12 @@  discard block
 block discarded – undo
3112 3668
 				}
3113 3669
 			}
3114 3670
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3115
-			if (!$isGoogleMail) {
3671
+			if (!$isGoogleMail)
3672
+			{
3116 3673
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3117
-			} else {
3674
+			}
3675
+			else
3676
+			{
3118 3677
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3119 3678
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3120 3679
 				unset($googleAutoFolderObjects);
@@ -3131,7 +3690,10 @@  discard block
 block discarded – undo
3131 3690
 				}
3132 3691
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3133 3692
 			}
3134
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3693
+			if (self::$debugTimes)
3694
+			{
3695
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3696
+			}
3135 3697
 			//self::$debugTimes=false;
3136 3698
 		}
3137 3699
 		// Get counter information and add them to each fetched folders array
@@ -3181,7 +3743,13 @@  discard block
 block discarded – undo
3181 3743
 		$rv = false;
3182 3744
 		foreach ($haystack as $k => $v)
3183 3745
 		{
3184
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3746
+			foreach($v as &$sv)
3747
+			{
3748
+if (trim($sv)==trim($needle))
3749
+			{
3750
+				return $k;
3751
+			}
3752
+			}
3185 3753
 		}
3186 3754
 		return $rv;
3187 3755
 	}
@@ -3208,7 +3776,10 @@  discard block
 block discarded – undo
3208 3776
 	 */
3209 3777
 	static function pathToFolderData ($_path, $_hDelimiter)
3210 3778
 	{
3211
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3779
+		if (!strpos($_path, self::DELIMITER))
3780
+		{
3781
+			$_path = self::DELIMITER.$_path;
3782
+		}
3212 3783
 		list(,$path) = explode(self::DELIMITER, $_path);
3213 3784
 		$path_chain = $parts = explode($_hDelimiter, $path);
3214 3785
 		$name = array_pop($parts);
@@ -3237,7 +3808,10 @@  discard block
 block discarded – undo
3237 3808
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3238 3809
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3239 3810
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3240
-		if ($pos1 == $pos2) return 0;
3811
+		if ($pos1 == $pos2)
3812
+		{
3813
+			return 0;
3814
+		}
3241 3815
 		return ($pos1 < $pos2) ? -1 : 1;
3242 3816
 	}
3243 3817
 
@@ -3268,7 +3842,10 @@  discard block
 block discarded – undo
3268 3842
 		// 0, 1 und -1
3269 3843
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3270 3844
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3271
-		if ($pos1 == $pos2) return 0;
3845
+		if ($pos1 == $pos2)
3846
+		{
3847
+			return 0;
3848
+		}
3272 3849
 		return ($pos1 < $pos2) ? -1 : 1;
3273 3850
 	}
3274 3851
 
@@ -3289,11 +3866,18 @@  discard block
 block discarded – undo
3289 3866
 		}
3290 3867
 		catch (\Exception $e)
3291 3868
 		{
3292
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3869
+			if (self::$debug)
3870
+			{
3871
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3872
+			}
3293 3873
 			return false;
3294 3874
 		}
3295
-		if(is_array($folderStatus)) {
3296
-			if ($_returnObject===false) return $folderStatus;
3875
+		if(is_array($folderStatus))
3876
+		{
3877
+			if ($_returnObject===false)
3878
+			{
3879
+				return $folderStatus;
3880
+			}
3297 3881
 			$status =  new \stdClass;
3298 3882
 			$status->messages   = $folderStatus['MESSAGES'];
3299 3883
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3320,7 +3904,8 @@  discard block
 block discarded – undo
3320 3904
 	{
3321 3905
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3322 3906
 		$maxreclevel=25;
3323
-		if ($reclevel > $maxreclevel) {
3907
+		if ($reclevel > $maxreclevel)
3908
+		{
3324 3909
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3325 3910
 			return array();
3326 3911
 		}
@@ -3334,7 +3919,8 @@  discard block
 block discarded – undo
3334 3919
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3335 3920
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3336 3921
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3337
-		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"]))) {
3922
+		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"])))
3923
+		{
3338 3924
 			// if there are children fetch them
3339 3925
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3340 3926
 
@@ -3342,7 +3928,8 @@  discard block
 block discarded – undo
3342 3928
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3343 3929
 			//_debug_array($buff);
3344 3930
 			$allMailboxes = array();
3345
-			foreach ($buff as $mbxname) {
3931
+			foreach ($buff as $mbxname)
3932
+			{
3346 3933
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3347 3934
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3348 3935
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3351,9 +3938,14 @@  discard block
 block discarded – undo
3351 3938
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3352 3939
 				}
3353 3940
 			}
3354
-			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'];
3941
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3942
+			{
3943
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3944
+			}
3355 3945
 			return $allMailboxes;
3356
-		} else {
3946
+		}
3947
+		else
3948
+		{
3357 3949
 			return array($_mailbox);
3358 3950
 		}
3359 3951
 	}
@@ -3377,14 +3969,21 @@  discard block
 block discarded – undo
3377 3969
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3378 3970
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3379 3971
 		);
3380
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3972
+		if ($_type == 'Templates')
3973
+		{
3974
+			$_type = 'Template';
3975
+		}
3976
+		// for some reason self::$autofolders uses 'Templates'!
3381 3977
 		$created = false;
3382 3978
 		if (!isset($types[$_type]))
3383 3979
 		{
3384 3980
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3385 3981
 			return false;
3386 3982
 		}
3387
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3983
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3984
+		{
3985
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3986
+		}
3388 3987
 
3389 3988
 		//highest precedence
3390 3989
 		try
@@ -3394,25 +3993,39 @@  discard block
 block discarded – undo
3394 3993
 		catch (\Exception $e)
3395 3994
 		{
3396 3995
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3397
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3996
+			if ($_type != 'Outbox')
3997
+			{
3998
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3999
+			}
3398 4000
 			$_folderName = false;
3399 4001
 		}
3400 4002
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3401
-		if ($_type == 'Archive') {
3402
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4003
+		if ($_type == 'Archive')
4004
+		{
4005
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4006
+			{
3403 4007
 				return false;
3404
-			} else {
4008
+			}
4009
+			else
4010
+			{
3405 4011
 				return $_folderName;
3406 4012
 			}
3407 4013
 
3408 4014
 		}
3409 4015
 		// does the folder exist??? (is configured/preset, but non-existent)
3410
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4016
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4017
+		{
3411 4018
 			try
3412 4019
 			{
3413 4020
 				$error = null;
3414
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3415
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4021
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
4022
+				{
4023
+					$created = true;
4024
+				}
4025
+				if ($error)
4026
+				{
4027
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4028
+				}
3416 4029
 			}
3417 4030
 			catch(Exception $e)
3418 4031
 			{
@@ -3421,9 +4034,16 @@  discard block
 block discarded – undo
3421 4034
 			}
3422 4035
 		}
3423 4036
 		// not sure yet if false is the correct behavior on none
3424
-		if ($_folderName =='none') return 'none' ; //false;
4037
+		if ($_folderName =='none')
4038
+		{
4039
+			return 'none' ;
4040
+		}
4041
+		//false;
3425 4042
 		//no (valid) folder found yet; try specialUseFolders
3426
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
4043
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
4044
+		{
4045
+			$_folderName = $f;
4046
+		}
3427 4047
 		//no specialUseFolder; try some Defaults
3428 4048
 		if (empty($_folderName) && isset($types[$_type]))
3429 4049
 		{
@@ -3449,7 +4069,10 @@  discard block
 block discarded – undo
3449 4069
 					$error = null;
3450 4070
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3451 4071
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3452
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4072
+					if ($error)
4073
+					{
4074
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4075
+					}
3453 4076
 				}
3454 4077
 				catch(Exception $e)
3455 4078
 				{
@@ -3551,17 +4174,22 @@  discard block
 block discarded – undo
3551 4174
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3552 4175
 	{
3553 4176
 		$sentFolder = $this->getSentFolder($_checkexistance);
3554
-		if(empty($sentFolder)) {
4177
+		if(empty($sentFolder))
4178
+		{
3555 4179
 			return false;
3556 4180
 		}
3557 4181
 		// does the folder exist???
3558
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4182
+		if ($_checkexistance && !$this->folderExists($_folderName))
4183
+		{
3559 4184
 			return false;
3560 4185
 		}
3561 4186
 
3562
-		if(false !== stripos($_folderName, $sentFolder)) {
4187
+		if(false !== stripos($_folderName, $sentFolder))
4188
+		{
3563 4189
 			return true;
3564
-		} else {
4190
+		}
4191
+		else
4192
+		{
3565 4193
 			return false;
3566 4194
 		}
3567 4195
 	}
@@ -3574,15 +4202,20 @@  discard block
 block discarded – undo
3574 4202
 	 */
3575 4203
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3576 4204
 	{
3577
-		if (stripos($_folderName, 'Outbox')===false) {
4205
+		if (stripos($_folderName, 'Outbox')===false)
4206
+		{
3578 4207
 			return false;
3579 4208
 		}
3580 4209
 		// does the folder exist???
3581
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4210
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4211
+		{
3582 4212
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3583
-			if(false !== stripos($_folderName, $outboxFolder)) {
4213
+			if(false !== stripos($_folderName, $outboxFolder))
4214
+			{
3584 4215
 				return true;
3585
-			} else {
4216
+			}
4217
+			else
4218
+			{
3586 4219
 				return false;
3587 4220
 			}
3588 4221
 		}
@@ -3598,17 +4231,25 @@  discard block
 block discarded – undo
3598 4231
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3599 4232
 	{
3600 4233
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3601
-		if(empty($draftFolder)) {
4234
+		if(empty($draftFolder))
4235
+		{
3602 4236
 			return false;
3603 4237
 		}
3604 4238
 		// does the folder exist???
3605
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4239
+		if ($_checkexistance && !$this->folderExists($_folderName))
4240
+		{
3606 4241
 			return false;
3607 4242
 		}
3608
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3609
-		if(false !== stripos($_folderName, $draftFolder)) {
4243
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4244
+		{
4245
+			$_folderName = $_folderName->utf8;
4246
+		}
4247
+		if(false !== stripos($_folderName, $draftFolder))
4248
+		{
3610 4249
 			return true;
3611
-		} else {
4250
+		}
4251
+		else
4252
+		{
3612 4253
 			return false;
3613 4254
 		}
3614 4255
 	}
@@ -3622,17 +4263,22 @@  discard block
 block discarded – undo
3622 4263
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3623 4264
 	{
3624 4265
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3625
-		if(empty($trashFolder)) {
4266
+		if(empty($trashFolder))
4267
+		{
3626 4268
 			return false;
3627 4269
 		}
3628 4270
 		// does the folder exist???
3629
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4271
+		if ($_checkexistance && !$this->folderExists($_folderName))
4272
+		{
3630 4273
 			return false;
3631 4274
 		}
3632 4275
 
3633
-		if(false !== stripos($_folderName, $trashFolder)) {
4276
+		if(false !== stripos($_folderName, $trashFolder))
4277
+		{
3634 4278
 			return true;
3635
-		} else {
4279
+		}
4280
+		else
4281
+		{
3636 4282
 			return false;
3637 4283
 		}
3638 4284
 	}
@@ -3646,17 +4292,22 @@  discard block
 block discarded – undo
3646 4292
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3647 4293
 	{
3648 4294
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3649
-		if(empty($templateFolder)) {
4295
+		if(empty($templateFolder))
4296
+		{
3650 4297
 			return false;
3651 4298
 		}
3652 4299
 		// does the folder exist???
3653
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4300
+		if ($_checkexistance && !$this->folderExists($_folderName))
4301
+		{
3654 4302
 			return false;
3655 4303
 		}
3656 4304
 
3657
-		if(false !== stripos($_folderName, $templateFolder)) {
4305
+		if(false !== stripos($_folderName, $templateFolder))
4306
+		{
3658 4307
 			return true;
3659
-		} else {
4308
+		}
4309
+		else
4310
+		{
3660 4311
 			return false;
3661 4312
 		}
3662 4313
 	}
@@ -3674,15 +4325,27 @@  discard block
 block discarded – undo
3674 4325
 		if (empty($_folder))
3675 4326
 		{
3676 4327
 			// this error is more or less without significance, unless we force the check
3677
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4328
+			if ($_forceCheck===true)
4329
+			{
4330
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4331
+			}
3678 4332
 			return false;
3679 4333
 		}
3680 4334
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3681
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3682
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4335
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4336
+		{
4337
+			return true;
4338
+		}
4339
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4340
+		{
4341
+			$_folder =  $_folder->utf8;
4342
+		}
3683 4343
 		// reduce traffic within the Instance per User; Expire every 5 hours
3684 4344
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3685
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4345
+		if (is_null($folderInfo))
4346
+		{
4347
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4348
+		}
3686 4349
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3687 4350
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3688 4351
 		{
@@ -3700,7 +4363,8 @@  discard block
 block discarded – undo
3700 4363
 
3701 4364
 		// does the folder exist???
3702 4365
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3703
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4366
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4367
+		{
3704 4368
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3705 4369
 			//return false;
3706 4370
 			//try to connect
@@ -3741,9 +4405,12 @@  discard block
 block discarded – undo
3741 4405
 
3742 4406
 		$this->icServer->openMailbox($folderName);
3743 4407
 
3744
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4408
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4409
+		{
3745 4410
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3746
-		} else {
4411
+		}
4412
+		else
4413
+		{
3747 4414
 			$this->icServer->expunge($folderName);
3748 4415
 		}
3749 4416
 	}
@@ -3762,10 +4429,16 @@  discard block
 block discarded – undo
3762 4429
 	{
3763 4430
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3764 4431
 		$oldMailbox = '';
3765
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4432
+		if (is_null($_folder) || empty($_folder))
4433
+		{
4434
+			$_folder = $this->sessionData['mailbox'];
4435
+		}
3766 4436
 		if (empty($_messageUID))
3767 4437
 		{
3768
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4438
+			if (self::$debug)
4439
+			{
4440
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4441
+			}
3769 4442
 			return false;
3770 4443
 		}
3771 4444
 		elseif ($_messageUID==='all')
@@ -3775,32 +4448,48 @@  discard block
 block discarded – undo
3775 4448
 		else
3776 4449
 		{
3777 4450
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3778
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4451
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4452
+			{
4453
+				$_messageUID = (array)$_messageUID;
4454
+			}
3779 4455
 			$uidsToDelete->add($_messageUID);
3780 4456
 		}
3781 4457
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3782
-		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");
4458
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4459
+		{
4460
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4461
+		}
3783 4462
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3784 4463
 		$trashFolder    = $this->getTrashFolder();
3785 4464
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3786 4465
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3787 4466
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3788
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4467
+		   (strtolower($_folder) == strtolower($draftFolder)))
4468
+		{
3789 4469
 			$deleteOptions = "remove_immediately";
3790 4470
 		}
3791
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4471
+		if($this->icServer->getCurrentMailbox() != $_folder)
4472
+		{
3792 4473
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3793 4474
 			$this->icServer->openMailbox($_folder);
3794 4475
 		}
3795 4476
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3796 4477
 		$updateCache = false;
3797
-		switch($deleteOptions) {
4478
+		switch($deleteOptions)
4479
+		{
3798 4480
 			case "move_to_trash":
3799 4481
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3800 4482
 				$updateCache = true;
3801
-				if(!empty($trashFolder)) {
3802
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3803
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4483
+				if(!empty($trashFolder))
4484
+				{
4485
+					if (self::$debug)
4486
+					{
4487
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4488
+					}
4489
+					if (self::$debug)
4490
+					{
4491
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4492
+					}
3804 4493
 					// copy messages
3805 4494
 					try
3806 4495
 					{
@@ -3816,7 +4505,10 @@  discard block
 block discarded – undo
3816 4505
 			case "mark_as_deleted":
3817 4506
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3818 4507
 				// mark messages as deleted
3819
-				if (is_null($_messageUID)) $_messageUID='all';
4508
+				if (is_null($_messageUID))
4509
+				{
4510
+					$_messageUID='all';
4511
+				}
3820 4512
 				foreach((array)$_messageUID as $key =>$uid)
3821 4513
 				{
3822 4514
 					//flag messages, that are flagged for deletion as seen too
@@ -3824,7 +4516,10 @@  discard block
 block discarded – undo
3824 4516
 					$flags = $this->getFlags($uid);
3825 4517
 					$this->flagMessages('delete', $uid, $_folder);
3826 4518
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3827
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4519
+					if (strpos( array2string($flags),'Deleted')!==false)
4520
+					{
4521
+						$undelete[] = $uid;
4522
+					}
3828 4523
 					unset($flags);
3829 4524
 				}
3830 4525
 				foreach((array)$undelete as $key =>$uid)
@@ -3836,7 +4531,10 @@  discard block
 block discarded – undo
3836 4531
 			case "remove_immediately":
3837 4532
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3838 4533
 				$updateCache = true;
3839
-				if (is_null($_messageUID)) $_messageUID='all';
4534
+				if (is_null($_messageUID))
4535
+				{
4536
+					$_messageUID='all';
4537
+				}
3840 4538
 				if (is_object($_messageUID))
3841 4539
 				{
3842 4540
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3853,7 +4551,8 @@  discard block
 block discarded – undo
3853 4551
 				$this->icServer->expunge($_folder);
3854 4552
 				break;
3855 4553
 		}
3856
-		if($oldMailbox != '') {
4554
+		if($oldMailbox != '')
4555
+		{
3857 4556
 			$this->icServer->openMailbox($oldMailbox);
3858 4557
 		}
3859 4558
 
@@ -3867,11 +4566,15 @@  discard block
 block discarded – undo
3867 4566
 	 *
3868 4567
 	 * @return null/array flags
3869 4568
 	 */
3870
-	function getFlags ($_messageUID) {
4569
+	function getFlags ($_messageUID)
4570
+	{
3871 4571
 		try
3872 4572
 		{
3873 4573
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3874
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4574
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4575
+			{
4576
+				$_messageUID = (array)$_messageUID;
4577
+			}
3875 4578
 			$uidsToFetch->add($_messageUID);
3876 4579
 			$_folderName = $this->icServer->getCurrentMailbox();
3877 4580
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3879,8 +4582,10 @@  discard block
 block discarded – undo
3879 4582
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3880 4583
 				'ids' => $uidsToFetch,
3881 4584
 			));
3882
-			if (is_object($headersNew)) {
3883
-				foreach($headersNew->ids() as $id) {
4585
+			if (is_object($headersNew))
4586
+			{
4587
+				foreach($headersNew->ids() as $id)
4588
+				{
3884 4589
 					$_headerObject = $headersNew->get($id);
3885 4590
 					$flags = $_headerObject->getFlags();
3886 4591
 				}
@@ -3905,10 +4610,16 @@  discard block
 block discarded – undo
3905 4610
 	 */
3906 4611
 	function getNotifyFlags ($_messageUID, $flags=null)
3907 4612
 	{
3908
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4613
+		if (self::$debug)
4614
+		{
4615
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4616
+		}
3909 4617
 		try
3910 4618
 		{
3911
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4619
+			if($flags===null)
4620
+			{
4621
+				$flags =  $this->getFlags($_messageUID);
4622
+			}
3912 4623
 		}
3913 4624
 		catch (\Exception $e)
3914 4625
 		{
@@ -3916,10 +4627,14 @@  discard block
 block discarded – undo
3916 4627
 		}
3917 4628
 
3918 4629
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3919
-			return true;
4630
+		{
4631
+					return true;
4632
+		}
3920 4633
 
3921 4634
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3922
-			return false;
4635
+		{
4636
+					return false;
4637
+		}
3923 4638
 
3924 4639
 		return null;
3925 4640
 	}
@@ -3940,7 +4655,10 @@  discard block
 block discarded – undo
3940 4655
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3941 4656
 		if (empty($_messageUID))
3942 4657
 		{
3943
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4658
+			if (self::$debug)
4659
+			{
4660
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4661
+			}
3944 4662
 			return false;
3945 4663
 		}
3946 4664
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3948,7 +4666,10 @@  discard block
 block discarded – undo
3948 4666
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3949 4667
 		{
3950 4668
 			$count = $this->getMailBoxCounters($folder,true);
3951
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4669
+			if ($count->messages == count($_messageUID))
4670
+			{
4671
+				$_messageUID='all';
4672
+			}
3952 4673
 		}
3953 4674
 
3954 4675
 		if ($_messageUID==='all')
@@ -3957,7 +4678,10 @@  discard block
 block discarded – undo
3957 4678
 		}
3958 4679
 		else
3959 4680
 		{
3960
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4681
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4682
+			{
4683
+				$_messageUID = (array)$_messageUID;
4684
+			}
3961 4685
 			$messageUIDs = array_chunk($_messageUID,50,true);
3962 4686
 		}
3963 4687
 		try
@@ -3973,7 +4697,8 @@  discard block
 block discarded – undo
3973 4697
 					$uidsToModify = new Horde_Imap_Client_Ids();
3974 4698
 					$uidsToModify->add($uids);
3975 4699
 				}
3976
-				switch($_flag) {
4700
+				switch($_flag)
4701
+				{
3977 4702
 					case "delete":
3978 4703
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3979 4704
 						break;
@@ -4059,7 +4784,10 @@  discard block
 block discarded – undo
4059 4784
 		{
4060 4785
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4061 4786
 		}
4062
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4787
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4788
+		{
4789
+			$_folder = $folder->utf8;
4790
+		}
4063 4791
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4064 4792
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4065 4793
 
@@ -4088,7 +4816,10 @@  discard block
 block discarded – undo
4088 4816
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4089 4817
 		if (empty($_messageUID))
4090 4818
 		{
4091
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4819
+			if (self::$debug)
4820
+			{
4821
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4822
+			}
4092 4823
 			return false;
4093 4824
 		}
4094 4825
 		elseif ($_messageUID==='all')
@@ -4100,7 +4831,10 @@  discard block
 block discarded – undo
4100 4831
 		{
4101 4832
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4102 4833
 			$uidsToMove = new Horde_Imap_Client_Ids();
4103
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4834
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4835
+			{
4836
+				$_messageUID = (array)$_messageUID;
4837
+			}
4104 4838
 			$uidsToMove->add($_messageUID);
4105 4839
 		}
4106 4840
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4122,12 +4856,14 @@  discard block
 block discarded – undo
4122 4856
 
4123 4857
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4124 4858
 
4125
-			if (is_object($headersNew)) {
4859
+			if (is_object($headersNew))
4860
+			{
4126 4861
 				$c=0;
4127 4862
 				$retUid = new Horde_Imap_Client_Ids();
4128 4863
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4129 4864
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4130
-				foreach($headersNew as &$_headerObject) {
4865
+				foreach($headersNew as &$_headerObject)
4866
+				{
4131 4867
 					$c++;
4132 4868
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4133 4869
 					$date = $_headerObject->getImapDate();
@@ -4211,7 +4947,11 @@  discard block
 block discarded – undo
4211 4947
 	{
4212 4948
 		try {
4213 4949
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4214
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4950
+			if ($convert2usertime)
4951
+			{
4952
+				$date->setUser();
4953
+			}
4954
+			// convert to user-time
4215 4955
 			$date2return = $date->format($format);
4216 4956
 		}
4217 4957
 		catch(\Exception $e)
@@ -4243,9 +4983,15 @@  discard block
 block discarded – undo
4243 4983
 	static function htmlentities($_string, $_charset=false)
4244 4984
 	{
4245 4985
 		//setting the charset (if not given)
4246
-		if ($_charset===false) $_charset = self::$displayCharset;
4986
+		if ($_charset===false)
4987
+		{
4988
+			$_charset = self::$displayCharset;
4989
+		}
4247 4990
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4248
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4991
+		if (empty($string) && !empty($_string))
4992
+		{
4993
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4994
+		}
4249 4995
 		return $string;
4250 4996
 	}
4251 4997
 
@@ -4265,18 +5011,41 @@  discard block
 block discarded – undo
4265 5011
 		$_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>'),
4266 5012
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4267 5013
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4268
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4269
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
5014
+		if (stripos($_html,'style')!==false)
5015
+		{
5016
+			Mail\Html::replaceTagsCompletley($_html,'style');
5017
+		}
5018
+		// clean out empty or pagewide style definitions / left over tags
5019
+		if (stripos($_html,'head')!==false)
5020
+		{
5021
+			Mail\Html::replaceTagsCompletley($_html,'head');
5022
+		}
5023
+		// Strip out stuff in head
4270 5024
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4271 5025
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4272 5026
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4273 5027
 
4274
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
5028
+		if (get_magic_quotes_gpc() === 1)
5029
+		{
5030
+			$_html = stripslashes($_html);
5031
+		}
4275 5032
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4276
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4277
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4278
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4279
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5033
+		if (stripos($_html,'!doctype')!==false)
5034
+		{
5035
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
5036
+		}
5037
+		if (stripos($_html,'?xml:namespace')!==false)
5038
+		{
5039
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
5040
+		}
5041
+		if (stripos($_html,'?xml version')!==false)
5042
+		{
5043
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
5044
+		}
5045
+		if (strpos($_html,'!CURSOR')!==false)
5046
+		{
5047
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5048
+		}
4280 5049
 		// htmLawed filter only the 'body'
4281 5050
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4282 5051
 		//if ($matches[2])
@@ -4315,8 +5084,10 @@  discard block
 block discarded – undo
4315 5084
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4316 5085
 		$CharsetFound=false;
4317 5086
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4318
-		if(is_array($_mimePartObject->parameters)) {
4319
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5087
+		if(is_array($_mimePartObject->parameters))
5088
+		{
5089
+			if(isset($_mimePartObject->parameters['CHARSET']))
5090
+			{
4320 5091
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4321 5092
 				$CharsetFound=true;
4322 5093
 			}
@@ -4337,7 +5108,10 @@  discard block
 block discarded – undo
4337 5108
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4338 5109
 	{
4339 5110
 		// decode the part
4340
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5111
+		if (self::$debug)
5112
+		{
5113
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5114
+		}
4341 5115
 		switch (strtoupper($_encoding))
4342 5116
 		{
4343 5117
 			case 'BASE64':
@@ -4377,13 +5151,19 @@  discard block
 block discarded – undo
4377 5151
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4378 5152
 		// as attachment AND as abstracted ical information (we use our notification style here).
4379 5153
 		$partText = $partCalendar = $partHTML = null;
4380
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5154
+		if (self::$debug)
5155
+		{
5156
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5157
+		}
4381 5158
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4382 5159
 		$ignore_first_part = true;
4383 5160
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4384 5161
 		{
4385 5162
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4386
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5163
+			if (self::$debug)
5164
+			{
5165
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5166
+			}
4387 5167
 
4388 5168
 			if ($ignore_first_part)
4389 5169
 			{
@@ -4399,11 +5179,17 @@  discard block
 block discarded – undo
4399 5179
 					switch($mimePart->getSubType())
4400 5180
 					{
4401 5181
 						case 'plain':
4402
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5182
+							if ($mimePart->getBytes() > 0)
5183
+							{
5184
+								$partText = $mimePart;
5185
+							}
4403 5186
 							break;
4404 5187
 
4405 5188
 						case 'html':
4406
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5189
+							if ($mimePart->getBytes() > 0)
5190
+							{
5191
+								$partHTML = $mimePart;
5192
+							}
4407 5193
 							break;
4408 5194
 					}
4409 5195
 					break;
@@ -4416,7 +5202,10 @@  discard block
 block discarded – undo
4416 5202
 							if (count($mimePart->getParts()) > 1)
4417 5203
 							{
4418 5204
 								// in a multipart alternative we treat the multipart/related as html part
4419
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5205
+								if (self::$debug)
5206
+								{
5207
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5208
+								}
4420 5209
 								$partHTML = $mimePart;
4421 5210
 								break 3; // GET OUT OF LOOP, will be processed according to type
4422 5211
 							}
@@ -4497,9 +5286,15 @@  discard block
 block discarded – undo
4497 5286
 	 */
4498 5287
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4499 5288
 	{
4500
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5289
+		if (self::$debug)
5290
+		{
5291
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5292
+		}
4501 5293
 		$bodyPart = array();
4502
-		if (self::$debug) _debug_array($_structure);
5294
+		if (self::$debug)
5295
+		{
5296
+			_debug_array($_structure);
5297
+		}
4503 5298
 
4504 5299
 		$ignore_first_part = true;
4505 5300
 		//$skipParts = array();
@@ -4507,7 +5302,10 @@  discard block
 block discarded – undo
4507 5302
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4508 5303
 		{
4509 5304
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4510
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5305
+			if (self::$debug)
5306
+			{
5307
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5308
+			}
4511 5309
 			if ($ignore_first_part)
4512 5310
 			{
4513 5311
 				$ignore_first_part = false;
@@ -4525,7 +5323,10 @@  discard block
 block discarded – undo
4525 5323
 			switch($part->getPrimaryType())
4526 5324
 			{
4527 5325
 				case 'multipart':
4528
-					if ($part->getDisposition() == 'attachment') continue;
5326
+					if ($part->getDisposition() == 'attachment')
5327
+					{
5328
+						continue;
5329
+					}
4529 5330
 					switch($part->getSubType())
4530 5331
 					{
4531 5332
 						case 'alternative':
@@ -4590,7 +5391,9 @@  discard block
 block discarded – undo
4590 5391
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4591 5392
 					{
4592 5393
 						$skipParts[$mime_id.'.0'] = $mime_type;
4593
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5394
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5395
+						{
5396
+$skipParts[$sub_id] = $sub_type;}
4594 5397
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4595 5398
 						//break 2;
4596 5399
 					}
@@ -4633,7 +5436,10 @@  discard block
 block discarded – undo
4633 5436
 	 */
4634 5437
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4635 5438
 	{
4636
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5439
+		if (self::$debug)
5440
+		{
5441
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5442
+		}
4637 5443
 
4638 5444
 		if (empty($_folder))
4639 5445
 		{
@@ -4642,7 +5448,10 @@  discard block
 block discarded – undo
4642 5448
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4643 5449
 		// querying contents of body part
4644 5450
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4645
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5451
+		if (!(is_object($_uid) || is_array($_uid)))
5452
+		{
5453
+			$_uid = (array)$_uid;
5454
+		}
4646 5455
 		$uidsToFetch->add($_uid);
4647 5456
 
4648 5457
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4650,9 +5459,12 @@  discard block
 block discarded – undo
4650 5459
 			'peek' => $_preserveSeen,
4651 5460
 			'decode' => true,	// try decode on server, does NOT neccessary work
4652 5461
 		);
4653
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5462
+		if ($_tryDecodingServerside===false)
5463
+		{
5464
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4654 5465
 		{
4655 5466
 			$_tryDecodingServerside=false;
5467
+		}
4656 5468
 			$fetchParams = array(
4657 5469
 				'peek' => $_preserveSeen,
4658 5470
 			);
@@ -4694,7 +5506,10 @@  discard block
 block discarded – undo
4694 5506
 	{
4695 5507
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4696 5508
 		$bodyPart = array();
4697
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5509
+		if (self::$debug)
5510
+		{
5511
+			_debug_array(array($_structure,function_backtrace()));
5512
+		}
4698 5513
 
4699 5514
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4700 5515
 		{
@@ -4744,8 +5559,12 @@  discard block
 block discarded – undo
4744 5559
 	 */
4745 5560
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4746 5561
 	{
4747
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4748
-		if($_htmlOptions != '') {
5562
+		if (self::$debug)
5563
+		{
5564
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5565
+		}
5566
+		if($_htmlOptions != '')
5567
+		{
4749 5568
 			$this->htmlOptions = $_htmlOptions;
4750 5569
 		}
4751 5570
 		if (empty($_folder))
@@ -4834,7 +5653,9 @@  discard block
 block discarded – undo
4834 5653
 						default:
4835 5654
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4836 5655
 					}
4837
-				} else {
5656
+				}
5657
+				else
5658
+				{
4838 5659
 					// what if the structure->disposition is attachment ,...
4839 5660
 				}
4840 5661
 				return self::normalizeBodyParts($bodyPart);
@@ -4845,13 +5666,18 @@  discard block
 block discarded – undo
4845 5666
 				{
4846 5667
 					case 'rfc822':
4847 5668
 						$newStructure = $_structure->getParts();
4848
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5669
+						if (self::$debug)
5670
+						{
5671
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4849 5672
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4850 5673
 				}
4851 5674
 				break;
4852 5675
 
4853 5676
 			default:
4854
-				if (self::$debug) _debug_array($_structure);
5677
+				if (self::$debug)
5678
+				{
5679
+					_debug_array($_structure);
5680
+				}
4855 5681
 				return array(
4856 5682
 					array(
4857 5683
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4875,9 +5701,12 @@  discard block
 block discarded – undo
4875 5701
 		{
4876 5702
 			foreach($_bodyParts as $singleBodyPart)
4877 5703
 			{
4878
-				if (!isset($singleBodyPart['body'])) {
5704
+				if (!isset($singleBodyPart['body']))
5705
+				{
4879 5706
 					$buff = self::normalizeBodyParts($singleBodyPart);
4880
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5707
+					foreach ((array)$buff as $val)
5708
+					{
5709
+$body2return[] = $val;}
4881 5710
 					continue;
4882 5711
 				}
4883 5712
 				$body2return[] = $singleBodyPart;
@@ -4903,13 +5732,20 @@  discard block
 block discarded – undo
4903 5732
 		$message='';
4904 5733
 		for($i=0; $i<count($bodyParts); $i++)
4905 5734
 		{
4906
-			if (!isset($bodyParts[$i]['body'])) {
5735
+			if (!isset($bodyParts[$i]['body']))
5736
+			{
4907 5737
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4908 5738
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4909 5739
 				continue;
4910 5740
 			}
4911
-			if (isset($bodyParts[$i]['error'])) continue;
4912
-			if (empty($bodyParts[$i]['body'])) continue;
5741
+			if (isset($bodyParts[$i]['error']))
5742
+			{
5743
+				continue;
5744
+			}
5745
+			if (empty($bodyParts[$i]['body']))
5746
+			{
5747
+				continue;
5748
+			}
4913 5749
 			// some characterreplacements, as they fail to translate
4914 5750
 			$sar = array(
4915 5751
 				'@(\x84|\x93|\x94)@',
@@ -4936,13 +5772,17 @@  discard block
 block discarded – undo
4936 5772
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4937 5773
 			}
4938 5774
 
4939
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5775
+			if ($bodyParts[$i]['charSet']===false)
5776
+			{
5777
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5778
+			}
4940 5779
 			// add line breaks to $bodyParts
4941 5780
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4942 5781
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4943 5782
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4944 5783
 			$mailClass->activeMimeType = 'text/plain';
4945
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5784
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5785
+			{
4946 5786
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4947 5787
 				if (!$preserveHTML)
4948 5788
 				{
@@ -4988,15 +5828,28 @@  discard block
 block discarded – undo
4988 5828
 						// as we switched off HTMLaweds tidy functionality
4989 5829
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4990 5830
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4991
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5831
+						if ($hasOther && $preserveHTML)
5832
+						{
5833
+							$newBody = $matches[1]. $newBody. $matches[3];
5834
+						}
4992 5835
 						$alreadyHtmlLawed=true;
4993 5836
 					}
4994 5837
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4995
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5838
+					if ($preserveHTML==false)
5839
+					{
5840
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5841
+					}
4996 5842
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4997
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5843
+					if ($preserveHTML==false)
5844
+					{
5845
+						$newBody = nl2br($newBody);
5846
+					}
5847
+					// we need this, as htmLawed removes \r\n
4998 5848
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4999
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5849
+					if ($preserveHTML==false)
5850
+					{
5851
+						$newBody = str_replace("<br />","\r\n",$newBody);
5852
+					}
5000 5853
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5001 5854
 				}
5002 5855
 				$message .= $newBody;
@@ -5033,12 +5886,12 @@  discard block
 block discarded – undo
5033 5886
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5034 5887
 				 )
5035 5888
 				)
5036
-			   )
5037
-			{
5889
+			   ) {
5038 5890
 				$s=explode(" ", $line);
5039 5891
 				$line = "";
5040 5892
 				$linecnt = 0;
5041
-				foreach ($s as &$v) {
5893
+				foreach ($s as &$v)
5894
+				{
5042 5895
 					$cnt = strlen($v);
5043 5896
 					// only break long words within the wordboundaries,
5044 5897
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -5048,14 +5901,20 @@  discard block
 block discarded – undo
5048 5901
 						$v=wordwrap($v, $allowedLength, $cut, true);
5049 5902
 					}
5050 5903
 					// the rest should be broken at the start of the new word that exceeds the limit
5051
-					if ($linecnt+$cnt > $allowedLength) {
5904
+					if ($linecnt+$cnt > $allowedLength)
5905
+					{
5052 5906
 						$v=$cut.$v;
5053 5907
 						#$linecnt = 0;
5054 5908
 						$linecnt =strlen($v)-strlen($cut);
5055
-					} else {
5909
+					}
5910
+					else
5911
+					{
5056 5912
 						$linecnt += $cnt;
5057 5913
 					}
5058
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5914
+					if (strlen($v))
5915
+					{
5916
+						$line .= (strlen($line) ? " " : "").$v;
5917
+					}
5059 5918
 				}
5060 5919
 			}
5061 5920
 			$newStr .= $line . "\n";
@@ -5076,11 +5935,18 @@  discard block
 block discarded – undo
5076 5935
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5077 5936
 	{
5078 5937
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5079
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5938
+		if (empty($_folder))
5939
+		{
5940
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5941
+		}
5080 5942
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5081
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5943
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5944
+		{
5082 5945
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5083
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5946
+			if (!(is_object($_uid) || is_array($_uid)))
5947
+			{
5948
+				$_uid = (array)$_uid;
5949
+			}
5084 5950
 			$uidsToFetch->add($_uid);
5085 5951
 
5086 5952
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5090,8 +5956,10 @@  discard block
 block discarded – undo
5090 5956
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5091 5957
 				'ids' => $uidsToFetch,
5092 5958
 			));
5093
-			if (is_object($headersNew)) {
5094
-				foreach($headersNew as &$_headerObject) {
5959
+			if (is_object($headersNew))
5960
+			{
5961
+				foreach($headersNew as &$_headerObject)
5962
+				{
5095 5963
 					$env = $_headerObject->getEnvelope();
5096 5964
 					//_debug_array($envFields->singleFields());
5097 5965
 					$singleFields = $envFields->singleFields();
@@ -5108,7 +5976,10 @@  discard block
 block discarded – undo
5108 5976
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5109 5977
 								$envelope[$v]=$env->$v->addresses;
5110 5978
 								$address = array();
5111
-								if (!is_array($envelope[$v])) break;
5979
+								if (!is_array($envelope[$v]))
5980
+								{
5981
+									break;
5982
+								}
5112 5983
 								foreach ($envelope[$v] as $k => $ad)
5113 5984
 								{
5114 5985
 									if (stripos($ad,'@')===false)
@@ -5145,7 +6016,9 @@  discard block
 block discarded – undo
5145 6016
 				}
5146 6017
 			}
5147 6018
 			return $envelope;
5148
-		} else {
6019
+		}
6020
+		else
6021
+		{
5149 6022
 
5150 6023
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5151 6024
 
@@ -5156,19 +6029,43 @@  discard block
 block discarded – undo
5156 6029
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5157 6030
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5158 6031
 			);
5159
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5160
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5161
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5162
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5163
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5164
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
6032
+			if (isset($headers['IN-REPLY-TO']))
6033
+			{
6034
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
6035
+			}
6036
+			if (isset($headers['REFERENCES']))
6037
+			{
6038
+				$newData['REFERENCES'] = $headers['REFERENCES'];
6039
+			}
6040
+			if (isset($headers['THREAD-TOPIC']))
6041
+			{
6042
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
6043
+			}
6044
+			if (isset($headers['THREAD-INDEX']))
6045
+			{
6046
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6047
+			}
6048
+			if (isset($headers['LIST-ID']))
6049
+			{
6050
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6051
+			}
6052
+			if (isset($headers['SIZE']))
6053
+			{
6054
+				$newData['SIZE'] = $headers['SIZE'];
6055
+			}
5165 6056
 			//_debug_array($newData);
5166 6057
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5167
-			foreach($recepientList as $recepientType) {
5168
-				if(isset($headers[$recepientType])) {
5169
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6058
+			foreach($recepientList as $recepientType)
6059
+			{
6060
+				if(isset($headers[$recepientType]))
6061
+				{
6062
+					if ($decode)
6063
+					{
6064
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6065
+					}
5170 6066
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5171
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6067
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6068
+					{
5172 6069
 						$addressData = array(
5173 6070
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5174 6071
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5176,17 +6073,25 @@  discard block
 block discarded – undo
5176 6073
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5177 6074
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5178 6075
 						);
5179
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6076
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6077
+						{
5180 6078
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5181
-						} else {
6079
+						}
6080
+						else
6081
+						{
5182 6082
 							$addressData['RFC822_EMAIL'] = 'NIL';
5183 6083
 						}
5184 6084
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5185 6085
 					}
5186
-				} else {
5187
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6086
+				}
6087
+				else
6088
+				{
6089
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6090
+					{
5188 6091
 						$newData[$recepientType] = $newData['FROM'];
5189
-					} else {
6092
+					}
6093
+					else
6094
+					{
5190 6095
 						$newData[$recepientType] = array();
5191 6096
 					}
5192 6097
 				}
@@ -5209,9 +6114,15 @@  discard block
 block discarded – undo
5209 6114
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5210 6115
 	{
5211 6116
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5212
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6117
+		if (empty($_folder))
6118
+		{
6119
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6120
+		}
5213 6121
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5214
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6122
+		if (!(is_object($_uid) || is_array($_uid)))
6123
+		{
6124
+			$_uid = (array)$_uid;
6125
+		}
5215 6126
 		$uidsToFetch->add($_uid);
5216 6127
 
5217 6128
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5229,7 +6140,8 @@  discard block
 block discarded – undo
5229 6140
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5230 6141
 			'ids' => $uidsToFetch,
5231 6142
 		));
5232
-		if (is_object($headersNew)) {
6143
+		if (is_object($headersNew))
6144
+		{
5233 6145
 			foreach($headersNew as $_fetchObject)
5234 6146
 			{
5235 6147
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5251,11 +6163,17 @@  discard block
 block discarded – undo
5251 6163
 			}
5252 6164
 			if ($decode === 'object')
5253 6165
 			{
5254
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6166
+				if (is_object($headers))
6167
+				{
6168
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6169
+				}
5255 6170
 				return $headers;
5256 6171
 			}
5257 6172
 			$retValue = is_object($headers) ? $headers->toArray():array();
5258
-			if ($size) $retValue['size'] = $size;
6173
+			if ($size)
6174
+			{
6175
+				$retValue['size'] = $size;
6176
+			}
5259 6177
 		}
5260 6178
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5261 6179
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5287,10 +6205,16 @@  discard block
 block discarded – undo
5287 6205
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5288 6206
 	{
5289 6207
 		static $rawHeaders;
5290
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6208
+		if (empty($_folder))
6209
+		{
6210
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6211
+		}
5291 6212
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5292 6213
 
5293
-		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);
6214
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6215
+		{
6216
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6217
+		}
5294 6218
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5295 6219
 		{
5296 6220
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5298,7 +6222,10 @@  discard block
 block discarded – undo
5298 6222
 		}
5299 6223
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5300 6224
 		$uid = $_uid;
5301
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6225
+		if (!(is_object($_uid) || is_array($_uid)))
6226
+		{
6227
+			$uid = (array)$_uid;
6228
+		}
5302 6229
 		$uidsToFetch->add($uid);
5303 6230
 
5304 6231
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5314,8 +6241,10 @@  discard block
 block discarded – undo
5314 6241
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5315 6242
 			'ids' => $uidsToFetch,
5316 6243
 		));
5317
-		if (is_object($headersNew)) {
5318
-			foreach($headersNew as &$_headerObject) {
6244
+		if (is_object($headersNew))
6245
+		{
6246
+			foreach($headersNew as &$_headerObject)
6247
+			{
5319 6248
 				$retValue = $_headerObject->getHeaderText();
5320 6249
 				if ($_partID != '')
5321 6250
 				{
@@ -5343,22 +6272,33 @@  discard block
 block discarded – undo
5343 6272
 	static function &getStyles($_bodyParts)
5344 6273
 	{
5345 6274
 		$style = '';
5346
-		if (empty($_bodyParts)) return "";
5347
-		foreach((array)$_bodyParts as $singleBodyPart) {
5348
-			if (!isset($singleBodyPart['body'])) {
6275
+		if (empty($_bodyParts))
6276
+		{
6277
+			return "";
6278
+		}
6279
+		foreach((array)$_bodyParts as $singleBodyPart)
6280
+		{
6281
+			if (!isset($singleBodyPart['body']))
6282
+			{
5349 6283
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5350 6284
 				$style .= $singleBodyPart['body'];
5351 6285
 				continue;
5352 6286
 			}
5353 6287
 
5354
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6288
+			if ($singleBodyPart['charSet']===false)
6289
+			{
6290
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6291
+			}
5355 6292
 			$singleBodyPart['body'] = Translation::convert(
5356 6293
 				$singleBodyPart['body'],
5357 6294
 				strtolower($singleBodyPart['charSet'])
5358 6295
 			);
5359 6296
 			$ct = 0;
5360 6297
 			$newStyle=array();
5361
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6298
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6299
+			{
6300
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6301
+			}
5362 6302
 			if ($ct>0)
5363 6303
 			{
5364 6304
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5390,7 +6330,11 @@  discard block
 block discarded – undo
5390 6330
 		// CSS Security
5391 6331
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5392 6332
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5393
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6333
+		if (stripos($css,'script')!==false)
6334
+		{
6335
+			Mail\Html::replaceTagsCompletley($css,'script');
6336
+		}
6337
+		// Strip out script that may be included
5394 6338
 		// 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
5395 6339
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5396 6340
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5411,8 +6355,14 @@  discard block
 block discarded – undo
5411 6355
 	{
5412 6356
 		//TODO: caching einbauen static!
5413 6357
 		static $rawBody;
5414
-		if (is_null($rawBody)) $rawBody = array();
5415
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6358
+		if (is_null($rawBody))
6359
+		{
6360
+			$rawBody = array();
6361
+		}
6362
+		if (empty($_folder))
6363
+		{
6364
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6365
+		}
5416 6366
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5417 6367
 		{
5418 6368
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5421,7 +6371,10 @@  discard block
 block discarded – undo
5421 6371
 
5422 6372
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5423 6373
 		$uid = $_uid;
5424
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6374
+		if (!(is_object($_uid) || is_array($_uid)))
6375
+		{
6376
+			$uid = (array)$_uid;
6377
+		}
5425 6378
 		$uidsToFetch->add($uid);
5426 6379
 
5427 6380
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5434,8 +6387,10 @@  discard block
 block discarded – undo
5434 6387
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5435 6388
 			'ids' => $uidsToFetch,
5436 6389
 		));
5437
-		if (is_object($headersNew)) {
5438
-			foreach($headersNew as &$_headerObject) {
6390
+		if (is_object($headersNew))
6391
+		{
6392
+			foreach($headersNew as &$_headerObject)
6393
+			{
5439 6394
 				$body = $_headerObject->getFullMsg();
5440 6395
 				if ($_partID != '')
5441 6396
 				{
@@ -5468,14 +6423,20 @@  discard block
 block discarded – undo
5468 6423
 	 */
5469 6424
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5470 6425
 	{
5471
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6426
+		if (self::$debug)
6427
+		{
6428
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6429
+		}
5472 6430
 
5473 6431
 		if (empty($_folder))
5474 6432
 		{
5475 6433
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5476 6434
 		}
5477 6435
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5478
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6436
+		if (!(is_object($_uid) || is_array($_uid)))
6437
+		{
6438
+			$_uid = (array)$_uid;
6439
+		}
5479 6440
 		$uidsToFetch->add($_uid);
5480 6441
 		try
5481 6442
 		{
@@ -5484,7 +6445,10 @@  discard block
 block discarded – undo
5484 6445
 	//		$fquery->envelope();
5485 6446
 	//		$fquery->size();
5486 6447
 			$_fquery->structure();
5487
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6448
+			if ($_partID)
6449
+			{
6450
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6451
+			}
5488 6452
 
5489 6453
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5490 6454
 				'ids' => $uidsToFetch,
@@ -5515,16 +6479,28 @@  discard block
 block discarded – undo
5515 6479
 	 */
5516 6480
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5517 6481
 	{
5518
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5519
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6482
+		if (self::$debug)
6483
+		{
6484
+			error_log( __METHOD__.":$_uid, $_partID");
6485
+		}
6486
+		if (empty($_folder))
6487
+		{
6488
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6489
+		}
5520 6490
 		$attachments = array();
5521 6491
 		if (!isset($_structure))
5522 6492
 		{
5523 6493
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5524 6494
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5525 6495
 		}
5526
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5527
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6496
+		if (!$_structure || !$_structure->contentTypeMap())
6497
+		{
6498
+			return array();
6499
+		}
6500
+		if (!empty($_partID))
6501
+		{
6502
+			$_structure = $_structure->getPart($_partID);
6503
+		}
5528 6504
 		$skipParts = array();
5529 6505
 		$tnefParts = array();
5530 6506
 		$skip = 0;
@@ -5553,7 +6529,13 @@  discard block
 block discarded – undo
5553 6529
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5554 6530
 			{
5555 6531
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5556
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6532
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6533
+				{
6534
+if ($sub_id != $mime_id)
6535
+				{
6536
+					$skipParts[$sub_id] = $sub_type;
6537
+				}
6538
+				}
5557 6539
 			}
5558 6540
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5559 6541
 			{
@@ -5564,7 +6546,10 @@  discard block
 block discarded – undo
5564 6546
 				$partDisposition='attachment';
5565 6547
 			}
5566 6548
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5567
-			if (array_key_exists($mime_id,$skipParts)) continue;
6549
+			if (array_key_exists($mime_id,$skipParts))
6550
+			{
6551
+				continue;
6552
+			}
5568 6553
 
5569 6554
 			if ($partDisposition == 'attachment' ||
5570 6555
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5575,23 +6560,41 @@  discard block
 block discarded – undo
5575 6560
 			{
5576 6561
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5577 6562
 				// we attempt to fetch "ourselves"
5578
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6563
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6564
+				{
6565
+					continue;
6566
+				}
5579 6567
 				$attachment = $part->getAllDispositionParameters();
5580 6568
 				$attachment['disposition'] = $part->getDisposition();
5581 6569
 				$attachment['mimeType'] = $mime_type;
5582 6570
 				$attachment['uid'] = $_uid;
5583 6571
 				$attachment['partID'] = $mime_id;
5584
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6572
+				if (!isset($attachment['name'])||empty($attachment['name']))
6573
+				{
6574
+					$attachment['name'] = $part->getName();
6575
+				}
5585 6576
 				if ($fetchTextCalendar)
5586 6577
 				{
5587 6578
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5588 6579
 					$method = $part->getContentTypeParameter('method');
5589
-					if ($method) $attachment['method'] = $method;
5590
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6580
+					if ($method)
6581
+					{
6582
+						$attachment['method'] = $method;
6583
+					}
6584
+					if (!isset($attachment['name']))
6585
+					{
6586
+						$attachment['name'] = 'event.ics';
6587
+					}
5591 6588
 				}
5592 6589
 				$attachment['size'] = $part->getBytes();
5593
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5594
-				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);
6590
+				if (($cid = $part->getContentId()))
6591
+				{
6592
+					$attachment['cid'] = $cid;
6593
+				}
6594
+				if (empty($attachment['name']))
6595
+				{
6596
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6597
+				}
5595 6598
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5596 6599
 				//typical winmail.dat attachment is
5597 6600
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5627,14 +6630,26 @@  discard block
 block discarded – undo
5627 6630
 						$attachment['uid'] = $tnp['uid'];
5628 6631
 						$attachment['partID'] = $tnp['partID'];
5629 6632
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5630
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6633
+						if (!isset($attachment['name'])||empty($attachment['name']))
6634
+						{
6635
+							$attachment['name'] = $part->getName();
6636
+						}
5631 6637
 						$attachment['size'] = $part->getBytes();
5632
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5633
-						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']);
6638
+						if (($cid = $part->getContentId()))
6639
+						{
6640
+							$attachment['cid'] = $cid;
6641
+						}
6642
+						if (empty($attachment['name']))
6643
+						{
6644
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6645
+						}
5634 6646
 						$attachments[] = $attachment;
5635 6647
 					}
5636 6648
 				}
5637
-				if ($tnefResolved===false) $attachments[]=$tnp;
6649
+				if ($tnefResolved===false)
6650
+				{
6651
+					$attachments[]=$tnp;
6652
+				}
5638 6653
 			}
5639 6654
 		}
5640 6655
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5738,8 +6753,14 @@  discard block
 block discarded – undo
5738 6753
 
5739 6754
 				$attachment = $part->getAllDispositionParameters();
5740 6755
 				$attachment['mimeType'] = $part->getType();
5741
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5742
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6756
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6757
+				{
6758
+					$attachment['filename'] = $part->getName();
6759
+				}
6760
+				if (($cid = $part->getContentId()))
6761
+				{
6762
+					$attachment['cid'] = $cid;
6763
+				}
5743 6764
 				if (empty($attachment['filename']))
5744 6765
 				{
5745 6766
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5751,7 +6772,10 @@  discard block
 block discarded – undo
5751 6772
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5752 6773
 			}
5753 6774
 		}
5754
-		if (!is_array($attachments)) return false;
6775
+		if (!is_array($attachments))
6776
+		{
6777
+			return false;
6778
+		}
5755 6779
 		return $attachments;
5756 6780
 	}
5757 6781
 
@@ -5770,10 +6794,16 @@  discard block
 block discarded – undo
5770 6794
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5771 6795
 	{
5772 6796
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5773
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6797
+		if (!isset($_folder))
6798
+		{
6799
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6800
+		}
5774 6801
 
5775 6802
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5776
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6803
+		if (!(is_object($_uid) || is_array($_uid)))
6804
+		{
6805
+			$_uid = (array)$_uid;
6806
+		}
5777 6807
 		$uidsToFetch->add($_uid);
5778 6808
 
5779 6809
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5782,8 +6812,10 @@  discard block
 block discarded – undo
5782 6812
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5783 6813
 			'ids' => $uidsToFetch,
5784 6814
 		));
5785
-		if (is_object($headersNew)) {
5786
-			foreach($headersNew as $id=>$_headerObject) {
6815
+		if (is_object($headersNew))
6816
+		{
6817
+			foreach($headersNew as $id=>$_headerObject)
6818
+			{
5787 6819
 				$body = $_headerObject->getFullMsg();
5788 6820
 				if ($_partID != '')
5789 6821
 				{
@@ -5797,7 +6829,10 @@  discard block
 block discarded – undo
5797 6829
 					}
5798 6830
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5799 6831
 					// itself is only triggered to fetch attachments
5800
-					if (empty($partDisposition)) $partDisposition='attachment';
6832
+					if (empty($partDisposition))
6833
+					{
6834
+						$partDisposition='attachment';
6835
+					}
5801 6836
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5802 6837
 					{
5803 6838
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5806,13 +6841,19 @@  discard block
 block discarded – undo
5806 6841
 						$charset = $part->getContentTypeParameter('charset');
5807 6842
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5808 6843
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5809
-						if ($_returnPart) return $part;
6844
+						if ($_returnPart)
6845
+						{
6846
+							return $part;
6847
+						}
5810 6848
 					}
5811 6849
 				}
5812 6850
 			}
5813 6851
 		}
5814 6852
 		$ext = MimeMagic::mime2ext($structure_mime);
5815
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6853
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6854
+		{
6855
+			$filename = trim($filename).'.'.$ext;
6856
+		}
5816 6857
 		if (!$part)
5817 6858
 		{
5818 6859
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5828,7 +6869,10 @@  discard block
 block discarded – undo
5828 6869
 		);
5829 6870
 
5830 6871
 		// try guessing the mimetype, if we get the application/octet-stream
5831
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6872
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6873
+		{
6874
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6875
+		}
5832 6876
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5833 6877
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5834 6878
 		{
@@ -5851,9 +6895,18 @@  discard block
 block discarded – undo
5851 6895
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5852 6896
 					{
5853 6897
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5854
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5855
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5856
-						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']);
6898
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6899
+						{
6900
+							$attachment['filename'] = $part->getName();
6901
+						}
6902
+						if (($cid = $part->getContentId()))
6903
+						{
6904
+							$attachment['cid'] = $cid;
6905
+						}
6906
+						if (empty($attachment['filename']))
6907
+						{
6908
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6909
+						}
5857 6910
 						$wmattach = $attachment;
5858 6911
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5859 6912
 
@@ -5863,7 +6916,10 @@  discard block
 block discarded – undo
5863 6916
 			if ($tnefResolved)
5864 6917
 			{
5865 6918
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5866
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6919
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6920
+				{
6921
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6922
+				}
5867 6923
 				$attachmentData = array(
5868 6924
 					'type'       => $wmattach['mimeType'],
5869 6925
 					'filename'   => $wmattach['filename'],
@@ -5893,7 +6949,10 @@  discard block
 block discarded – undo
5893 6949
 		static $uid=null, $part=null, $structure=null;
5894 6950
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5895 6951
 
5896
-		if(empty($_cid)) return false;
6952
+		if(empty($_cid))
6953
+		{
6954
+			return false;
6955
+		}
5897 6956
 
5898 6957
 		if ($_uid != $uid || $_part != $part)
5899 6958
 		{
@@ -5918,13 +6977,19 @@  discard block
 block discarded – undo
5918 6977
 					$attachment = $part;
5919 6978
 				}
5920 6979
 				// everything else we only consider after we checked all
5921
-				if (!isset($attachment)) $attachment = $part;
6980
+				if (!isset($attachment))
6981
+				{
6982
+					$attachment = $part;
6983
+				}
5922 6984
 				// do we want content fetched, can be done later, if not needed
5923 6985
 				if (isset($_stream))
5924 6986
 				{
5925 6987
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5926 6988
 				}
5927
-				if (isset($attachment)) break;
6989
+				if (isset($attachment))
6990
+				{
6991
+					break;
6992
+				}
5928 6993
 			}
5929 6994
 		}
5930 6995
 		// set name as filename, if not set
@@ -5955,10 +7020,17 @@  discard block
 block discarded – undo
5955 7020
 	 */
5956 7021
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5957 7022
 	{
5958
-		if (is_null($part)) return null;//new Horde_Mime_Part;
7023
+		if (is_null($part))
7024
+		{
7025
+			return null;
7026
+		}
7027
+		//new Horde_Mime_Part;
5959 7028
 		$encoding = null;
5960 7029
 		$fetchAsBinary = true;
5961
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
7030
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
7031
+		{
7032
+			$fetchAsBinary = false;
7033
+		}
5962 7034
 		// we need to set content on structure to decode transfer encoding
5963 7035
 		$part->setContents(
5964 7036
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5995,7 +7067,10 @@  discard block
 block discarded – undo
5995 7067
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5996 7068
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5997 7069
 		// for flags at all)
5998
-		if (empty($_flags)) $_flags = '\\Recent';
7070
+		if (empty($_flags))
7071
+		{
7072
+			$_flags = '\\Recent';
7073
+		}
5999 7074
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
6000 7075
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
6001 7076
 		try
@@ -6012,18 +7087,27 @@  discard block
 block discarded – undo
6012 7087
 		}
6013 7088
 		catch (\Exception $e)
6014 7089
 		{
6015
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7090
+			if (self::$debug)
7091
+			{
7092
+				error_log("Could not append Message: ".$e->getMessage());
7093
+			}
6016 7094
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
6017 7095
 			//return false;
6018 7096
 		}
6019 7097
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
6020 7098
 		//$messageid = true; // for debug reasons only
6021
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7099
+		if ($messageid === true || empty($messageid))
7100
+		{
7101
+			// try to figure out the message uid
6022 7102
 		{
6023 7103
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7104
+		}
6024 7105
 			if ($list)
6025 7106
 			{
6026
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7107
+				if (self::$debug)
7108
+				{
7109
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7110
+				}
6027 7111
 				$messageid = $list['header'][0]['uid'];
6028 7112
 			}
6029 7113
 		}
@@ -6064,7 +7148,10 @@  discard block
 block discarded – undo
6064 7148
 	{
6065 7149
 			//echo __METHOD__." called for $uid,$partid <br>";
6066 7150
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6067
-			if (empty($headers)) return false;
7151
+			if (empty($headers))
7152
+			{
7153
+				return false;
7154
+			}
6068 7155
 			// dont force retrieval of the textpart, let mailClass preferences decide
6069 7156
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6070 7157
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6082,15 +7169,30 @@  discard block
 block discarded – undo
6082 7169
 			//error_log(array2string($bodyParts));
6083 7170
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6084 7171
 
6085
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6086
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6087
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6088
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7172
+			if ($mailClass->isSentFolder($mailbox))
7173
+			{
7174
+				$mailaddress = $headers['TO'];
7175
+			}
7176
+			elseif (isset($headers['FROM']))
7177
+			{
7178
+				$mailaddress = $headers['FROM'];
7179
+			}
7180
+			elseif (isset($headers['SENDER']))
7181
+			{
7182
+				$mailaddress = $headers['SENDER'];
7183
+			}
7184
+			if (isset($headers['CC']))
7185
+			{
7186
+				$mailaddress .= ','.$headers['CC'];
7187
+			}
6089 7188
 			//_debug_array(array($headers,$mailaddress));
6090 7189
 			$subject = $headers['SUBJECT'];
6091 7190
 
6092 7191
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6093
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7192
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7193
+			{
7194
+				$message = '<pre>'.$message.'</pre>';
7195
+			}
6094 7196
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6095 7197
 			$message = $headdata.$message;
6096 7198
 			//echo __METHOD__.'<br>';
@@ -6141,7 +7243,8 @@  discard block
 block discarded – undo
6141 7243
 							$attachments[$num]['attachment'] = $c->getContents();
6142 7244
 						}
6143 7245
 						// no attempt to convert, if we dont know about the charset
6144
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7246
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7247
+						{
6145 7248
 							// we do not try guessing the charset, if it is not set
6146 7249
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6147 7250
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6162,7 +7265,10 @@  discard block
 block discarded – undo
6162 7265
 						unset($attachments[$num]['attachment']);
6163 7266
 					}
6164 7267
 				}
6165
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7268
+				if (is_array($attachedMessages))
7269
+				{
7270
+					$attachments = array_merge($attachments,$attachedMessages);
7271
+				}
6166 7272
 			}
6167 7273
 			return array(
6168 7274
 					'mailaddress'=>$mailaddress,
@@ -6184,10 +7290,17 @@  discard block
 block discarded – undo
6184 7290
 	{
6185 7291
 		$c = 0;
6186 7292
 		// use the standardIdentity
6187
-		foreach($_identities as $key => $acc) {
6188
-			if ($c==0) $identity = $acc;
7293
+		foreach($_identities as $key => $acc)
7294
+		{
7295
+			if ($c==0)
7296
+			{
7297
+				$identity = $acc;
7298
+			}
6189 7299
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6190
-			if ($key==$_profile_id) $identity = $acc;
7300
+			if ($key==$_profile_id)
7301
+			{
7302
+				$identity = $acc;
7303
+			}
6191 7304
 			$c++;
6192 7305
 		}
6193 7306
 		return $identity;
@@ -6203,20 +7316,53 @@  discard block
 block discarded – undo
6203 7316
 	{
6204 7317
 		$headdata = null;
6205 7318
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6206
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6207
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6208
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6209
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6210
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6211
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6212
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6213
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6214
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7319
+		if ($header['SUBJECT'])
7320
+		{
7321
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7322
+		}
7323
+		if ($header['FROM'])
7324
+		{
7325
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7326
+		}
7327
+		if ($header['SENDER'])
7328
+		{
7329
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7330
+		}
7331
+		if ($header['TO'])
7332
+		{
7333
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7334
+		}
7335
+		if ($header['CC'])
7336
+		{
7337
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7338
+		}
7339
+		if ($header['BCC'])
7340
+		{
7341
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7342
+		}
7343
+		if ($header['DATE'])
7344
+		{
7345
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7346
+		}
7347
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7348
+		{
7349
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7350
+		}
7351
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7352
+		{
7353
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7354
+		}
6215 7355
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6216 7356
 		if (!empty($headdata))
6217 7357
 		{
6218
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6219
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7358
+			if (!empty($headline) && $headline != 'SUPPRESS')
7359
+			{
7360
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7361
+			}
7362
+			if (empty($headline))
7363
+			{
7364
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7365
+			}
6220 7366
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6221 7367
 		}
6222 7368
 		else
@@ -6250,12 +7396,15 @@  discard block
 block discarded – undo
6250 7396
 		$returnAddr ='';
6251 7397
 		if (is_array($rfcAddressArray))
6252 7398
 		{
6253
-			foreach((array)$rfcAddressArray as $addressData) {
7399
+			foreach((array)$rfcAddressArray as $addressData)
7400
+			{
6254 7401
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6255
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7402
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7403
+				{
6256 7404
 					continue;
6257 7405
 				}
6258
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7406
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7407
+				{
6259 7408
 					continue;
6260 7409
 				}
6261 7410
 				if ($addressData['RFC822_EMAIL'])
@@ -6269,7 +7418,10 @@  discard block
 block discarded – undo
6269 7418
 				}
6270 7419
 				$addressObject = $addressObjectA[0];
6271 7420
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6272
-				if (!$addressObject->valid) continue;
7421
+				if (!$addressObject->valid)
7422
+				{
7423
+					continue;
7424
+				}
6273 7425
 				//$mb =(string)$addressObject->mailbox;
6274 7426
 				//$h = (string)$addressObject->host;
6275 7427
 				//$p = (string)$addressObject->personal;
@@ -6286,7 +7438,10 @@  discard block
 block discarded – undo
6286 7438
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6287 7439
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6288 7440
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6289
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7441
+			if (is_string($rfcAddressArray))
7442
+			{
7443
+				return $rfcAddressArray;
7444
+			}
6290 7445
 		}
6291 7446
 		return $returnAddr;
6292 7447
 	}
@@ -6303,10 +7458,19 @@  discard block
 block discarded – undo
6303 7458
 	{
6304 7459
 		$mergeobj = new Contacts\Merge();
6305 7460
 
6306
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7461
+		if (empty($mimetype))
7462
+		{
7463
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7464
+		}
6307 7465
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6308
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6309
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7466
+		if (empty($rv) && !empty($content) && !empty($err))
7467
+		{
7468
+			$rv = $content;
7469
+		}
7470
+		if (!empty($err) && !empty($content) && !empty($ids))
7471
+		{
7472
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7473
+		}
6310 7474
 		return $rv;
6311 7475
 	}
6312 7476
 
@@ -6343,13 +7507,15 @@  discard block
 block discarded – undo
6343 7507
 			settype($bytes, 'integer');
6344 7508
 			$bytes /= 10;
6345 7509
 		}
6346
-		else
6347
-			settype($bytes, 'integer');
7510
+		else {
7511
+					settype($bytes, 'integer');
7512
+		}
6348 7513
 
6349 7514
 		return $bytes . ' ' . $type ;
6350 7515
 	}
6351 7516
 
6352
-	static function detect_qp(&$sting) {
7517
+	static function detect_qp(&$sting)
7518
+	{
6353 7519
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6354 7520
 		return preg_match("$needle",$string);
6355 7521
 	}
@@ -6366,9 +7532,15 @@  discard block
 block discarded – undo
6366 7532
 	 */
6367 7533
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6368 7534
 	{
6369
-		if (is_null($_endtime)) $_endtime = microtime(true);
7535
+		if (is_null($_endtime))
7536
+		{
7537
+			$_endtime = microtime(true);
7538
+		}
6370 7539
 		$usagetime = microtime(true) - $_starttime;
6371
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7540
+		if (self::$debugTimes)
7541
+		{
7542
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7543
+		}
6372 7544
 	}
6373 7545
 
6374 7546
 	/**
@@ -6383,7 +7555,10 @@  discard block
 block discarded – undo
6383 7555
 	 */
6384 7556
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6385 7557
 	{
6386
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7558
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7559
+		{
7560
+			return $_formData['file'];
7561
+		}
6387 7562
 
6388 7563
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6389 7564
 		$importfailed = $tmpFileName = false;
@@ -6432,8 +7607,15 @@  discard block
 block discarded – undo
6432 7607
 			{
6433 7608
 				$buff = explode('.',$_formData['name']);
6434 7609
 				$suffix = '';
6435
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6436
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7610
+				if (is_array($buff))
7611
+				{
7612
+					$suffix = array_pop($buff);
7613
+				}
7614
+				// take the last extension to check with ext2mime
7615
+				if (!empty($suffix))
7616
+				{
7617
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7618
+				}
6437 7619
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6438 7620
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6439 7621
 				{
@@ -6481,7 +7663,9 @@  discard block
 block discarded – undo
6481 7663
 			{
6482 7664
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6483 7665
 			}
6484
-		} else {
7666
+		}
7667
+		else
7668
+		{
6485 7669
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6486 7670
 			$importfailed = true;
6487 7671
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6527,21 +7711,32 @@  discard block
 block discarded – undo
6527 7711
 				if (substr($url, 0, 5) !== 'data:')
6528 7712
 				{
6529 7713
 					$filename = basename($url);
6530
-					if (($directory = dirname($url)) == '.') $directory = '';
7714
+					if (($directory = dirname($url)) == '.')
7715
+					{
7716
+						$directory = '';
7717
+					}
6531 7718
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6532 7719
 					$mimeType  = MimeMagic::ext2mime($ext);
6533
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7720
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7721
+					{
7722
+$directory .= '/'; }
6534 7723
 					$myUrl = $directory.$filename;
6535
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7724
+					if ($myUrl[0]=='/')
7725
+					{
7726
+						// local path -> we only allow path's that are available via http/https (or vfs)
6536 7727
 					{
6537 7728
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6538 7729
 					}
7730
+					}
6539 7731
 					// use vfs instead of url containing webdav.php
6540 7732
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6541 7733
 					// webdav.php urls as vfs
6542
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7734
+					if (strpos($myUrl,'/webdav.php') !== false)
7735
+					{
7736
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6543 7737
 					{
6544 7738
 						Vfs::load_wrapper('vfs');
7739
+					}
6545 7740
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6546 7741
 						$basedir = 'vfs://default';
6547 7742
 						$needTempFile = false;
@@ -6570,8 +7765,13 @@  discard block
 block discarded – undo
6570 7765
 						}
6571 7766
 					}
6572 7767
 
6573
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6574
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7768
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7769
+					{
7770
+$basedir .= '/'; }
7771
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7772
+					{
7773
+						$data = file_get_contents($basedir.urldecode($myUrl));
7774
+					}
6575 7775
 				}
6576 7776
 				if (substr($url,0,strlen('data:'))=='data:')
6577 7777
 				{
@@ -6672,7 +7872,10 @@  discard block
 block discarded – undo
6672 7872
 				$_folder = $this->getSentFolder();
6673 7873
 			}
6674 7874
 			$delimiter = $this->getHierarchyDelimiter();
6675
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7875
+			if($_folder=='INBOX'.$delimiter)
7876
+			{
7877
+				$_folder='INBOX';
7878
+			}
6676 7879
 			if ($importfailed === false)
6677 7880
 			{
6678 7881
 				$Subject = $mailObject->getHeader('Subject');
@@ -6701,7 +7904,9 @@  discard block
 block discarded – undo
6701 7904
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6702 7905
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6703 7906
 						count($SendAndMergeTocontacts) > 1 && $val &&
6704
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7907
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7908
+					{
7909
+						// do the merge
6705 7910
 					{
6706 7911
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6707 7912
 
@@ -6710,6 +7915,7 @@  discard block
 block discarded – undo
6710 7915
 						{
6711 7916
 							//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));
6712 7917
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7918
+					}
6713 7919
 							$mailObject->addAddress($merged,'',$type);
6714 7920
 							if($type == 'to')
6715 7921
 							{
@@ -6741,9 +7947,15 @@  discard block
 block discarded – undo
6741 7947
 						$mailObject->clearCustomHeaders();
6742 7948
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6743 7949
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6744
-						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));
7950
+						if($text_body)
7951
+						{
7952
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7953
+						}
6745 7954
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6746
-						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));
7955
+						if($html_body)
7956
+						{
7957
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7958
+						}
6747 7959
 
6748 7960
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6749 7961
 						// set a higher timeout for big messages
@@ -6758,9 +7970,12 @@  discard block
 block discarded – undo
6758 7970
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6759 7971
 						}
6760 7972
 					}
6761
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7973
+					elseif (!$k)
7974
+					{
7975
+						// 1. entry, further entries will fail for apps other then addressbook
6762 7976
 					{
6763 7977
 						$openAsDraft = true;
7978
+					}
6764 7979
 						$mailObject->removeHeader('Message-ID');
6765 7980
 						$mailObject->removeHeader('Date');
6766 7981
 						$mailObject->clearCustomHeaders();
@@ -6775,9 +7990,12 @@  discard block
 block discarded – undo
6775 7990
 
6776 7991
 						// No addresses from placeholders?  Treat it as just a contact ID
6777 7992
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6778
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7993
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7994
+						{
7995
+							// do the merge
6779 7996
 						{
6780 7997
 							$contact = $bo_merge->contacts->read($val);
7998
+						}
6781 7999
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6782 8000
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6783 8001
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6788,9 +8006,15 @@  discard block
 block discarded – undo
6788 8006
 						}
6789 8007
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6790 8008
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6791
-						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));
8009
+						if (!empty($Body))
8010
+						{
8011
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8012
+						}
6792 8013
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6793
-						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));
8014
+						if (!empty($AltBody))
8015
+						{
8016
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8017
+						}
6794 8018
 						$_folder = $this->getDraftFolder();
6795 8019
 					}
6796 8020
 					if ($sendOK || $openAsDraft)
@@ -6798,11 +8022,15 @@  discard block
 block discarded – undo
6798 8022
 						if ($this->folderExists($_folder,true))
6799 8023
 						{
6800 8024
 						    if($this->isSentFolder($_folder))
6801
-							{
8025
+						    {
6802 8026
 						        $flags = '\\Seen';
6803
-						    } elseif($this->isDraftFolder($_folder)) {
8027
+						    }
8028
+						    elseif($this->isDraftFolder($_folder))
8029
+						    {
6804 8030
 						        $flags = '\\Draft';
6805
-						    } else {
8031
+						    }
8032
+						    else
8033
+						    {
6806 8034
 						        $flags = '';
6807 8035
 						    }
6808 8036
 							$savefailed = false;
@@ -6836,7 +8064,10 @@  discard block
 block discarded – undo
6836 8064
 						}
6837 8065
 						else
6838 8066
 						{
6839
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8067
+							if (!$openComposeWindow)
8068
+							{
8069
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8070
+							}
6840 8071
 						}
6841 8072
 					}
6842 8073
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6884,7 +8115,10 @@  discard block
 block discarded – undo
6884 8115
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6885 8116
 				break;
6886 8117
 		}
6887
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8118
+		if (!isset($message))
8119
+		{
8120
+			$message = fopen($tmpFileName, 'r');
8121
+		}
6888 8122
 
6889 8123
 		if (!$message)
6890 8124
 		{
@@ -6915,7 +8149,10 @@  discard block
 block discarded – undo
6915 8149
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6916 8150
 
6917 8151
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6918
-			if ($length===false) $length = strlen($start);
8152
+			if ($length===false)
8153
+			{
8154
+				$length = strlen($start);
8155
+			}
6919 8156
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6920 8157
 
6921 8158
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6944,7 +8181,10 @@  discard block
 block discarded – undo
6944 8181
 		}
6945 8182
 		else
6946 8183
 		{
6947
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8184
+			if (($type = gettype($message)) == 'object')
8185
+			{
8186
+				$type = get_class ($message);
8187
+			}
6948 8188
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6949 8189
 		}
6950 8190
 	}
@@ -6968,7 +8208,9 @@  discard block
 block discarded – undo
6968 8208
 			$matches = array();
6969 8209
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6970 8210
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6971
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8211
+			foreach ($matches[0] as &$match)
8212
+			{
8213
+$match = trim($match,', ');}
6972 8214
 			$addresses = implode(',',$matches[0]);
6973 8215
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6974 8216
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6999,7 +8241,10 @@  discard block
 block discarded – undo
6999 8241
 			}
7000 8242
 			else
7001 8243
 			{
7002
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8244
+				if ($previousFailed && $remember)
8245
+				{
8246
+					$adr->personal = $remember. ' ' . $adr->personal;
8247
+				}
7003 8248
 				$remember = '';
7004 8249
 				$previousFailed=false;
7005 8250
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -7021,7 +8266,10 @@  discard block
 block discarded – undo
7021 8266
 	{
7022 8267
 		$acc = Mail\Account::read($this->profileID);
7023 8268
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
7024
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8269
+		if (self::$debug)
8270
+		{
8271
+			error_log(__METHOD__.__LINE__.array2string($identity));
8272
+		}
7025 8273
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
7026 8274
 
7027 8275
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.
mail/inc/class.mail_ui.inc.php 2 patches
Spacing   +827 added lines, -834 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @var array
42 42
 	 */
43
-	var $public_functions = array
44
-	(
43
+	var $public_functions = array(
45 44
 		'index' => True,
46 45
 		'displayHeader'	=> True,
47 46
 		'displayMessage'	=> True,
@@ -92,17 +91,17 @@  discard block
 block discarded – undo
92 91
 	 * @var array
93 92
 	 */
94 93
 	var $searchTypes = array(
95
-		'quick'		=> 'quicksearch',	// lang('quicksearch')
96
-		'quickwithcc'=> 'quicksearch (with cc)',	// lang('quicksearch (with cc)')
97
-		'subject'	=> 'subject',		// lang('subject')
98
-		'body'		=> 'message body',	// lang('message body')
99
-		'from'		=> 'from',			// lang('from')
100
-		'to'		=> 'to',			// lang('to')
101
-		'cc'		=> 'cc',			// lang('cc')
102
-		'text'		=> 'whole message',	// lang('whole message')
103
-		'larger'		=> 'greater than',	// lang('greater than')
104
-		'smaller'		=> 'less than',	// lang('less than')
105
-		'bydate' 	=> 'Selected date range (with quicksearch)',// lang('Selected date range (with quicksearch)')
94
+		'quick'		=> 'quicksearch', // lang('quicksearch')
95
+		'quickwithcc'=> 'quicksearch (with cc)', // lang('quicksearch (with cc)')
96
+		'subject'	=> 'subject', // lang('subject')
97
+		'body'		=> 'message body', // lang('message body')
98
+		'from'		=> 'from', // lang('from')
99
+		'to'		=> 'to', // lang('to')
100
+		'cc'		=> 'cc', // lang('cc')
101
+		'text'		=> 'whole message', // lang('whole message')
102
+		'larger'		=> 'greater than', // lang('greater than')
103
+		'smaller'		=> 'less than', // lang('less than')
104
+		'bydate' 	=> 'Selected date range (with quicksearch)', // lang('Selected date range (with quicksearch)')
106 105
 	);
107 106
 
108 107
 	/**
@@ -111,12 +110,12 @@  discard block
 block discarded – undo
111 110
 	 * @var array
112 111
 	 */
113 112
 	var $statusTypes = array(
114
-		'any'		=> 'any status',// lang('any status')
115
-		'flagged'	=> 'flagged',	// lang('flagged')
116
-		'unseen'	=> 'unread',	// lang('unread')
117
-		'answered'	=> 'replied',	// lang('replied')
118
-		'seen'		=> 'read',		// lang('read')
119
-		'deleted'	=> 'deleted',	// lang('deleted')
113
+		'any'		=> 'any status', // lang('any status')
114
+		'flagged'	=> 'flagged', // lang('flagged')
115
+		'unseen'	=> 'unread', // lang('unread')
116
+		'answered'	=> 'replied', // lang('replied')
117
+		'seen'		=> 'read', // lang('read')
118
+		'deleted'	=> 'deleted', // lang('deleted')
120 119
 	);
121 120
 
122 121
 	/**
@@ -124,12 +123,12 @@  discard block
 block discarded – undo
124 123
 	 *
125 124
 	 * @param boolean $run_constructor =true false: no not run constructor and therefore do NOT connect to imap server
126 125
 	 */
127
-	function __construct($run_constructor=true)
126
+	function __construct($run_constructor = true)
128 127
 	{
129 128
 		$this->mail_tree = new mail_tree($this);
130 129
 		if (!$run_constructor) return;
131 130
 
132
-		if (Mail::$debugTimes) $starttime = microtime (true);
131
+		if (Mail::$debugTimes) $starttime = microtime(true);
133 132
 		// no autohide of the sidebox, as we use it for folderlist now.
134 133
 		unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
135 134
 
@@ -145,13 +144,13 @@  discard block
 block discarded – undo
145 144
 		}
146 145
 
147 146
 		try {
148
-			$this->mail_bo = Mail::getInstance(true,self::$icServerID, true, false, true);
147
+			$this->mail_bo = Mail::getInstance(true, self::$icServerID, true, false, true);
149 148
 			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
150 149
 			//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer));
151 150
 
152 151
 			// RegEx to minimize extra openConnection
153 152
 			$needle = '/^(?!mail)/';
154
-			if (!preg_match($needle,$_GET['menuaction']) && !Api\Json\Request::isJSONRequest())
153
+			if (!preg_match($needle, $_GET['menuaction']) && !Api\Json\Request::isJSONRequest())
155 154
 			{
156 155
 				//error_log(__METHOD__.__LINE__.' Fetched IC Server openConnection:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
157 156
 				//openConnection gathers SpecialUseFolderInformation and Delimiter Info
@@ -164,12 +163,12 @@  discard block
 block discarded – undo
164 163
 			if (Api\Json\Request::isJSONRequest() && $_GET['menuaction'] != 'mail.mail_ui.index')
165 164
 			{
166 165
 				$response = Api\Json\Response::get();
167
-				$response->call('egw.message',$e->getMessage(),'error');
166
+				$response->call('egw.message', $e->getMessage(), 'error');
168 167
 			}
169 168
 			// redirect to mail wizard to handle it (redirect works for ajax too), unless index is called. we want the sidebox
170
-			if ($_GET['menuaction'] != 'mail.mail_ui.index') self::callWizard($e->getMessage(),true,'error',false);
169
+			if ($_GET['menuaction'] != 'mail.mail_ui.index') self::callWizard($e->getMessage(), true, 'error', false);
171 170
 		}
172
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
171
+		if (Mail::$debugTimes) Mail::logRunTimes($starttime, null, '', __METHOD__.__LINE__);
173 172
 	}
174 173
 
175 174
 	/**
@@ -179,10 +178,10 @@  discard block
 block discarded – undo
179 178
 	 * @param boolean $exit If true, will call exit() after opening the wizardpopup
180 179
 	 * @param string $msg_type = 'success' message type
181 180
 	 */
182
-	static function callWizard($message, $exit=true, $msg_type='success',$reset_sidebox_on_index=true)
181
+	static function callWizard($message, $exit = true, $msg_type = 'success', $reset_sidebox_on_index = true)
183 182
 	{
184 183
 		//error_log(__METHOD__."('$message', $exit) ".function_backtrace());
185
-		$linkData=(self::$icServerID ? array(
184
+		$linkData = (self::$icServerID ? array(
186 185
 				'menuaction' => 'mail.mail_wizard.edit',
187 186
 				'acc_id' => self::$icServerID,
188 187
 			) : array(
@@ -196,11 +195,11 @@  discard block
 block discarded – undo
196 195
 		{
197 196
 			$response = Api\Json\Response::get();
198 197
 			$windowName = "editMailAccount".self::$icServerID;
199
-			$response->call("egw.open_link", Egw::link('/index.php', $linkData), $windowName, "600x480",null,true);
198
+			$response->call("egw.open_link", Egw::link('/index.php', $linkData), $windowName, "600x480", null, true);
200 199
 			Framework::message($message, 'error');
201 200
 			if ($_GET['menuaction'] == 'mail.mail_ui.index' && $reset_sidebox_on_index)
202 201
 			{
203
-				$response->call('framework.setSidebox','mail',array(),'md5');
202
+				$response->call('framework.setSidebox', 'mail', array(), 'md5');
204 203
 			}
205 204
 			if ($exit)
206 205
 			{
@@ -210,8 +209,8 @@  discard block
 block discarded – undo
210 209
 		else	// regular GET request eg. in idots template
211 210
 		{
212 211
 			$windowName = "editMailAccount".self::$icServerID;
213
-			Framework::popup(Framework::link('/index.php',$linkData),$windowName);
214
-			$GLOBALS['egw']->framework->render($message,'',true);
212
+			Framework::popup(Framework::link('/index.php', $linkData), $windowName);
213
+			$GLOBALS['egw']->framework->render($message, '', true);
215 214
 			if ($exit)
216 215
 			{
217 216
 				exit();
@@ -227,9 +226,9 @@  discard block
 block discarded – undo
227 226
 	 *
228 227
 	 * @throws Api\Exception
229 228
 	 */
230
-	function changeProfile($_icServerID,$unsetCache=false)
229
+	function changeProfile($_icServerID, $unsetCache = false)
231 230
 	{
232
-		if (Mail::$debugTimes) $starttime = microtime (true);
231
+		if (Mail::$debugTimes) $starttime = microtime(true);
233 232
 		if (self::$icServerID != $_icServerID)
234 233
 		{
235 234
 			self::$icServerID = $_icServerID;
@@ -237,35 +236,35 @@  discard block
 block discarded – undo
237 236
 		if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.self::$icServerID.'<->'.$_icServerID);
238 237
 
239 238
 		if ($unsetCache) Mail::unsetCachedObjects(self::$icServerID);
240
-		$this->mail_bo = Mail::getInstance(false,self::$icServerID,true, false, true);
239
+		$this->mail_bo = Mail::getInstance(false, self::$icServerID, true, false, true);
241 240
 		if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
242 241
 		// no icServer Object: something failed big time
243
-		if (!isset($this->mail_bo->icServer) || $this->mail_bo->icServer->ImapServerId<>$_icServerID)
242
+		if (!isset($this->mail_bo->icServer) || $this->mail_bo->icServer->ImapServerId <> $_icServerID)
244 243
 		{
245 244
 			self::$icServerID = $_icServerID;
246 245
 			throw new Api\Exception('Profile change failed!');
247 246
 		}
248 247
 
249 248
 		// save session varchar
250
-		$oldicServerID =& Api\Cache::getSession('mail','activeProfileID');
249
+		$oldicServerID = & Api\Cache::getSession('mail', 'activeProfileID');
251 250
 		if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID);
252 251
 		if (true) $oldicServerID = self::$icServerID;
253
-		if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true ))
252
+		if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true))
254 253
 		{
255 254
 			throw new Api\Exception(__METHOD__." failed to change Profile to $_icServerID");
256 255
 		}
257 256
 
258
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
257
+		if (Mail::$debugTimes) Mail::logRunTimes($starttime, null, '', __METHOD__.__LINE__);
259 258
 	}
260 259
 
261 260
 	/**
262 261
 	 * Ajax function to request next branch of a tree branch
263 262
 	 */
264
-	static function ajax_tree_autoloading ($_id = null)
263
+	static function ajax_tree_autoloading($_id = null)
265 264
 	{
266 265
 		$mail_ui = new mail_ui();
267 266
 		$id = $_id ? $_id : $_GET['id'];
268
-		Etemplate\Widget\Tree::send_quote_json($mail_ui->mail_tree->getTree($id,'',1,false));
267
+		Etemplate\Widget\Tree::send_quote_json($mail_ui->mail_tree->getTree($id, '', 1, false));
269 268
 	}
270 269
 
271 270
 	/**
@@ -274,11 +273,11 @@  discard block
 block discarded – undo
274 273
 	 * @param array $content
275 274
 	 * @param type $msg
276 275
 	 */
277
-	function subscription(array $content=null ,$msg=null)
276
+	function subscription(array $content = null, $msg = null)
278 277
 	{
279 278
 		$stmpl = new Etemplate('mail.subscribe');
280 279
 
281
-		if(is_array($content))
280
+		if (is_array($content))
282 281
 		{
283 282
 			$profileId = $content['profileId'];
284 283
 		}
@@ -288,14 +287,14 @@  discard block
 block discarded – undo
288 287
 		}
289 288
 		// Initial tree's options, the rest would be loaded dynamicaly by autoloading,
290 289
 		// triggered from client-side. Also, we keep this here as
291
-		$sel_options['foldertree'] =  $this->mail_tree->getTree(null,$profileId,1,true,false,true);
290
+		$sel_options['foldertree'] = $this->mail_tree->getTree(null, $profileId, 1, true, false, true);
292 291
 
293 292
 		//Get all subscribed folders
294 293
 		// as getting all subscribed folders is very fast operation
295 294
 		// we can use it to get a comparison base for folders which
296 295
 		// got subscribed or unsubscribed by the user
297 296
 		try {
298
-			$subscribed = $this->mail_bo->icServer->listSubscribedMailboxes('',0,true);
297
+			$subscribed = $this->mail_bo->icServer->listSubscribedMailboxes('', 0, true);
299 298
 		} catch (Exception $ex) {
300 299
 			Framework::message($ex->getMessage());
301 300
 		}
@@ -306,7 +305,7 @@  discard block
 block discarded – undo
306 305
 
307 306
 			foreach ($subscribed as $folder)
308 307
 			{
309
-				$folderName = $profileId . self::$delimiter . $folder['MAILBOX'];
308
+				$folderName = $profileId.self::$delimiter.$folder['MAILBOX'];
310 309
 				array_push($content['foldertree'], $folderName);
311 310
 			}
312 311
 		}
@@ -320,9 +319,9 @@  discard block
 block discarded – undo
320 319
 				{
321 320
 					// do not let user (un)subscribe namespace roots eg. "other", "user" or "INBOX", same for tree-root/account itself
322 321
 					$namespace_roots = array($profileId);
323
-					foreach($this->mail_bo->_getNameSpaces() as $namespace)
322
+					foreach ($this->mail_bo->_getNameSpaces() as $namespace)
324 323
 					{
325
-						$namespace_roots[] = $profileId . self::$delimiter . str_replace($namespace['delimiter'], '', $namespace['prefix']);
324
+						$namespace_roots[] = $profileId.self::$delimiter.str_replace($namespace['delimiter'], '', $namespace['prefix']);
326 325
 					}
327 326
 					$to_unsubscribe = $to_subscribe = array();
328 327
 					foreach ($content['foldertree'] as $path => $value)
@@ -330,7 +329,7 @@  discard block
 block discarded – undo
330 329
 						list(,$node) = explode($profileId.self::$delimiter, $path);
331 330
 						if ($node)
332 331
 						{
333
-							if (is_array($subscribed) && $subscribed[$node] && !$value['value']) $to_unsubscribe []= $node;
332
+							if (is_array($subscribed) && $subscribed[$node] && !$value['value']) $to_unsubscribe [] = $node;
334 333
 							if (is_array($subscribed) && !$subscribed[$node] && $value['value']) $to_subscribe [] = $node;
335 334
 							if ($value['value']) $cont[] = $path;
336 335
 						}
@@ -340,7 +339,7 @@  discard block
 block discarded – undo
340 339
 					// set foldertree options to basic node in order to avoid initial autoloading
341 340
 					// from client side, as no options would trigger that.
342 341
 					$sel_options['foldertree'] = array('id' => '0', 'item'=> array());
343
-					foreach(array_merge($to_subscribe, $to_unsubscribe) as $mailbox)
342
+					foreach (array_merge($to_subscribe, $to_unsubscribe) as $mailbox)
344 343
 					{
345 344
 						if (in_array($profileId.self::$delimiter.$mailbox, $namespace_roots, true))
346 345
 						{
@@ -376,18 +375,18 @@  discard block
 block discarded – undo
376 375
 						}
377 376
 					}
378 377
 					// update foldertree in main window
379
-					$parentFolder='INBOX';
378
+					$parentFolder = 'INBOX';
380 379
 					$refreshData = array(
381 380
 						$profileId => lang($parentFolder),
382 381
 					);
383 382
 					$response = Api\Json\Response::get();
384
-					foreach($refreshData as $folder => &$name)
383
+					foreach ($refreshData as $folder => &$name)
385 384
 					{
386
-						$name = $this->mail_tree->getTree($folder, $profileId,1,true,true,true);
385
+						$name = $this->mail_tree->getTree($folder, $profileId, 1, true, true, true);
387 386
 					}
388 387
 					// give success/error message to opener and popup itself
389 388
 					//$response->call('opener.app.mail.subscription_refresh',$refreshData);
390
-					$response->call('opener.app.mail.mail_reloadNode',$refreshData);
389
+					$response->call('opener.app.mail.mail_reloadNode', $refreshData);
391 390
 
392 391
 					Framework::refresh_opener($msg, 'mail', null, null, null, null, null, $msg_type);
393 392
 					if ($button == 'apply')
@@ -407,7 +406,7 @@  discard block
 block discarded – undo
407 406
 
408 407
 		$readonlys = array();
409 408
 
410
-		$stmpl->exec('mail.mail_ui.subscription', $content,$sel_options,$readonlys,$preserv,2);
409
+		$stmpl->exec('mail.mail_ui.subscription', $content, $sel_options, $readonlys, $preserv, 2);
411 410
 	}
412 411
 
413 412
 	/**
@@ -416,12 +415,12 @@  discard block
 block discarded – undo
416 415
 	 * @param array $content
417 416
 	 * @param string $msg
418 417
 	 */
419
-	function index(array $content=null,$msg=null)
418
+	function index(array $content = null, $msg = null)
420 419
 	{
421 420
 		//error_log(__METHOD__.__LINE__.array2string($content));
422
-		try	{
421
+		try {
423 422
 				//error_log(__METHOD__.__LINE__.function_backtrace());
424
-				if (Mail::$debugTimes) $starttime = microtime (true);
423
+				if (Mail::$debugTimes) $starttime = microtime(true);
425 424
 				$this->mail_bo->restoreSessionData();
426 425
 				$sessionFolder = $this->mail_bo->sessionData['mailbox'];
427 426
 				if ($this->mail_bo->folderExists($sessionFolder))
@@ -442,26 +441,26 @@  discard block
 block discarded – undo
442 441
 					{
443 442
 						// These only set on first load
444 443
 						$content[self::$nm_index] = array(
445
-							'filter'         => 'any',	// filter is used to choose the mailbox
446
-							'lettersearch'   => false,	// I  show a lettersearch
447
-							'searchletter'   =>	false,	// I0 active letter of the lettersearch or false for [all]
448
-							'start'          =>	0,		// IO position in list
449
-							'order'          =>	'date',	// IO name of the column to sort after (optional for the sortheaders)
450
-							'sort'           =>	'DESC',	// IO direction of the sort: 'ASC' or 'DESC'
444
+							'filter'         => 'any', // filter is used to choose the mailbox
445
+							'lettersearch'   => false, // I  show a lettersearch
446
+							'searchletter'   =>	false, // I0 active letter of the lettersearch or false for [all]
447
+							'start'          =>	0, // IO position in list
448
+							'order'          =>	'date', // IO name of the column to sort after (optional for the sortheaders)
449
+							'sort'           =>	'DESC', // IO direction of the sort: 'ASC' or 'DESC'
451 450
 						);
452 451
 					}
453 452
 					if (Api\Header\UserAgent::mobile()) $content[self::$nm_index]['header_row'] = 'mail.index.header_right';
454 453
 				}
455 454
 
456 455
 				// These must always be set, even if $content is an array
457
-				$content[self::$nm_index]['cat_is_select'] = true;    // Category select is just a normal selectbox
458
-				$content[self::$nm_index]['no_filter2'] = false;       // Disable second filter
456
+				$content[self::$nm_index]['cat_is_select'] = true; // Category select is just a normal selectbox
457
+				$content[self::$nm_index]['no_filter2'] = false; // Disable second filter
459 458
 				$content[self::$nm_index]['actions'] = self::get_actions();
460
-				$content[self::$nm_index]['row_id'] = 'row_id';	     // is a concatenation of trim($GLOBALS['egw_info']['user']['account_id']):profileID:base64_encode(FOLDERNAME):uid
459
+				$content[self::$nm_index]['row_id'] = 'row_id'; // is a concatenation of trim($GLOBALS['egw_info']['user']['account_id']):profileID:base64_encode(FOLDERNAME):uid
461 460
 				$content[self::$nm_index]['placeholder_actions'] = array('composeasnew');
462 461
 				$content[self::$nm_index]['get_rows'] = 'mail_ui::get_rows';
463
-				$content[self::$nm_index]['num_rows'] = 0;      // Do not send any rows with initial request
464
-				$content[self::$nm_index]['default_cols'] = 'status,attachments,subject,address,date,size';	// I  columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns
462
+				$content[self::$nm_index]['num_rows'] = 0; // Do not send any rows with initial request
463
+				$content[self::$nm_index]['default_cols'] = 'status,attachments,subject,address,date,size'; // I  columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns
465 464
 				$content[self::$nm_index]['csv_fields'] = false;
466 465
 				if ($msg)
467 466
 				{
@@ -473,11 +472,11 @@  discard block
 block discarded – undo
473 472
 					unset($content['msg']);
474 473
 				}
475 474
 				// call getQuotaRoot asynchronously in getRows by initiating a client Server roundtrip
476
-				$quota = false;//$this->mail_bo->getQuotaRoot();
477
-				if($quota !== false && $quota['limit'] != 'NOT SET') {
475
+				$quota = false; //$this->mail_bo->getQuotaRoot();
476
+				if ($quota !== false && $quota['limit'] != 'NOT SET') {
478 477
 					$quotainfo = $this->quotaDisplay($quota['usage'], $quota['limit']);
479 478
 					$content[self::$nm_index]['quota'] = $sel_options[self::$nm_index]['quota'] = $quotainfo['text'];
480
-					$content[self::$nm_index]['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] =  (string)$quotainfo['percent'];
479
+					$content[self::$nm_index]['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] = (string)$quotainfo['percent'];
481 480
 					$content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = $quotainfo['class'];
482 481
 					$content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "";
483 482
 				} else {
@@ -486,43 +485,43 @@  discard block
 block discarded – undo
486 485
 					$content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "mail_DisplayNone";
487 486
 				}
488 487
 				// call gatherVacation asynchronously in getRows by initiating a client Server roundtrip
489
-				$vacation = false;//$this->gatherVacation();
488
+				$vacation = false; //$this->gatherVacation();
490 489
 				//error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation));
491
-				if($vacation) {
492
-					if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date' && $vacation['end_date'] > time()))
490
+				if ($vacation) {
491
+					if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status'] == 'by_date' && $vacation['end_date'] > time()))
493 492
 					{
494 493
 						$dtfrmt = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']/*.' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']!='24'?'h:i a':'H:i')*/;
495 494
 						$content[self::$nm_index]['vacationnotice'] = $sel_options[self::$nm_index]['vacationnotice'] = lang('Vacation notice is active');
496
-						$content[self::$nm_index]['vacationrange'] = $sel_options[self::$nm_index]['vacationrange'] = ($vacation['status']=='by_date'? Api\DateTime::server2user($vacation['start_date'],$dtfrmt,true).($vacation['end_date']>$vacation['start_date']?'->'.Api\DateTime::server2user($vacation['end_date']+ 24*3600-1,$dtfrmt,true):''):'');
495
+						$content[self::$nm_index]['vacationrange'] = $sel_options[self::$nm_index]['vacationrange'] = ($vacation['status'] == 'by_date' ? Api\DateTime::server2user($vacation['start_date'], $dtfrmt, true).($vacation['end_date'] > $vacation['start_date'] ? '->'.Api\DateTime::server2user($vacation['end_date'] + 24 * 3600 - 1, $dtfrmt, true) : '') : '');
497 496
 					}
498 497
 				}
499
-				if ($vacation==false)
498
+				if ($vacation == false)
500 499
 				{
501 500
 					$content[self::$nm_index]['vacationnotice'] = $sel_options[self::$nm_index]['vacationnotice'] = '';
502 501
 					$content[self::$nm_index]['vacationrange'] = $sel_options[self::$nm_index]['vacationrange'] = '';
503 502
 				}
504 503
 				//$zstarttime = microtime (true);
505
-				$sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
504
+				$sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'], !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
506 505
 				//$zendtime = microtime(true) - $zstarttime;
507 506
 				//error_log(__METHOD__.__LINE__. " time used: ".$zendtime);
508
-				$content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.(!empty($this->mail_bo->sessionData['mailbox'])?$this->mail_bo->sessionData['mailbox']:'INBOX');
507
+				$content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.(!empty($this->mail_bo->sessionData['mailbox']) ? $this->mail_bo->sessionData['mailbox'] : 'INBOX');
509 508
 				// since we are connected,(and selected the folder) we check for capabilities SUPPORTS_KEYWORDS to eventually add the keyword filters
510
-				if ( $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
509
+				if ($this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
511 510
 				{
512
-					$this->statusTypes = array_merge($this->statusTypes,array(
513
-						'keyword1'	=> 'important',//lang('important'),
514
-						'keyword2'	=> 'job',	//lang('job'),
515
-						'keyword3'	=> 'personal',//lang('personal'),
516
-						'keyword4'	=> 'to do',	//lang('to do'),
517
-						'keyword5'	=> 'later',	//lang('later'),
511
+					$this->statusTypes = array_merge($this->statusTypes, array(
512
+						'keyword1'	=> 'important', //lang('important'),
513
+						'keyword2'	=> 'job', //lang('job'),
514
+						'keyword3'	=> 'personal', //lang('personal'),
515
+						'keyword4'	=> 'to do', //lang('to do'),
516
+						'keyword5'	=> 'later', //lang('later'),
518 517
 					));
519 518
 				}
520 519
 				else
521 520
 				{
522
-					$keywords = array('keyword1','keyword2','keyword3','keyword4','keyword5');
523
-					foreach($keywords as &$k)
521
+					$keywords = array('keyword1', 'keyword2', 'keyword3', 'keyword4', 'keyword5');
522
+					foreach ($keywords as &$k)
524 523
 					{
525
-						if (array_key_exists($k,$this->statusTypes)) unset($this->statusTypes[$k]);
524
+						if (array_key_exists($k, $this->statusTypes)) unset($this->statusTypes[$k]);
526 525
 					}
527 526
 				}
528 527
 
@@ -533,8 +532,8 @@  discard block
 block discarded – undo
533 532
 
534 533
 				if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
535 534
 				{
536
-					Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
537
-					if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
535
+					Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
536
+					if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID] = true;
538 537
 				}
539 538
 				if (!Mail::$supportsORinQuery[$this->mail_bo->profileID])
540 539
 				{
@@ -546,14 +545,14 @@  discard block
 block discarded – undo
546 545
 				//error_log(__METHOD__.__LINE__.array2string($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']));
547 546
 				$content[self::$nm_index]['cat_id'] = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType'];
548 547
 				$sel_options['filter'] = $this->statusTypes;
549
-				$sel_options['filter2'] = array(''=>lang('No details'),1=>lang('Details'));
548
+				$sel_options['filter2'] = array(''=>lang('No details'), 1=>lang('Details'));
550 549
 				$content[self::$nm_index]['filter2'] = $GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails'];
551 550
 
552 551
 				$etpl = new Etemplate('mail.index');
553 552
 				//apply infolog_filter_change javascript method (hide/show of date filter form) over onchange filter
554 553
 				$content[self::$nm_index]['cat_id_onchange'] = "app.mail.mail_searchtype_change()";
555 554
 				// set the actions on tree
556
-				$etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions());
555
+				$etpl->setElementAttribute(self::$nm_index.'[foldertree]', 'actions', $this->get_tree_actions());
557 556
 
558 557
 				// sending preview toolbar actions
559 558
 				if ($content['mailSplitter']) $etpl->setElementAttribute('mailPreview[toolbar]', 'actions', $this->get_toolbar_actions());
@@ -564,31 +563,31 @@  discard block
 block discarded – undo
564 563
 				//we use the category "filter" option as specifier where we want to search (quick, subject, from, to, etc. ....)
565 564
 				if (empty($content[self::$nm_index]['cat_id']) || empty($content[self::$nm_index]['search']))
566 565
 				{
567
-					$content[self::$nm_index]['cat_id']=($content[self::$nm_index]['cat_id']?(!Mail::$supportsORinQuery[$this->mail_bo->profileID]&&($content[self::$nm_index]['cat_id']=='quick'||$content[self::$nm_index]['cat_id']=='quickwithcc')?'subject':$content[self::$nm_index]['cat_id']):(Mail::$supportsORinQuery[$this->mail_bo->profileID]?'quick':'subject'));
566
+					$content[self::$nm_index]['cat_id'] = ($content[self::$nm_index]['cat_id'] ? (!Mail::$supportsORinQuery[$this->mail_bo->profileID] && ($content[self::$nm_index]['cat_id'] == 'quick' || $content[self::$nm_index]['cat_id'] == 'quickwithcc') ? 'subject' : $content[self::$nm_index]['cat_id']) : (Mail::$supportsORinQuery[$this->mail_bo->profileID] ? 'quick' : 'subject'));
568 567
 				}
569 568
 				$readonlys = $preserv = array();
570
-				if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
569
+				if (Mail::$debugTimes) Mail::logRunTimes($starttime, null, '', __METHOD__.__LINE__);
571 570
 		}
572 571
 		catch (Exception $e)
573 572
 		{
574 573
 			// do not exit here. mail-tree should be build. if we exit here, we never get there.
575
-			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:'').' Menuaction:'.$_GET['menuaction'].'.'.function_backtrace());
574
+			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details ? ', '.$e->details : '').' Menuaction:'.$_GET['menuaction'].'.'.function_backtrace());
576 575
 			if (empty($etpl))
577 576
 			{
578
-				$sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
577
+				$sel_options[self::$nm_index]['foldertree'] = $this->mail_tree->getInitialIndexTree(null, $this->mail_bo->profileID, null, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'], !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
579 578
 				$etpl = new Etemplate('mail.index');
580 579
 			}
581
-			$etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions(false));
580
+			$etpl->setElementAttribute(self::$nm_index.'[foldertree]', 'actions', $this->get_tree_actions(false));
582 581
 			$readonlys = $preserv = array();
583
-			if (empty($content)) $content=array();
582
+			if (empty($content)) $content = array();
584 583
 
585
-			self::callWizard($e->getMessage().$e->getMessage().($e->details?', '.$e->details:''),false, 'error',false);
584
+			self::callWizard($e->getMessage().$e->getMessage().($e->details ? ', '.$e->details : ''), false, 'error', false);
586 585
 			//return false;
587 586
 		}
588 587
 		// Check preview pane is enabled, then show spliter
589 588
 		if ($this->mail_bo->mailPreferences['previewPane']) $etpl->setElementAttribute('mail.index.spliter', 'template', 'mail.index.nospliter');
590 589
 
591
-		return $etpl->exec('mail.mail_ui.index',$content,$sel_options,$readonlys,$preserv);
590
+		return $etpl->exec('mail.mail_ui.index', $content, $sel_options, $readonlys, $preserv);
592 591
 	}
593 592
 
594 593
 	/**
@@ -598,11 +597,11 @@  discard block
 block discarded – undo
598 597
 	 * @param {boolean} $imap_actions set to false if you want to avoid to talk to the imap-server
599 598
 	 * @return array
600 599
 	 */
601
-	function get_tree_actions($imap_actions=true)
600
+	function get_tree_actions($imap_actions = true)
602 601
 	{
603 602
 		// Start at 2 so auto-added copy+paste actions show up as second group
604 603
 		// Needed because there's no 'select all' action to push things down
605
-		$group=1;
604
+		$group = 1;
606 605
 		// Set tree actions
607 606
 		$tree_actions = array(
608 607
 			'drop_move_mail' => array(
@@ -683,12 +682,12 @@  discard block
 block discarded – undo
683 682
 				'onExecute' => 'javaScript:app.mail.edit_sieve',
684 683
 
685 684
 				'enabled'	=> 'javaScript:app.mail.sieve_enabled',
686
-				'icon' => 'mail/filter',	// funnel
685
+				'icon' => 'mail/filter', // funnel
687 686
 				'hideOnMobile' => true
688 687
 			),
689 688
 			'vacation' => array(
690 689
 				'caption' => 'Vacation notice',
691
-				'icon' => 'mail/navbar',	// mail as in admin
690
+				'icon' => 'mail/navbar', // mail as in admin
692 691
 				'onExecute' => 'javaScript:app.mail.edit_vacation',
693 692
 				'enabled'	=> 'javaScript:app.mail.sieve_enabled',
694 693
 			),
@@ -729,8 +728,8 @@  discard block
 block discarded – undo
729 728
 			unset($tree_actions['subscribe']);
730 729
 			unset($tree_actions['unsubscribe']);
731 730
 		}
732
-		++$group;	// put delete in own group
733
-		switch($GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'])
731
+		++$group; // put delete in own group
732
+		switch ($GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'])
734 733
 		{
735 734
 			case 'move_to_trash':
736 735
 				$tree_actions['empty_trash'] = array(
@@ -749,7 +748,7 @@  discard block
 block discarded – undo
749 748
 				);
750 749
 				break;
751 750
 		}
752
-		$junkFolder = ($imap_actions?$this->mail_bo->getJunkFolder():null);
751
+		$junkFolder = ($imap_actions ? $this->mail_bo->getJunkFolder() : null);
753 752
 
754 753
 		//error_log(__METHOD__.__LINE__.$junkFolder);
755 754
 		if ($junkFolder && !empty($junkFolder))
@@ -762,8 +761,8 @@  discard block
 block discarded – undo
762 761
 				'group'	=> $group,
763 762
 			);
764 763
 		}
765
-		$tree_actions['sieve']['group']	= $tree_actions['vacation']['group'] = ++$group;	// new group for filter
766
-		$tree_actions['edit_account']['group'] = $tree_actions['edit_acl']['group']	= ++$group;
764
+		$tree_actions['sieve']['group'] = $tree_actions['vacation']['group'] = ++$group; // new group for filter
765
+		$tree_actions['edit_account']['group'] = $tree_actions['edit_acl']['group'] = ++$group;
767 766
 
768 767
 
769 768
 		// enforce global (group-specific) ACL
@@ -798,19 +797,19 @@  discard block
 block discarded – undo
798 797
 	 * @param {string} $_folderName name of mailbox needs to be subcribe or unsubscribed
799 798
 	 * @param {boolean} $_status set true for subscribe and false to unsubscribe
800 799
 	 */
801
-	public function ajax_foldersubscription($_acc_id,$_folderName, $_status)
800
+	public function ajax_foldersubscription($_acc_id, $_folderName, $_status)
802 801
 	{
803 802
 		//Change the Mail object to related profileId
804 803
 		$this->changeProfile($_acc_id);
805 804
 
806
-		if($this->mail_bo->icServer->subscribeMailbox($_folderName, $_status))
805
+		if ($this->mail_bo->icServer->subscribeMailbox($_folderName, $_status))
807 806
 		{
808 807
 			$this->mail_bo->resetFolderObjectCache($_acc_id);
809
-			$this->ajax_reloadNode($_acc_id,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
808
+			$this->ajax_reloadNode($_acc_id, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
810 809
 		}
811 810
 		else
812 811
 		{
813
-			error_log(__METHOD__.__LINE__."()". lang('Folder %1 %2 failed!',$_folderName,$_status?'subscribed':'unsubscribed'));
812
+			error_log(__METHOD__.__LINE__."()".lang('Folder %1 %2 failed!', $_folderName, $_status ? 'subscribed' : 'unsubscribed'));
814 813
 		}
815 814
 	}
816 815
 
@@ -822,25 +821,25 @@  discard block
 block discarded – undo
822 821
 	 * @param string $_nodeID if of node whos children are requested
823 822
 	 * @param boolean $_subscribedOnly flag to tell wether to fetch all or only subscribed (default)
824 823
 	 */
825
-	public function ajax_foldertree($_nodeID = null,$_subscribedOnly=null)
824
+	public function ajax_foldertree($_nodeID = null, $_subscribedOnly = null)
826 825
 	{
827 826
 		$nodeID = $_GET['id'];
828 827
 		if (!is_null($_nodeID)) $nodeID = $_nodeID;
829
-		$subscribedOnly = (bool)(!is_null($_subscribedOnly)?$_subscribedOnly:!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
828
+		$subscribedOnly = (bool)(!is_null($_subscribedOnly) ? $_subscribedOnly : !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
830 829
 		$fetchCounters = !is_null($_nodeID);
831
-		list($_profileID,$_folderName) = explode(self::$delimiter,$nodeID,2);
830
+		list($_profileID, $_folderName) = explode(self::$delimiter, $nodeID, 2);
832 831
 
833 832
 		if (!empty($_folderName)) $fetchCounters = true;
834 833
 
835 834
 		// Check if it is called for refresh root
836 835
 		// then we need to reinitialized the index tree
837
-		if(!$nodeID && !$_profileID)
836
+		if (!$nodeID && !$_profileID)
838 837
 		{
839
-			$data = $this->mail_tree->getInitialIndexTree(null,null,null,null,true,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
838
+			$data = $this->mail_tree->getInitialIndexTree(null, null, null, null, true, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
840 839
 		}
841 840
 		else
842 841
 		{
843
-			$data = $this->mail_tree->getTree($nodeID,$_profileID,0, false,$subscribedOnly,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
842
+			$data = $this->mail_tree->getTree($nodeID, $_profileID, 0, false, $subscribedOnly, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
844 843
 		}
845 844
 		if (!is_null($_nodeID)) return $data;
846 845
 		Etemplate\Widget\Tree::send_quote_json($data);
@@ -856,17 +855,17 @@  discard block
 block discarded – undo
856 855
 	 */
857 856
 	static function findNode($_out, $_nodeID, $childElements = false)
858 857
 	{
859
-		foreach($_out['item'] as $node)
858
+		foreach ($_out['item'] as $node)
860 859
 		{
861
-			if (strcmp($node['id'],$_nodeID)===0)
860
+			if (strcmp($node['id'], $_nodeID) === 0)
862 861
 			{
863 862
 				//error_log(__METHOD__.__LINE__.':'.$_nodeID.'->'.$node['id']);
864
-				return ($childElements?$node['item']:$node);
863
+				return ($childElements ? $node['item'] : $node);
865 864
 			}
866
-			elseif (is_array($node['item']) && strncmp($node['id'],$_nodeID,strlen($node['id']))===0 && strlen($_nodeID)>strlen($node['id']))
865
+			elseif (is_array($node['item']) && strncmp($node['id'], $_nodeID, strlen($node['id'])) === 0 && strlen($_nodeID) > strlen($node['id']))
867 866
 			{
868 867
 				//error_log(__METHOD__.__LINE__.' descend into '.$node['id']);
869
-				return self::findNode($node,$_nodeID,$childElements);
868
+				return self::findNode($node, $_nodeID, $childElements);
870 869
 			}
871 870
 		}
872 871
 	}
@@ -880,7 +879,7 @@  discard block
 block discarded – undo
880 879
 	 */
881 880
 	private function get_actions()
882 881
 	{
883
-		static $accArray=array(); // buffer identity names on single request
882
+		static $accArray = array(); // buffer identity names on single request
884 883
 		// duplicated from mail_hooks
885 884
 		static $deleteOptions = array(
886 885
 			'move_to_trash'		=> 'move to trash',
@@ -891,12 +890,12 @@  discard block
 block discarded – undo
891 890
 		$lastFolderUsedForMove = null;
892 891
 		$moveactions = array();
893 892
 		$archiveFolder = $this->mail_bo->getArchiveFolder();
894
-		$lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1);
893
+		$lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 1);
895 894
 		//error_log(__METHOD__.__LINE__." StoredFolders->".array2string($lastFoldersUsedForMoveCont));
896 895
 		//error_log(__METHOD__.__LINE__.' ProfileId:'.$this->mail_bo->profileID." StoredFolders->(".count($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]).") ".array2string($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]));
897 896
 		if (is_null($accArray))
898 897
 		{
899
-			foreach(Mail\Account::search($only_current_user=true, false) as $acc_id => $accountObj)
898
+			foreach (Mail\Account::search($only_current_user = true, false) as $acc_id => $accountObj)
900 899
 			{
901 900
 				//error_log(__METHOD__.__LINE__.array2string($accountObj));
902 901
 				if (!$accountObj->is_imap())
@@ -904,22 +903,22 @@  discard block
 block discarded – undo
904 903
 					// not to be used for IMAP Foldertree, as there is no Imap host
905 904
 					continue;
906 905
 				}
907
-				$identity_name = Mail\Account::identity_name($accountObj,true,$GLOBALS['egw_info']['user']['acount_id']);
908
-				$accArray[$acc_id] = str_replace(array('<','>'),array('[',']'),$identity_name);// as angle brackets are quoted, display in Javascript messages when used is ugly, so use square brackets instead
906
+				$identity_name = Mail\Account::identity_name($accountObj, true, $GLOBALS['egw_info']['user']['acount_id']);
907
+				$accArray[$acc_id] = str_replace(array('<', '>'), array('[', ']'), $identity_name); // as angle brackets are quoted, display in Javascript messages when used is ugly, so use square brackets instead
909 908
 			}
910 909
 		}
911
-		if (!is_array($lastFoldersUsedForMoveCont)) $lastFoldersUsedForMoveCont=array();
910
+		if (!is_array($lastFoldersUsedForMoveCont)) $lastFoldersUsedForMoveCont = array();
912 911
 		foreach (array_keys($lastFoldersUsedForMoveCont) as $pid)
913 912
 		{
914
-			if ($this->mail_bo->profileID==$pid && isset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]))
913
+			if ($this->mail_bo->profileID == $pid && isset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]))
915 914
 			{
916 915
 				$_folder = $this->mail_bo->icServer->getCurrentMailbox();
917 916
 				//error_log(__METHOD__.__LINE__.' '.$_folder."<->".$lastFoldersUsedForMoveCont[$this->mail_bo->profileID].function_backtrace());
918
-				$counter =1;
917
+				$counter = 1;
919 918
 				foreach ($lastFoldersUsedForMoveCont[$this->mail_bo->profileID] as $i => $lastFolderUsedForMoveCont)
920 919
 				{
921 920
 					$moveaction = 'move_';
922
-					if ($_folder!=$i)
921
+					if ($_folder != $i)
923 922
 					{
924 923
 						$moveaction .= $lastFolderUsedForMoveCont;
925 924
 						//error_log(__METHOD__.__LINE__.'#'.$moveaction);
@@ -930,7 +929,7 @@  discard block
 block discarded – undo
930 929
 							$fS['profileName'] = $accArray[$this->mail_bo->profileID];
931 930
 							$fS['shortDisplayName'] = $i;
932 931
 							$moveactions[$moveaction] = $fS;
933
-							$counter ++;
932
+							$counter++;
934 933
 						}
935 934
 						else
936 935
 						{
@@ -940,9 +939,9 @@  discard block
 block discarded – undo
940 939
 					}
941 940
 				}
942 941
 			}
943
-			elseif ($this->mail_bo->profileID!=$pid && isset($lastFoldersUsedForMoveCont[$pid]) && !empty($lastFoldersUsedForMoveCont[$pid]))
942
+			elseif ($this->mail_bo->profileID != $pid && isset($lastFoldersUsedForMoveCont[$pid]) && !empty($lastFoldersUsedForMoveCont[$pid]))
944 943
 			{
945
-				$counter =1;
944
+				$counter = 1;
946 945
 				foreach ($lastFoldersUsedForMoveCont[$pid] as $i => $lastFolderUsedForMoveCont)
947 946
 				{
948 947
 					//error_log(__METHOD__.__LINE__."$i => $lastFolderUsedForMoveCont");
@@ -955,19 +954,19 @@  discard block
 block discarded – undo
955 954
 						$fS['profileName'] = $accArray[$pid];
956 955
 						$fS['shortDisplayName'] = $i;
957 956
 						$moveactions[$moveaction] = $fS;
958
-						$counter ++;
957
+						$counter++;
959 958
 					}
960 959
 				}
961 960
 			}
962 961
 		}
963
-		Api\Cache::setCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),$lastFoldersUsedForMoveCont, $expiration=60*60*1);
962
+		Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']), $lastFoldersUsedForMoveCont, $expiration = 60 * 60 * 1);
964 963
 		$group = 0;
965
-		$actions =  array(
964
+		$actions = array(
966 965
 			'open' => array(
967 966
 				'caption' => lang('Open'),
968 967
 				'icon' => 'view',
969 968
 				'group' => ++$group,
970
-				'onExecute' => Api\Header\UserAgent::mobile()?'javaScript:app.mail.mobileView':'javaScript:app.mail.mail_open',
969
+				'onExecute' => Api\Header\UserAgent::mobile() ? 'javaScript:app.mail.mobileView' : 'javaScript:app.mail.mail_open',
971 970
 				'allowOnMultiple' => false,
972 971
 				'default' => true,
973 972
 				'mobileViewTemplate' => 'view?'.filemtime(Api\Etemplate\Widget\Template::rel2path('/mail/templates/mobile/view.xet'))
@@ -1020,20 +1019,20 @@  discard block
 block discarded – undo
1020 1019
 				'allowOnMultiple' => false,
1021 1020
 			)
1022 1021
 		);
1023
-		$macounter=0;
1022
+		$macounter = 0;
1024 1023
 		if (!empty($moveactions))
1025 1024
 		{
1026 1025
 			//error_log(__METHOD__.__LINE__.array2string($moveactions));
1027
-			$children=array();
1028
-			$pID=0;
1026
+			$children = array();
1027
+			$pID = 0;
1029 1028
 			foreach ($moveactions as $moveaction => $lastFolderUsedForMove)
1030 1029
 			{
1031
-				$group = ($pID != $lastFolderUsedForMove['profileID'] && $macounter>0? $group+1 : $group);
1030
+				$group = ($pID != $lastFolderUsedForMove['profileID'] && $macounter > 0 ? $group + 1 : $group);
1032 1031
 				//error_log(__METHOD__.__LINE__."#$pID != ".$lastFolderUsedForMove['profileID']."#".$macounter.'#'.$groupCounter.'#');
1033 1032
 				$children = array_merge($children,
1034 1033
 					array(
1035 1034
 						$moveaction => array(
1036
-							'caption' => (!empty($lastFolderUsedForMove['profileName'])?$lastFolderUsedForMove['profileName']:'('.$lastFolderUsedForMove['profileID'].')').': '.(isset($lastFolderUsedForMove['shortDisplayName'])?$lastFolderUsedForMove['shortDisplayName']:''),
1035
+							'caption' => (!empty($lastFolderUsedForMove['profileName']) ? $lastFolderUsedForMove['profileName'] : '('.$lastFolderUsedForMove['profileID'].')').': '.(isset($lastFolderUsedForMove['shortDisplayName']) ? $lastFolderUsedForMove['shortDisplayName'] : ''),
1037 1036
 							'icon' => 'move',
1038 1037
 							'group' => $group,
1039 1038
 							'onExecute' => 'javaScript:app.mail.mail_move2folder',
@@ -1044,7 +1043,7 @@  discard block
 block discarded – undo
1044 1043
 				$pID = $lastFolderUsedForMove['profileID'];
1045 1044
 				$macounter++;
1046 1045
 			}
1047
-			$actions['moveto'] =	array(
1046
+			$actions['moveto'] = array(
1048 1047
 				'caption' => lang('Move selected to'),
1049 1048
 				'icon' => 'move',
1050 1049
 				'group' => $group,
@@ -1087,7 +1086,7 @@  discard block
 block discarded – undo
1087 1086
 				'icon' => 'tracker/navbar',
1088 1087
 				'onExecute' => 'javaScript:app.mail.mail_integrate',
1089 1088
 				'popup' => Link::get_registry('tracker', 'add_popup'),
1090
-				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'),
1089
+				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'), 'tracker'),
1091 1090
 				'allowOnMultiple' => false,
1092 1091
 			),
1093 1092
 			'calendar' => array(
@@ -1306,25 +1305,25 @@  discard block
 block discarded – undo
1306 1305
 	 * @param array &$rows
1307 1306
 	 * @param array &$readonlys
1308 1307
 	 */
1309
-	public static function get_rows(&$query,&$rows,&$readonlys)
1308
+	public static function get_rows(&$query, &$rows, &$readonlys)
1310 1309
 	{
1311
-		unset($readonlys);	// not used, but required by function signature
1310
+		unset($readonlys); // not used, but required by function signature
1312 1311
 
1313 1312
 		// handle possible profile change in get_rows
1314 1313
 		if (!empty($query['selectedFolder']))
1315 1314
 		{
1316
-			list($_profileID,$folderName) = explode(self::$delimiter, $query['selectedFolder'], 2);
1315
+			list($_profileID, $folderName) = explode(self::$delimiter, $query['selectedFolder'], 2);
1317 1316
 			if (is_numeric(($_profileID)) && $_profileID != $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'])
1318 1317
 			{
1319 1318
 				try {
1320
-					$mail_ui = new mail_ui(false);	// do NOT run constructor, as we change profile anyway
1319
+					$mail_ui = new mail_ui(false); // do NOT run constructor, as we change profile anyway
1321 1320
 					$mail_ui->changeProfile($_profileID);
1322 1321
 					$query['actions'] = $mail_ui->get_actions();
1323 1322
 				}
1324
-				catch(Exception $e)
1323
+				catch (Exception $e)
1325 1324
 				{
1326 1325
 					unset($e);
1327
-					$rows=array();
1326
+					$rows = array();
1328 1327
 					return 0;
1329 1328
 				}
1330 1329
 				if (empty($folderName)) $query['selectedFolder'] = $_profileID.self::$delimiter.'INBOX';
@@ -1334,12 +1333,12 @@  discard block
 block discarded – undo
1334 1333
 		{
1335 1334
 			try
1336 1335
 			{
1337
-				$mail_ui = new mail_ui(true);	// run constructor for current profile
1336
+				$mail_ui = new mail_ui(true); // run constructor for current profile
1338 1337
 			}
1339
-			catch(Exception $e)
1338
+			catch (Exception $e)
1340 1339
 			{
1341 1340
 				unset($e);
1342
-				$rows=array();
1341
+				$rows = array();
1343 1342
 				return 0;
1344 1343
 			}
1345 1344
 			if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX';
@@ -1350,68 +1349,68 @@  discard block
 block discarded – undo
1350 1349
 		//$query['search'] is the phrase in the searchbox
1351 1350
 
1352 1351
 		$mail_ui->mail_bo->restoreSessionData();
1353
-		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$query['selectedFolder'];
1352
+		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox'] = $query['selectedFolder'];
1354 1353
 		$mail_ui->mail_bo->saveSessionData();
1355 1354
 
1356 1355
 		$sRToFetch = null;
1357
-		list($_profileID,$_folderName) = explode(self::$delimiter,$query['selectedFolder'],2);
1358
-		if (strpos($_folderName,self::$delimiter)!==false)
1356
+		list($_profileID, $_folderName) = explode(self::$delimiter, $query['selectedFolder'], 2);
1357
+		if (strpos($_folderName, self::$delimiter) !== false)
1359 1358
 		{
1360
-			list($app,$_profileID,$_folderName) = explode(self::$delimiter,$_folderName,3);
1359
+			list($app, $_profileID, $_folderName) = explode(self::$delimiter, $_folderName, 3);
1361 1360
 			unset($app);
1362 1361
 		}
1363 1362
 		//save selected Folder to sessionData (mailbox)->currentFolder
1364
-		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$_folderName;
1365
-		$toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default)
1363
+		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox'] = $_folderName;
1364
+		$toSchema = false; //decides to select list schema with column to selected (if false fromaddress is default)
1366 1365
 		if ($mail_ui->mail_bo->folderExists($_folderName))
1367 1366
 		{
1368
-			$toSchema = $mail_ui->mail_bo->isDraftFolder($_folderName,false)||$mail_ui->mail_bo->isSentFolder($_folderName,false)||$mail_ui->mail_bo->isTemplateFolder($_folderName,false);
1367
+			$toSchema = $mail_ui->mail_bo->isDraftFolder($_folderName, false) || $mail_ui->mail_bo->isSentFolder($_folderName, false) || $mail_ui->mail_bo->isTemplateFolder($_folderName, false);
1369 1368
 		}
1370 1369
 		else
1371 1370
 		{
1372 1371
 			// take the extra time on failure
1373
-			if (!$mail_ui->mail_bo->folderExists($_folderName,true))
1372
+			if (!$mail_ui->mail_bo->folderExists($_folderName, true))
1374 1373
 			{
1375 1374
 				//error_log(__METHOD__.__LINE__.' Test on Folder:'.$_folderName.' failed; Using INBOX instead');
1376
-				$query['selectedFolder']=$mail_ui->mail_bo->sessionData['mailbox']=$_folderName='INBOX';
1375
+				$query['selectedFolder'] = $mail_ui->mail_bo->sessionData['mailbox'] = $_folderName = 'INBOX';
1377 1376
 			}
1378 1377
 		}
1379 1378
 		$mail_ui->mail_bo->saveSessionData();
1380 1379
 		$rowsFetched['messages'] = null;
1381
-		$offset = $query['start']+1; // we always start with 1
1380
+		$offset = $query['start'] + 1; // we always start with 1
1382 1381
 		$maxMessages = $query['num_rows'];
1383 1382
 		//error_log(__METHOD__.__LINE__.array2string($query));
1384
-		$sort = ($query['order']=='address'?($toSchema?'toaddress':'fromaddress'):$query['order']);
1385
-		if (!empty($query['search'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate']))))
1383
+		$sort = ($query['order'] == 'address' ? ($toSchema ? 'toaddress' : 'fromaddress') : $query['order']);
1384
+		if (!empty($query['search']) || ($query['cat_id'] == 'bydate' && (!empty($query['startdate']) || !empty($query['enddate']))))
1386 1385
 		{
1387 1386
 			if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]))
1388 1387
 			{
1389
-				Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
1388
+				Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1390 1389
 				if (!isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]))
1391 1390
 				{
1392
-					Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]=true;
1391
+					Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] = true;
1393 1392
 				}
1394 1393
 			}
1395 1394
 			//error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']);
1396 1395
 			$cutoffdate = $cutoffdate2 = null;
1397
-			if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
1398
-			if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
1396
+			if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'], 'ts'); //SINCE, enddate
1397
+			if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'], 'ts'); //BEFORE, startdate
1399 1398
 			//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
1400 1399
 			$filter = array(
1401
-				'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
1402
-				'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')),
1400
+				'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? lang('quicksearch') : lang('subject')),
1401
+				'type' => ($query['cat_id'] ? $query['cat_id'] : (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? 'quick' : 'subject')),
1403 1402
 				'string' => $query['search'],
1404 1403
 				'status' => 'any',
1405 1404
 				//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
1406 1405
 			);
1407
-			if ($query['enddate']||$query['startdate']) {
1406
+			if ($query['enddate'] || $query['startdate']) {
1408 1407
 				$filter['range'] = "BETWEEN";
1409 1408
 				if ($cutoffdate) {
1410
-					$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
1409
+					$filter[(empty($cutoffdate2) ? 'date' : 'since')] = date("d-M-Y", $cutoffdate);
1411 1410
 					if (empty($cutoffdate2)) $filter['range'] = "SINCE";
1412 1411
 				}
1413 1412
 				if ($cutoffdate2) {
1414
-					$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
1413
+					$filter[(empty($cutoffdate) ? 'date' : 'before')] = date("d-M-Y", $cutoffdate2);
1415 1414
 					if (empty($cutoffdate)) $filter['range'] = "BEFORE";
1416 1415
 				}
1417 1416
 			}
@@ -1424,17 +1423,17 @@  discard block
 block discarded – undo
1424 1423
 		{
1425 1424
 			$filter['status'] = $query['filter'];
1426 1425
 		}
1427
-		$reverse = ($query['sort']=='ASC'?false:true);
1426
+		$reverse = ($query['sort'] == 'ASC' ? false : true);
1428 1427
 		$prefchanged = false;
1429
-		if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']) || ($query['cat_id'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']))
1428
+		if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']) || ($query['cat_id'] != $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveSearchType']))
1430 1429
 		{
1431 1430
 			//error_log(__METHOD__.__LINE__.' Changing userPref ActivesearchType:'.$query['cat_id']);
1432
-			$GLOBALS['egw']->preferences->add('mail','ActiveSearchType',$query['cat_id'],'user');
1431
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveSearchType', $query['cat_id'], 'user');
1433 1432
 			$prefchanged = true;
1434 1433
 		}
1435
-		if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']) || ($query['filter2'] !=$GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']))
1434
+		if (!isset($GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']) || ($query['filter2'] != $GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']))
1436 1435
 		{
1437
-			$GLOBALS['egw']->preferences->add('mail','ShowDetails',$query['filter2'],'user');
1436
+			$GLOBALS['egw']->preferences->add('mail', 'ShowDetails', $query['filter2'], 'user');
1438 1437
 			$prefchanged = true;
1439 1438
 		}
1440 1439
 		if ($prefchanged)
@@ -1459,18 +1458,18 @@  discard block
 block discarded – undo
1459 1458
 					$sort,
1460 1459
 					$reverse,
1461 1460
 					$filter,
1462
-					$rByUid=true
1461
+					$rByUid = true
1463 1462
 				);
1464 1463
 				$rowsFetched['messages'] = $_sR['count'];
1465 1464
 				$ids = $_sR['match']->ids;
1466 1465
 				// if $sR is false, something failed fundamentally
1467
-				if($reverse === true) $ids = ($ids===false?array():array_reverse((array)$ids));
1468
-				$sR = array_slice((array)$ids,($offset==0?0:$offset-1),$maxMessages); // we need only $maxMessages of uids
1469
-				$sRToFetch = $sR;//array_slice($sR,0,50); // we fetch only the headers of a subset of the fetched uids
1466
+				if ($reverse === true) $ids = ($ids === false ? array() : array_reverse((array)$ids));
1467
+				$sR = array_slice((array)$ids, ($offset == 0 ? 0 : $offset - 1), $maxMessages); // we need only $maxMessages of uids
1468
+				$sRToFetch = $sR; //array_slice($sR,0,50); // we fetch only the headers of a subset of the fetched uids
1470 1469
 				//error_log(__METHOD__.__LINE__.' Rows fetched (UID only):'.count($sR).' Data:'.array2string($sR));
1471 1470
 				$maxMessages = 75;
1472 1471
 				$sortResultwH['header'] = array();
1473
-				if (count($sRToFetch)>0)
1472
+				if (count($sRToFetch) > 0)
1474 1473
 				{
1475 1474
 					//error_log(__METHOD__.__LINE__.' Headers to fetch with UIDs:'.count($sRToFetch).' Data:'.array2string($sRToFetch));
1476 1475
 					$sortResult = array();
@@ -1484,7 +1483,7 @@  discard block
 block discarded – undo
1484 1483
 						$filter,
1485 1484
 						$sRToFetch,
1486 1485
 						true, //cacheResult
1487
-						($query['filter2']?true:false) // fetchPreview
1486
+						($query['filter2'] ? true : false) // fetchPreview
1488 1487
 					);
1489 1488
 				}
1490 1489
 			}
@@ -1501,30 +1500,30 @@  discard block
 block discarded – undo
1501 1500
 					$filter,
1502 1501
 					null, // this uids only
1503 1502
 					true, // cacheResult
1504
-					($query['filter2']?true:false) // fetchPreview
1503
+					($query['filter2'] ? true : false) // fetchPreview
1505 1504
 				);
1506 1505
 				$rowsFetched['messages'] = $sortResultwH['info']['total'];
1507 1506
 			}
1508 1507
 		}
1509 1508
 		catch (Exception $e)
1510 1509
 		{
1511
-			$sortResultwH=array();
1512
-			$sR=array();
1510
+			$sortResultwH = array();
1511
+			$sR = array();
1513 1512
 			self::callWizard($e->getMessage(), false, 'error');
1514 1513
 		}
1515 1514
 		$response = Api\Json\Response::get();
1516 1515
 		// unlock immediately after fetching the rows
1517
-		if (stripos($_GET['menuaction'],'ajax_get_rows')!==false)
1516
+		if (stripos($_GET['menuaction'], 'ajax_get_rows') !== false)
1518 1517
 		{
1519 1518
 			//error_log(__METHOD__.__LINE__.' unlock tree ->'.$_GET['menuaction']);
1520 1519
 			$response->call('app.mail.unlock_tree');
1521 1520
 		}
1522 1521
 
1523
-		if (is_array($sR) && count($sR)>0)
1522
+		if (is_array($sR) && count($sR) > 0)
1524 1523
 		{
1525 1524
 			foreach ((array)$sR as $key => $v)
1526 1525
 			{
1527
-				if (array_key_exists($key,(array)$sortResultwH['header'])==true)
1526
+				if (array_key_exists($key, (array)$sortResultwH['header']) == true)
1528 1527
 				{
1529 1528
 					$sortResult['header'][] = $sortResultwH['header'][$key];
1530 1529
 				}
@@ -1542,12 +1541,12 @@  discard block
 block discarded – undo
1542 1541
 		if (empty($rowsFetched['messages'])) $rowsFetched['messages'] = $rowsFetched['rowsFetched'];
1543 1542
 
1544 1543
 		//error_log(__METHOD__.__LINE__.' Rows fetched:'.$rowsFetched.' Data:'.array2string($sortResult));
1545
-		$cols = array('row_id','uid','status','attachments','subject','address','toaddress','fromaddress','ccaddress','additionaltoaddress','date','size','modified','bodypreview');
1546
-		if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE') unset($cols[0]);
1547
-		$rows = $mail_ui->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType=$toSchema);
1544
+		$cols = array('row_id', 'uid', 'status', 'attachments', 'subject', 'address', 'toaddress', 'fromaddress', 'ccaddress', 'additionaltoaddress', 'date', 'size', 'modified', 'bodypreview');
1545
+		if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode'] == 'EGW_SELECTMODE_TOGGLE') unset($cols[0]);
1546
+		$rows = $mail_ui->header2gridelements($sortResult['header'], $cols, $_folderName, $folderType = $toSchema);
1548 1547
 		//error_log(__METHOD__.__LINE__.array2string($rows));
1549 1548
 
1550
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'],__METHOD__.__LINE__);
1549
+		if (Mail::$debugTimes) Mail::logRunTimes($starttime, null, 'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'], __METHOD__.__LINE__);
1551 1550
 		return $rowsFetched['messages'];
1552 1551
 	}
1553 1552
 
@@ -1559,7 +1558,7 @@  discard block
 block discarded – undo
1559 1558
 	 * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID
1560 1559
 	 * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid
1561 1560
 	 */
1562
-	function createRowID($_folderName, $message_uid, $_prependApp=false)
1561
+	function createRowID($_folderName, $message_uid, $_prependApp = false)
1563 1562
 	{
1564 1563
 		return self::generateRowID($this->mail_bo->profileID, $_folderName, $message_uid, $_prependApp);
1565 1564
 	}
@@ -1573,9 +1572,9 @@  discard block
 block discarded – undo
1573 1572
 	 * @param boolean $_prependApp to indicate that the app 'mail' is to be used for creating the rowID
1574 1573
 	 * @return string - a colon separated string in the form [app:]accountID:profileID:folder:message_uid
1575 1574
 	 */
1576
-	static function generateRowID($_profileID, $_folderName, $message_uid, $_prependApp=false)
1575
+	static function generateRowID($_profileID, $_folderName, $message_uid, $_prependApp = false)
1577 1576
 	{
1578
-		return ($_prependApp?'mail'.self::$delimiter:'').trim($GLOBALS['egw_info']['user']['account_id']).self::$delimiter.$_profileID.self::$delimiter.base64_encode($_folderName).self::$delimiter.$message_uid;
1577
+		return ($_prependApp ? 'mail'.self::$delimiter : '').trim($GLOBALS['egw_info']['user']['account_id']).self::$delimiter.$_profileID.self::$delimiter.base64_encode($_folderName).self::$delimiter.$message_uid;
1579 1578
 	}
1580 1579
 
1581 1580
 	/**
@@ -1586,13 +1585,13 @@  discard block
 block discarded – undo
1586 1585
 	 */
1587 1586
 	static function splitRowID($_rowID)
1588 1587
 	{
1589
-		$res = explode(self::$delimiter,$_rowID);
1588
+		$res = explode(self::$delimiter, $_rowID);
1590 1589
 		// as a rowID is perceeded by app::, should be mail!
1591 1590
 		//error_log(__METHOD__.__LINE__.array2string($res).' [0] isInt:'.is_int($res[0]).' [0] isNumeric:'.is_numeric($res[0]).' [0] isString:'.is_string($res[0]).' Count:'.count($res));
1592
-		if (count($res)==4 && is_numeric($res[0]) )
1591
+		if (count($res) == 4 && is_numeric($res[0]))
1593 1592
 		{
1594 1593
 			// we have an own created rowID; prepend app=mail
1595
-			array_unshift($res,'mail');
1594
+			array_unshift($res, 'mail');
1596 1595
 		}
1597 1596
 		return array('app'=>$res[0], 'accountID'=>$res[1], 'profileID'=>$res[2], 'folder'=>base64_decode($res[3]), 'msgUID'=>$res[4]);
1598 1597
 	}
@@ -1606,56 +1605,56 @@  discard block
 block discarded – undo
1606 1605
 	{
1607 1606
 		$actions = $this->get_actions();
1608 1607
 		$arrActions = array('composeasnew', 'reply', 'reply_all', 'forward', 'flagged', 'delete', 'print',
1609
-			'infolog', 'tracker', 'calendar', 'save', 'view', 'read', 'label1',	'label2', 'label3',	'label4', 'label5');
1610
-		foreach( $arrActions as &$act)
1608
+			'infolog', 'tracker', 'calendar', 'save', 'view', 'read', 'label1', 'label2', 'label3', 'label4', 'label5');
1609
+		foreach ($arrActions as &$act)
1611 1610
 		{
1612 1611
 			//error_log(__METHOD__.__LINE__.' '.$act.'->'.array2string($actions[$act]));
1613 1612
 			switch ($act)
1614 1613
 			{
1615 1614
 				case 'forward':
1616
-					$actionsenabled[$act]=$actions[$act];
1615
+					$actionsenabled[$act] = $actions[$act];
1617 1616
 					break;
1618 1617
 				case 'save':
1619
-					$actionsenabled[$act]=$actions[$act];
1618
+					$actionsenabled[$act] = $actions[$act];
1620 1619
 
1621 1620
 					break;
1622 1621
 				case 'view':
1623
-					$actionsenabled[$act]=$actions[$act];
1622
+					$actionsenabled[$act] = $actions[$act];
1624 1623
 					break;
1625 1624
 				case 'flagged':
1626
-					$actionsenabled[$act]= $actions['mark']['children'][$act];
1625
+					$actionsenabled[$act] = $actions['mark']['children'][$act];
1627 1626
 					break;
1628 1627
 				case 'read':
1629
-					$actionsenabled[$act]= $actions['mark']['children'][$act];
1628
+					$actionsenabled[$act] = $actions['mark']['children'][$act];
1630 1629
 					break;
1631 1630
 				case 'label1':
1632 1631
 					$actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('important');
1633
-					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1632
+					$actionsenabled[$act] = $actions['mark']['children']['setLabel']['children'][$act];
1634 1633
 					break;
1635 1634
 				case 'label2':
1636 1635
 					$actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('job');
1637
-					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1636
+					$actionsenabled[$act] = $actions['mark']['children']['setLabel']['children'][$act];
1638 1637
 					break;
1639 1638
 				case 'label3':
1640 1639
 					$actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('personal');
1641
-					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1640
+					$actionsenabled[$act] = $actions['mark']['children']['setLabel']['children'][$act];
1642 1641
 					break;
1643 1642
 				case 'label4':
1644 1643
 					$actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('to do');
1645
-					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1644
+					$actionsenabled[$act] = $actions['mark']['children']['setLabel']['children'][$act];
1646 1645
 					break;
1647 1646
 				case 'label5':
1648 1647
 					$actions['mark']['children']['setLabel']['children'][$act]['caption'] = lang('later');
1649
-					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1648
+					$actionsenabled[$act] = $actions['mark']['children']['setLabel']['children'][$act];
1650 1649
 					break;
1651 1650
 				default:
1652
-					if (isset($actions[$act])) $actionsenabled[$act]=$actions[$act];
1651
+					if (isset($actions[$act])) $actionsenabled[$act] = $actions[$act];
1653 1652
 			}
1654 1653
 		}
1655 1654
 		unset($actionsenabled['drag_mail']);
1656 1655
 		//error_log(array2string($actionsenabled['view']));
1657
-		unset($actionsenabled['view']['children']['openastext']);//not supported in preview
1658
-		unset($actionsenabled['view']['children']['openashtml']);//not supported in preview
1656
+		unset($actionsenabled['view']['children']['openastext']); //not supported in preview
1657
+		unset($actionsenabled['view']['children']['openashtml']); //not supported in preview
1659 1658
 
1660 1659
 		return $actionsenabled;
1661 1660
 	}
@@ -1669,45 +1668,45 @@  discard block
 block discarded – undo
1669 1668
 	 * @param array $_folderType used to determine if we need to populate from/to
1670 1669
 	 * @return array populated result array
1671 1670
 	 */
1672
-	public function header2gridelements($_headers, $cols, $_folderName, $_folderType=0)
1671
+	public function header2gridelements($_headers, $cols, $_folderName, $_folderType = 0)
1673 1672
 	{
1674 1673
 		if (Mail::$debugTimes) $starttime = microtime(true);
1675 1674
 		$rv = array();
1676
-		$i=0;
1677
-		foreach((array)$_headers as $header)
1675
+		$i = 0;
1676
+		foreach ((array)$_headers as $header)
1678 1677
 		{
1679 1678
 			$i++;
1680 1679
 			$data = array();
1681 1680
 			//error_log(__METHOD__.array2string($header));
1682 1681
 			$message_uid = $header['uid'];
1683 1682
 			$data['uid'] = $message_uid;
1684
-			$data['row_id']=$this->createRowID($_folderName,$message_uid);
1683
+			$data['row_id'] = $this->createRowID($_folderName, $message_uid);
1685 1684
 
1686 1685
 			$flags = "";
1687
-			if(!empty($header['recent'])) $flags .= "R";
1688
-			if(!empty($header['flagged'])) $flags .= "F";
1689
-			if(!empty($header['answered'])) $flags .= "A";
1690
-			if(!empty($header['forwarded'])) $flags .= "W";
1691
-			if(!empty($header['deleted'])) $flags .= "D";
1692
-			if(!empty($header['seen'])) $flags .= "S";
1693
-			if(!empty($header['label1'])) $flags .= "1";
1694
-			if(!empty($header['label2'])) $flags .= "2";
1695
-			if(!empty($header['label3'])) $flags .= "3";
1696
-			if(!empty($header['label4'])) $flags .= "4";
1697
-			if(!empty($header['label5'])) $flags .= "5";
1686
+			if (!empty($header['recent'])) $flags .= "R";
1687
+			if (!empty($header['flagged'])) $flags .= "F";
1688
+			if (!empty($header['answered'])) $flags .= "A";
1689
+			if (!empty($header['forwarded'])) $flags .= "W";
1690
+			if (!empty($header['deleted'])) $flags .= "D";
1691
+			if (!empty($header['seen'])) $flags .= "S";
1692
+			if (!empty($header['label1'])) $flags .= "1";
1693
+			if (!empty($header['label2'])) $flags .= "2";
1694
+			if (!empty($header['label3'])) $flags .= "3";
1695
+			if (!empty($header['label4'])) $flags .= "4";
1696
+			if (!empty($header['label5'])) $flags .= "5";
1698 1697
 
1699 1698
 			$data["status"] = "<span class=\"status_img\"></span>";
1700 1699
 			//error_log(__METHOD__.array2string($header).' Flags:'.$flags);
1701 1700
 
1702 1701
 			// the css for this row
1703
-			$is_recent=false;
1702
+			$is_recent = false;
1704 1703
 			$css_styles = array("mail");
1705 1704
 			if ($header['deleted']) {
1706 1705
 				$css_styles[] = 'deleted';
1707 1706
 			}
1708 1707
 			if ($header['recent'] && !($header['deleted'] || $header['seen'] || $header['answered'] || $header['forwarded'])) {
1709 1708
 				$css_styles[] = 'recent';
1710
-				$is_recent=true;
1709
+				$is_recent = true;
1711 1710
 			}
1712 1711
 			if ($header['priority'] < 3) {
1713 1712
 				$css_styles[] = 'prio_high';
@@ -1745,19 +1744,19 @@  discard block
 block discarded – undo
1745 1744
 			if (in_array("subject", $cols))
1746 1745
 			{
1747 1746
 				// filter out undisplayable characters
1748
-				$search = array('[\016]','[\017]',
1749
-					'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
1750
-					'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
1747
+				$search = array('[\016]', '[\017]',
1748
+					'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
1749
+					'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
1751 1750
 				$replace = '';
1752 1751
 
1753
-				$header['subject'] = preg_replace($search,$replace,$header['subject']);
1752
+				$header['subject'] = preg_replace($search, $replace, $header['subject']);
1754 1753
 				// curly brackets get messed up by the template!
1755 1754
 
1756 1755
 				if (!empty($header['subject'])) {
1757 1756
 					// make the subject shorter if it is to long
1758 1757
 					$subject = $header['subject'];
1759 1758
 				} else {
1760
-					$subject = '('. lang('no subject') .')';
1759
+					$subject = '('.lang('no subject').')';
1761 1760
 				}
1762 1761
 
1763 1762
 				$data["subject"] = $subject; // the mailsubject
@@ -1767,53 +1766,53 @@  discard block
 block discarded – undo
1767 1766
 			//error_log(__METHOD__.__LINE__.array2string($header));
1768 1767
 			if (in_array("attachments", $cols))
1769 1768
 			{
1770
-				if($header['mimetype'] == 'multipart/mixed' ||
1769
+				if ($header['mimetype'] == 'multipart/mixed' ||
1771 1770
 					$header['mimetype'] == 'multipart/signed' ||
1772 1771
 					$header['mimetype'] == 'multipart/related' ||
1773 1772
 					$header['mimetype'] == 'multipart/report' ||
1774 1773
 					$header['mimetype'] == 'text/calendar' ||
1775 1774
 					$header['mimetype'] == 'text/html' ||
1776
-					substr($header['mimetype'],0,11) == 'application' ||
1777
-					substr($header['mimetype'],0,5) == 'audio' ||
1778
-					substr($header['mimetype'],0,5) == 'video' ||
1775
+					substr($header['mimetype'], 0, 11) == 'application' ||
1776
+					substr($header['mimetype'], 0, 5) == 'audio' ||
1777
+					substr($header['mimetype'], 0, 5) == 'video' ||
1779 1778
 					$header['mimetype'] == 'multipart/alternative')
1780 1779
 				{
1781
-					$image = Api\Html::image('mail','attach');
1780
+					$image = Api\Html::image('mail', 'attach');
1782 1781
 					$imageHTMLBlock = '';
1783
-					$datarowid = $this->createRowID($_folderName,$message_uid,true);
1782
+					$datarowid = $this->createRowID($_folderName, $message_uid, true);
1784 1783
 					$attachments = $header['attachments'];
1785
-					if (count($attachments)<1)
1784
+					if (count($attachments) < 1)
1786 1785
 					{
1787 1786
 						$image = '&nbsp;';
1788 1787
 					}
1789
-					if (count($attachments)==1)
1788
+					if (count($attachments) == 1)
1790 1789
 					{
1791
-						$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName);
1792
-						$image = Api\Html::image('mail','attach',$attachments[0]['name'].(!empty($attachments[0]['mimeType'])?' ('.$attachments[0]['mimeType'].')':''));
1790
+						$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folderName);
1791
+						$image = Api\Html::image('mail', 'attach', $attachments[0]['name'].(!empty($attachments[0]['mimeType']) ? ' ('.$attachments[0]['mimeType'].')' : ''));
1793 1792
 					}
1794
-					if (count($attachments)>1)
1793
+					if (count($attachments) > 1)
1795 1794
 					{
1796
-						$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'],$_folderName);
1797
-						$image = Api\Html::image('mail','attach',lang('%1 attachments',count($attachments)));
1795
+						$imageHTMLBlock = self::createAttachmentBlock($attachments, $datarowid, $header['uid'], $_folderName);
1796
+						$image = Api\Html::image('mail', 'attach', lang('%1 attachments', count($attachments)));
1798 1797
 					}
1799 1798
 
1800 1799
 					$attachmentFlag = $image;
1801 1800
 				} else {
1802
-					$attachmentFlag ='&nbsp;';
1801
+					$attachmentFlag = '&nbsp;';
1803 1802
 				}
1804 1803
 				// show priority flag
1805 1804
 				if ($header['priority'] < 3) {
1806
-					 $image = Api\Html::image('mail','prio_high');
1805
+					 $image = Api\Html::image('mail', 'prio_high');
1807 1806
 				} elseif ($header['priority'] > 3) {
1808
-					$image = Api\Html::image('mail','prio_low');
1807
+					$image = Api\Html::image('mail', 'prio_low');
1809 1808
 				} else {
1810 1809
 					$image = '';
1811 1810
 				}
1812 1811
 				// show a flag for flagged messages
1813
-				$imageflagged ='';
1812
+				$imageflagged = '';
1814 1813
 				if ($header['flagged'])
1815 1814
 				{
1816
-					$imageflagged = Api\Html::image('mail','unread_flagged_small');
1815
+					$imageflagged = Api\Html::image('mail', 'unread_flagged_small');
1817 1816
 				}
1818 1817
 				$data["attachments"] = $image.$attachmentFlag.$imageflagged; // icon for attachments available
1819 1818
 			}
@@ -1822,7 +1821,7 @@  discard block
 block discarded – undo
1822 1821
 			if (in_array("toaddress", $cols))
1823 1822
 			{
1824 1823
 				// sent or drafts or template folder means foldertype > 0, use to address instead of from
1825
-				$data["toaddress"] = $header['to_address'];//Mail::htmlentities($header['to_address'],$this->charset);
1824
+				$data["toaddress"] = $header['to_address']; //Mail::htmlentities($header['to_address'],$this->charset);
1826 1825
 			}
1827 1826
 
1828 1827
 			if (in_array("additionaltoaddress", $cols))
@@ -1855,29 +1854,29 @@  discard block
 block discarded – undo
1855 1854
 			$data['flags'] = Array();
1856 1855
 			if ($header['seen']) $data["flags"]['read'] = 'read';
1857 1856
 			foreach ($css_styles as &$flag) {
1858
-				if ($flag!='mail')
1857
+				if ($flag != 'mail')
1859 1858
 				{
1860
-					if ($flag=='labelone') {$data["flags"]['label1'] = 'label1';}
1861
-					elseif ($flag=='labeltwo') {$data["flags"]['label2'] = 'label2';}
1862
-					elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';}
1863
-					elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';}
1864
-					elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';}
1865
-					elseif ($flag=='unseen') {unset($data["flags"]['read']);}
1859
+					if ($flag == 'labelone') {$data["flags"]['label1'] = 'label1'; }
1860
+					elseif ($flag == 'labeltwo') {$data["flags"]['label2'] = 'label2'; }
1861
+					elseif ($flag == 'labelthree') {$data["flags"]['label3'] = 'label3'; }
1862
+					elseif ($flag == 'labelfour') {$data["flags"]['label4'] = 'label4'; }
1863
+					elseif ($flag == 'labelfive') {$data["flags"]['label5'] = 'label5'; }
1864
+					elseif ($flag == 'unseen') {unset($data["flags"]['read']); }
1866 1865
 					else $data["flags"][$flag] = $flag;
1867 1866
 				}
1868 1867
 			}
1869 1868
 			if ($header['disposition-notification-to']) $data['dispositionnotificationto'] = $header['disposition-notification-to'];
1870
-			if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']);
1869
+			if (($header['mdnsent'] || $header['mdnnotsent']|$header['seen']) && isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']);
1871 1870
 			$data['attachmentsBlock'] = $imageHTMLBlock;
1872
-			$data['address'] = ($_folderType?$data["toaddress"]:$data["fromaddress"]);
1873
-			if (in_array("bodypreview", $cols)&&$header['bodypreview'])
1871
+			$data['address'] = ($_folderType ? $data["toaddress"] : $data["fromaddress"]);
1872
+			if (in_array("bodypreview", $cols) && $header['bodypreview'])
1874 1873
 			{
1875 1874
 				$data["bodypreview"] = $header['bodypreview'];
1876 1875
 			}
1877 1876
 			$rv[] = $data;
1878 1877
 			//error_log(__METHOD__.__LINE__.array2string($data));
1879 1878
 		}
1880
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName,__METHOD__.__LINE__);
1879
+		if (Mail::$debugTimes) Mail::logRunTimes($starttime, null, 'Folder:'.$_folderName, __METHOD__.__LINE__);
1881 1880
 
1882 1881
 		// ToDo: call this ONLY if labels change
1883 1882
 		Etemplate\Widget::setElementAttribute('toolbar', 'actions', $this->get_toolbar_actions());
@@ -1892,8 +1891,8 @@  discard block
 block discarded – undo
1892 1891
 	 */
1893 1892
 	function displayHeader()
1894 1893
 	{
1895
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
1896
-		if(isset($_GET['part'])) $partID = $_GET['part'];
1894
+		if (isset($_GET['id'])) $rowID = $_GET['id'];
1895
+		if (isset($_GET['part'])) $partID = $_GET['part'];
1897 1896
 
1898 1897
 		$hA = self::splitRowID($rowID);
1899 1898
 		$uid = $hA['msgUID'];
@@ -1907,17 +1906,17 @@  discard block
 block discarded – undo
1907 1906
 		}
1908 1907
 
1909 1908
 		$this->mail_bo->reopen($mailbox);
1910
-		$headers_in	= $this->mail_bo->getMessageRawHeader($uid, $partID);
1909
+		$headers_in = $this->mail_bo->getMessageRawHeader($uid, $partID);
1911 1910
 
1912 1911
 		// add line breaks to $rawheaders
1913
-		$newRawHeaders = explode("\n",$headers_in);
1912
+		$newRawHeaders = explode("\n", $headers_in);
1914 1913
 		reset($newRawHeaders);
1915 1914
 
1916 1915
 		// reset $rawheaders
1917
-		$rawheaders 	= "";
1916
+		$rawheaders = "";
1918 1917
 		// create it new, with good line breaks
1919 1918
 		reset($newRawHeaders);
1920
-		while(list($key,$value) = @each($newRawHeaders)) {
1919
+		while (list($key, $value) = @each($newRawHeaders)) {
1921 1920
 			$rawheaders .= wordwrap($value, 90, "\n     ");
1922 1921
 		}
1923 1922
 
@@ -1929,7 +1928,7 @@  discard block
 block discarded – undo
1929 1928
 		}
1930 1929
 
1931 1930
 		header('Content-type: text/html; charset=iso-8859-1');
1932
-		print '<pre>'. htmlspecialchars($rawheaders, ENT_NOQUOTES, 'iso-8859-1') .'</pre>';
1931
+		print '<pre>'.htmlspecialchars($rawheaders, ENT_NOQUOTES, 'iso-8859-1').'</pre>';
1933 1932
 
1934 1933
 	}
1935 1934
 
@@ -1942,10 +1941,10 @@  discard block
 block discarded – undo
1942 1941
 	{
1943 1942
 		if (is_null($_requesteddata)) $_requesteddata = $_GET;
1944 1943
 
1945
-		$preventRedirect=false;
1946
-		if(isset($_requesteddata['id'])) $rowID	= $_requesteddata['id'];
1947
-		if(isset($_requesteddata['part'])) $partID = $_requesteddata['part']!='null'?$_requesteddata['part']:null;
1948
-		if(isset($_requesteddata['mode'])) $preventRedirect   = (($_requesteddata['mode']=='display' || $_requesteddata['mode'] == 'print')?true:false);
1944
+		$preventRedirect = false;
1945
+		if (isset($_requesteddata['id'])) $rowID = $_requesteddata['id'];
1946
+		if (isset($_requesteddata['part'])) $partID = $_requesteddata['part'] != 'null' ? $_requesteddata['part'] : null;
1947
+		if (isset($_requesteddata['mode'])) $preventRedirect = (($_requesteddata['mode'] == 'display' || $_requesteddata['mode'] == 'print') ? true : false);
1949 1948
 
1950 1949
 		$hA = self::splitRowID($rowID);
1951 1950
 		$uid = $hA['msgUID'];
@@ -1969,79 +1968,79 @@  discard block
 block discarded – undo
1969 1968
 		}
1970 1969
 		if (!$preventRedirect && ($this->mail_bo->isDraftFolder($mailbox) || $this->mail_bo->isTemplateFolder($mailbox)))
1971 1970
 		{
1972
-			Egw::redirect_link('/index.php',array('menuaction'=>'mail.mail_compose.compose','id'=>$rowID,'from'=>'composefromdraft'));
1971
+			Egw::redirect_link('/index.php', array('menuaction'=>'mail.mail_compose.compose', 'id'=>$rowID, 'from'=>'composefromdraft'));
1973 1972
 		}
1974 1973
 		$this->mail_bo->reopen($mailbox);
1975 1974
 		// retrieve the flags of the message, before touching it.
1976 1975
 		try
1977 1976
 		{
1978
-			$headers	= $this->mail_bo->getMessageHeader($uid, $partID,true,true,$mailbox);
1977
+			$headers = $this->mail_bo->getMessageHeader($uid, $partID, true, true, $mailbox);
1979 1978
 		}
1980 1979
 		catch (Api\Exception $e)
1981 1980
 		{
1982 1981
 			$error_msg[] = lang("ERROR: Message could not be displayed.");
1983
-			$error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3",$mailbox,$uid,$partID);
1982
+			$error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3", $mailbox, $uid, $partID);
1984 1983
 			Framework::message($e->getMessage(), 'error');
1985 1984
 		}
1986 1985
 		if (!empty($uid)) $this->mail_bo->getFlags($uid);
1987
-		$envelope	= $this->mail_bo->getMessageEnvelope($uid, $partID,true,$mailbox);
1986
+		$envelope = $this->mail_bo->getMessageEnvelope($uid, $partID, true, $mailbox);
1988 1987
 		//error_log(__METHOD__.__LINE__.array2string($envelope));
1989
-		$this->mail_bo->getMessageRawHeader($uid, $partID,$mailbox);
1988
+		$this->mail_bo->getMessageRawHeader($uid, $partID, $mailbox);
1990 1989
 		$fetchEmbeddedImages = false;
1991 1990
 		// if we are in HTML so its likely that we should show the embedded images; as a result
1992 1991
 		// we do NOT want to see those, that are embedded in the list of attachments
1993
-		if ($htmlOptions !='always_display') $fetchEmbeddedImages = true;
1994
-		$attachments	= $this->mail_bo->getMessageAttachments($uid, $partID, null, $fetchEmbeddedImages,true,true,$mailbox);
1992
+		if ($htmlOptions != 'always_display') $fetchEmbeddedImages = true;
1993
+		$attachments = $this->mail_bo->getMessageAttachments($uid, $partID, null, $fetchEmbeddedImages, true, true, $mailbox);
1995 1994
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
1996 1995
 		$attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox);
1997 1996
 
1998
-		$nonDisplayAbleCharacters = array('[\016]','[\017]',
1999
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2000
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
1997
+		$nonDisplayAbleCharacters = array('[\016]', '[\017]',
1998
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
1999
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2001 2000
 
2002 2001
 		//error_log(__METHOD__.__LINE__.$mailBody);
2003 2002
 		$this->mail_bo->closeConnection();
2004 2003
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
2005 2004
 		$etpl = new Etemplate('mail.display');
2006
-		$subject = $this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false);
2005
+		$subject = $this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters, '', $envelope['SUBJECT']), false);
2007 2006
 
2008 2007
 		// Set up data for taglist widget(s)
2009
-		if ($envelope['FROM']==$envelope['SENDER']) unset($envelope['SENDER']);
2008
+		if ($envelope['FROM'] == $envelope['SENDER']) unset($envelope['SENDER']);
2010 2009
 		$sel_options = array();
2011
-		foreach(array('SENDER','FROM','TO','CC','BCC') as $field)
2010
+		foreach (array('SENDER', 'FROM', 'TO', 'CC', 'BCC') as $field)
2012 2011
 		{
2013 2012
 			if (!isset($envelope[$field])) continue;
2014
-			foreach($envelope[$field] as $field_data)
2013
+			foreach ($envelope[$field] as $field_data)
2015 2014
 			{
2016 2015
 				//error_log(__METHOD__.__LINE__.array2string($field_data));
2017 2016
 				$content[$field][] = $field_data;
2018 2017
 				$sel_options[$field][] = array(
2019 2018
 					// taglist requires these - not optional
2020 2019
 					'id' => $field_data,
2021
-					'label' => str_replace('"',"'",$field_data),
2020
+					'label' => str_replace('"', "'", $field_data),
2022 2021
 				);
2023 2022
 			}
2024 2023
 		}
2025 2024
 		$actionsenabled = $this->getDisplayToolbarActions();
2026 2025
 		$content['displayToolbaractions'] = json_encode($actionsenabled);
2027 2026
 		if (empty($subject)) $subject = lang('no subject');
2028
-		$content['msg'] = (is_array($error_msg)?implode("<br>",$error_msg):$error_msg);
2027
+		$content['msg'] = (is_array($error_msg) ? implode("<br>", $error_msg) : $error_msg);
2029 2028
 		// Send mail ID so we can use it for actions
2030 2029
 		$content['mail_id'] = $rowID;
2031 2030
 		if (!is_array($headers) || !isset($headers['DATE']))
2032 2031
 		{
2033
-			$headers['DATE'] = (is_array($envelope)&&$envelope['DATE']?$envelope['DATE']:'');
2032
+			$headers['DATE'] = (is_array($envelope) && $envelope['DATE'] ? $envelope['DATE'] : '');
2034 2033
 		}
2035
-		$content['mail_displaydate'] = Mail::_strtotime($headers['DATE'],'ts',true);
2034
+		$content['mail_displaydate'] = Mail::_strtotime($headers['DATE'], 'ts', true);
2036 2035
 		$content['mail_displaysubject'] = $subject;
2037
-		$linkData = array('menuaction'=>"mail.mail_ui.loadEmailBody","_messageID"=>$rowID);
2038
-		if (!empty($partID)) $linkData['_partID']=$partID;
2039
-		if ($htmlOptions != $this->mail_bo->htmlOptions) $linkData['_htmloptions']=$htmlOptions;
2040
-		$content['mailDisplayBodySrc'] = Egw::link('/index.php',$linkData);
2036
+		$linkData = array('menuaction'=>"mail.mail_ui.loadEmailBody", "_messageID"=>$rowID);
2037
+		if (!empty($partID)) $linkData['_partID'] = $partID;
2038
+		if ($htmlOptions != $this->mail_bo->htmlOptions) $linkData['_htmloptions'] = $htmlOptions;
2039
+		$content['mailDisplayBodySrc'] = Egw::link('/index.php', $linkData);
2041 2040
 		$content['mail_displayattachments'] = $attachmentHTMLBlock;
2042
-		$content['mail_id']=$rowID;
2043
-		$content['mailDisplayContainerClass']=(count($attachments)?"mailDisplayContainer mailDisplayContainerFixedHeight":"mailDisplayContainer mailDisplayContainerFullHeight");
2044
-		$content['mailDisplayAttachmentsClass']=(count($attachments)?"mailDisplayAttachments":"mail_DisplayNone");
2041
+		$content['mail_id'] = $rowID;
2042
+		$content['mailDisplayContainerClass'] = (count($attachments) ? "mailDisplayContainer mailDisplayContainerFixedHeight" : "mailDisplayContainer mailDisplayContainerFullHeight");
2043
+		$content['mailDisplayAttachmentsClass'] = (count($attachments) ? "mailDisplayAttachments" : "mail_DisplayNone");
2045 2044
 
2046 2045
 		// DRAG attachments actions
2047 2046
 		$etpl->setElementAttribute('mail_displayattachments', 'actions', array(
@@ -2058,22 +2057,22 @@  discard block
 block discarded – undo
2058 2057
 			$this->changeProfile($rememberServerID);
2059 2058
 		}
2060 2059
 
2061
-		$etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2);
2060
+		$etpl->exec('mail.mail_ui.displayMessage', $content, $sel_options, $readonlys, $preserv, 2);
2062 2061
 	}
2063 2062
 
2064 2063
 	/**
2065 2064
 	 * Build actions for display toolbar
2066 2065
 	 */
2067
-	function getDisplayToolbarActions ()
2066
+	function getDisplayToolbarActions()
2068 2067
 	{
2069 2068
 		$actions = $this->get_toolbar_actions();
2070
-		$actions['mark']['children']['flagged']=array(
2069
+		$actions['mark']['children']['flagged'] = array(
2071 2070
 			'group' => $actions['mark']['children']['flagged']['group'],
2072 2071
 			'caption' => 'Flagged',
2073 2072
 			'icon' => 'unread_flagged_small',
2074 2073
 			'onExecute' => 'javaScript:app.mail.mail_flag',
2075 2074
 		);
2076
-		$actions['mark']['children']['unflagged']=array(
2075
+		$actions['mark']['children']['unflagged'] = array(
2077 2076
 			'group' => $actions['mark']['children']['flagged']['group'],
2078 2077
 			'caption' => 'Unflagged',
2079 2078
 			'icon' => 'read_flagged_small',
@@ -2085,9 +2084,9 @@  discard block
 block discarded – undo
2085 2084
 		$compose = $actions['composeasnew'];
2086 2085
 		unset($actions['composeasnew']);
2087 2086
 
2088
-		$actions2 = array_reverse($actions,true);
2089
-		$actions2['composeasnew']= $compose;
2090
-		return array_reverse($actions2,true);
2087
+		$actions2 = array_reverse($actions, true);
2088
+		$actions2['composeasnew'] = $compose;
2089
+		return array_reverse($actions2, true);
2091 2090
 	}
2092 2091
 
2093 2092
 	/**
@@ -2100,22 +2099,22 @@  discard block
 block discarded – undo
2100 2099
 	 * @param boolean $_returnFullHTML flag wether to return HTML or data array
2101 2100
 	 * @return array|string data array or html or empty string
2102 2101
 	 */
2103
-	static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox,$_returnFullHTML=false)
2102
+	static function createAttachmentBlock($attachments, $rowID, $uid, $mailbox, $_returnFullHTML = false)
2104 2103
 	{
2105
-		$attachmentHTMLBlock='';
2104
+		$attachmentHTMLBlock = '';
2106 2105
 		$attachmentHTML = array();
2107 2106
 		if (is_array($attachments) && count($attachments) > 0) {
2108
-			$url_img_vfs = Api\Html::image('filemanager','navbar', lang('Filemanager'), ' height="16"');
2109
-			$url_img_vfs_save_all = Api\Html::image('mail','save_all', lang('Save all'));
2107
+			$url_img_vfs = Api\Html::image('filemanager', 'navbar', lang('Filemanager'), ' height="16"');
2108
+			$url_img_vfs_save_all = Api\Html::image('mail', 'save_all', lang('Save all'));
2110 2109
 
2111 2110
 			foreach ($attachments as $key => $value)
2112 2111
 			{
2113
-				$attachmentHTML[$key]['filename']= ($value['name'] ? ( $value['filename'] ? $value['filename'] : $value['name'] ) : lang('(no subject)'));
2114
-				$attachmentHTML[$key]['filename'] = Api\Translation::convert_jsonsafe($attachmentHTML[$key]['filename'],'utf-8');
2112
+				$attachmentHTML[$key]['filename'] = ($value['name'] ? ($value['filename'] ? $value['filename'] : $value['name']) : lang('(no subject)'));
2113
+				$attachmentHTML[$key]['filename'] = Api\Translation::convert_jsonsafe($attachmentHTML[$key]['filename'], 'utf-8');
2115 2114
 				//error_log(array2string($value));
2116 2115
 				//error_log(strtoupper($value['mimeType']) .'<->'. Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']));
2117
-				if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']);
2118
-				$attachmentHTML[$key]['type']=$value['mimeType'];
2116
+				if (strtoupper($value['mimeType'] == 'APPLICATION/OCTET-STREAM')) $value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']);
2117
+				$attachmentHTML[$key]['type'] = $value['mimeType'];
2119 2118
 				$attachmentHTML[$key]['mimetype'] = Api\MimeMagic::mime2label($value['mimeType']);
2120 2119
 				$hA = self::splitRowID($rowID);
2121 2120
 				$uid = $hA['msgUID'];
@@ -2125,26 +2124,25 @@  discard block
 block discarded – undo
2125 2124
 				$attachmentHTML[$key]['mime_data'] = Link::set_data($value['mimeType'], 'EGroupware\\Api\\Mail::getAttachmentAccount', array(
2126 2125
 					$acc_id, $mailbox, $uid, $value['partID'], $value['is_winmail'], true
2127 2126
 				));
2128
-				$attachmentHTML[$key]['size']=Vfs::hsize($value['size']);
2129
-				$attachmentHTML[$key]['attachment_number']=$key;
2130
-				$attachmentHTML[$key]['partID']=$value['partID'];
2127
+				$attachmentHTML[$key]['size'] = Vfs::hsize($value['size']);
2128
+				$attachmentHTML[$key]['attachment_number'] = $key;
2129
+				$attachmentHTML[$key]['partID'] = $value['partID'];
2131 2130
 				$attachmentHTML[$key]['mail_id'] = $rowID;
2132
-				$attachmentHTML[$key]['winmailFlag']=$value['is_winmail'];
2131
+				$attachmentHTML[$key]['winmailFlag'] = $value['is_winmail'];
2133 2132
 				$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone";
2134 2133
 
2135
-				switch(strtoupper($value['mimeType']))
2134
+				switch (strtoupper($value['mimeType']))
2136 2135
 				{
2137 2136
 					case 'MESSAGE/RFC822':
2138
-						$linkData = array
2139
-						(
2137
+						$linkData = array(
2140 2138
 							'menuaction'	=> 'mail.mail_ui.displayMessage',
2141 2139
 							'mode'		=> 'display', //message/rfc822 attachments should be opened in display mode
2142 2140
 							'id'		=> $rowID,
2143 2141
 							'part'		=> $value['partID'],
2144 2142
 							'is_winmail'    => $value['is_winmail']
2145 2143
 						);
2146
-						$windowName = 'displayMessage_'. $rowID.'_'.$value['partID'];
2147
-						$linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());";
2144
+						$windowName = 'displayMessage_'.$rowID.'_'.$value['partID'];
2145
+						$linkView = "egw_openWindowCentered('".Egw::link('/index.php', $linkData)."','$windowName',700,egw_getWindowOuterHeight());";
2148 2146
 						break;
2149 2147
 					case 'IMAGE/JPEG':
2150 2148
 					case 'IMAGE/PNG':
@@ -2155,7 +2153,7 @@  discard block
 block discarded – undo
2155 2153
 					case 'TEXT/HTML':
2156 2154
 					case 'TEXT/DIRECTORY':
2157 2155
 						$sfxMimeType = $value['mimeType'];
2158
-						$buff = explode('.',$value['name']);
2156
+						$buff = explode('.', $value['name']);
2159 2157
 						$suffix = '';
2160 2158
 						if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
2161 2159
 						if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -2168,49 +2166,47 @@  discard block
 block discarded – undo
2168 2166
 					case 'TEXT/VCARD':
2169 2167
 					case 'TEXT/CALENDAR':
2170 2168
 					case 'TEXT/X-VCALENDAR':
2171
-						$linkData = array
2172
-						(
2169
+						$linkData = array(
2173 2170
 							'menuaction'	=> 'mail.mail_ui.getAttachment',
2174 2171
 							'id'		=> $rowID,
2175 2172
 							'part'		=> $value['partID'],
2176 2173
 							'is_winmail'    => $value['is_winmail'],
2177 2174
 							'mailbox'   => base64_encode($mailbox),
2178 2175
 						);
2179
-						$windowName = 'displayAttachment_'. $uid;
2176
+						$windowName = 'displayAttachment_'.$uid;
2180 2177
 						$reg = '800x600';
2181 2178
 						// handle calendar/vcard
2182
-						if (strtoupper($value['mimeType'])=='TEXT/CALENDAR')
2179
+						if (strtoupper($value['mimeType']) == 'TEXT/CALENDAR')
2183 2180
 						{
2184
-							$windowName = 'displayEvent_'. $rowID;
2185
-							$reg2 = Link::get_registry('calendar','view_popup');
2186
-							$attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg);
2181
+							$windowName = 'displayEvent_'.$rowID;
2182
+							$reg2 = Link::get_registry('calendar', 'view_popup');
2183
+							$attachmentHTML[$key]['popup'] = (!empty($reg2) ? $reg2 : $reg);
2187 2184
 						}
2188
-						if (strtoupper($value['mimeType'])=='TEXT/X-VCARD' || strtoupper($value['mimeType'])=='TEXT/VCARD')
2185
+						if (strtoupper($value['mimeType']) == 'TEXT/X-VCARD' || strtoupper($value['mimeType']) == 'TEXT/VCARD')
2189 2186
 						{
2190
-							$windowName = 'displayContact_'. $rowID;
2191
-							$reg2 = Link::get_registry('addressbook','add_popup');
2192
-							$attachmentHTML[$key]['popup']=(!empty($reg2) ? $reg2 : $reg);
2187
+							$windowName = 'displayContact_'.$rowID;
2188
+							$reg2 = Link::get_registry('addressbook', 'add_popup');
2189
+							$attachmentHTML[$key]['popup'] = (!empty($reg2) ? $reg2 : $reg);
2193 2190
 						}
2194 2191
 						// apply to action
2195
-						list($width,$height) = explode('x',(!empty($reg2) ? $reg2 : $reg));
2196
-						$linkView = "egw_openWindowCentered('".Egw::link('/index.php',$linkData)."','$windowName',$width,$height);";
2192
+						list($width, $height) = explode('x', (!empty($reg2) ? $reg2 : $reg));
2193
+						$linkView = "egw_openWindowCentered('".Egw::link('/index.php', $linkData)."','$windowName',$width,$height);";
2197 2194
 						break;
2198 2195
 					default:
2199
-						$linkData = array
2200
-						(
2196
+						$linkData = array(
2201 2197
 							'menuaction'	=> 'mail.mail_ui.getAttachment',
2202 2198
 							'id'		=> $rowID,
2203 2199
 							'part'		=> $value['partID'],
2204 2200
 							'is_winmail'    => $value['is_winmail'],
2205 2201
 							'mailbox'   => base64_encode($mailbox),
2206 2202
 						);
2207
-						$linkView = "window.location.href = '".Egw::link('/index.php',$linkData)."';";
2203
+						$linkView = "window.location.href = '".Egw::link('/index.php', $linkData)."';";
2208 2204
 						break;
2209 2205
 				}
2210 2206
 				// we either use mime_data for server-side supported mime-types or mime_url for client-side or download
2211 2207
 				if (empty($attachmentHTML[$key]['mime_data']))
2212 2208
 				{
2213
-					$attachmentHTML[$key]['mime_url'] = Egw::link('/index.php',$linkData);
2209
+					$attachmentHTML[$key]['mime_url'] = Egw::link('/index.php', $linkData);
2214 2210
 					unset($attachmentHTML[$key]['mime_data']);
2215 2211
 				}
2216 2212
 				$attachmentHTML[$key]['windowName'] = $windowName;
@@ -2220,8 +2216,7 @@  discard block
 block discarded – undo
2220 2216
 					($value['name'] ? $value['name'] : lang('(no subject)')).
2221 2217
 					'</b></a>';
2222 2218
 
2223
-				$linkData = array
2224
-				(
2219
+				$linkData = array(
2225 2220
 					'menuaction'	=> 'mail.mail_ui.getAttachment',
2226 2221
 					'mode'		=> 'save',
2227 2222
 					'id'		=> $rowID,
@@ -2229,11 +2224,11 @@  discard block
 block discarded – undo
2229 2224
 					'is_winmail'    => $value['is_winmail'],
2230 2225
 					'mailbox'   => base64_encode($mailbox),
2231 2226
 				);
2232
-				$attachmentHTML[$key]['link_save'] ="<a href='".Egw::link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail','fileexport')."</a>";
2227
+				$attachmentHTML[$key]['link_save'] = "<a href='".Egw::link('/index.php', $linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail', 'fileexport')."</a>";
2233 2228
 
2234 2229
 				if ($GLOBALS['egw_info']['user']['apps']['filemanager'])
2235 2230
 				{
2236
-					$link_vfs_save = Egw::link('/index.php',array(
2231
+					$link_vfs_save = Egw::link('/index.php', array(
2237 2232
 						'menuaction' => 'filemanager.filemanager_select.select',
2238 2233
 						'mode' => 'saveas',
2239 2234
 						'name' => $value['name'],
@@ -2252,19 +2247,19 @@  discard block
 block discarded – undo
2252 2247
 							//$rowID
2253 2248
 							$ids["id[$ikey]"] = $rowID.'::'.$value['partID'].'::'.$value['is_winmail'].'::'.$value['name'];
2254 2249
 						}
2255
-						$link_vfs_save = Egw::link('/index.php',array(
2250
+						$link_vfs_save = Egw::link('/index.php', array(
2256 2251
 							'menuaction' => 'filemanager.filemanager_select.select',
2257 2252
 							'mode' => 'select-dir',
2258 2253
 							'method' => 'mail.mail_ui.vfsSaveAttachment',
2259 2254
 							'label' => lang('Save all'),
2260
-						)+$ids);
2255
+						) + $ids);
2261 2256
 						$vfs_save .= "<a href='#' onclick=\"egw_openWindowCentered('$link_vfs_save','vfs_save_attachment','640','530',window.outerWidth/2,window.outerHeight/2); return false;\">$url_img_vfs_save_all</a>";
2262 2257
 					}
2263 2258
 					$attachmentHTML[$key]['link_save'] .= $vfs_save;
2264 2259
 					//error_log(__METHOD__.__LINE__.$attachmentHTML[$key]['link_save']);
2265 2260
 				}
2266 2261
 			}
2267
-			$attachmentHTMLBlock="<table width='100%'>";
2262
+			$attachmentHTMLBlock = "<table width='100%'>";
2268 2263
 			foreach ((array)$attachmentHTML as $row)
2269 2264
 			{
2270 2265
 				$attachmentHTMLBlock .= "<tr><td><div class='useEllipsis'>".$row['link_view'].'</div></td>';
@@ -2282,7 +2277,7 @@  discard block
 block discarded – undo
2282 2277
 				unset($attachmentHTML[$ikey]['link_save']);
2283 2278
 			}
2284 2279
 		}
2285
-		return ($_returnFullHTML?$attachmentHTMLBlock:$attachmentHTML);
2280
+		return ($_returnFullHTML ? $attachmentHTMLBlock : $attachmentHTML);
2286 2281
 	}
2287 2282
 
2288 2283
 	/**
@@ -2293,7 +2288,7 @@  discard block
 block discarded – undo
2293 2288
 	 */
2294 2289
 	function gatherVacation($cachedVacations = array())
2295 2290
 	{
2296
-		$isVacationEnabled = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host||$this->mail_bo->icServer->acc_imap_host);
2291
+		$isVacationEnabled = $this->mail_bo->icServer->acc_sieve_enabled && ($this->mail_bo->icServer->acc_sieve_host || $this->mail_bo->icServer->acc_imap_host);
2297 2292
 		//error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation));
2298 2293
 
2299 2294
 		if ($isVacationEnabled)
@@ -2306,7 +2301,7 @@  discard block
 block discarded – undo
2306 2301
 
2307 2302
 				$cachedVacations = array($sieveServer->acc_id => $vacation) + (array)$cachedVacations;
2308 2303
 				// Set vacation to the instance cache for particular account with expiration of one day
2309
-				Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'vacationNotice'.$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations, 60*60*24);
2304
+				Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'vacationNotice'.$GLOBALS['egw_info']['user']['account_lid'], $cachedVacations, 60 * 60 * 24);
2310 2305
 			}
2311 2306
 			catch (PEAR_Exception $ex)
2312 2307
 			{
@@ -2327,36 +2322,36 @@  discard block
 block discarded – undo
2327 2322
 	function quotaDisplay($_usage, $_limit)
2328 2323
 	{
2329 2324
 
2330
-		if($_limit == 0) {
2331
-			$quotaPercent=100;
2325
+		if ($_limit == 0) {
2326
+			$quotaPercent = 100;
2332 2327
 		} else {
2333
-			$quotaPercent=round(($_usage*100)/$_limit);
2328
+			$quotaPercent = round(($_usage * 100) / $_limit);
2334 2329
 		}
2335 2330
 
2336
-		$quotaLimit=Mail::show_readable_size($_limit*1024);
2337
-		$quotaUsage=Mail::show_readable_size($_usage*1024);
2331
+		$quotaLimit = Mail::show_readable_size($_limit * 1024);
2332
+		$quotaUsage = Mail::show_readable_size($_usage * 1024);
2338 2333
 
2339 2334
 
2340
-		if($quotaPercent > 90 && $_limit>0) {
2341
-			$quotaBG='mail-index_QuotaRed';
2342
-		} elseif($quotaPercent > 80 && $_limit>0) {
2343
-			$quotaBG='mail-index_QuotaYellow';
2335
+		if ($quotaPercent > 90 && $_limit > 0) {
2336
+			$quotaBG = 'mail-index_QuotaRed';
2337
+		} elseif ($quotaPercent > 80 && $_limit > 0) {
2338
+			$quotaBG = 'mail-index_QuotaYellow';
2344 2339
 		} else {
2345
-			$quotaBG='mail-index_QuotaGreen';
2340
+			$quotaBG = 'mail-index_QuotaGreen';
2346 2341
 		}
2347 2342
 
2348
-		if($_limit > 0) {
2349
-			$quotaText = $quotaUsage .'/'.$quotaLimit;
2343
+		if ($_limit > 0) {
2344
+			$quotaText = $quotaUsage.'/'.$quotaLimit;
2350 2345
 		} else {
2351 2346
 			$quotaText = $quotaUsage;
2352 2347
 		}
2353 2348
 
2354
-		if($quotaPercent > 50) {
2349
+		if ($quotaPercent > 50) {
2355 2350
 		} else {
2356 2351
 		}
2357 2352
 		$quota['class'] = $quotaBG;
2358
-		$quota['text'] = lang('Quota: %1',$quotaText);
2359
-		$quota['percent'] = (string)round(($_usage*100)/$_limit);
2353
+		$quota['text'] = lang('Quota: %1', $quotaText);
2354
+		$quota['percent'] = (string)round(($_usage * 100) / $_limit);
2360 2355
 		return $quota;
2361 2356
 	}
2362 2357
 
@@ -2370,12 +2365,12 @@  discard block
 block discarded – undo
2370 2365
 		$uid	= $_GET['uid'];
2371 2366
 		$cid	= base64_decode($_GET['cid']);
2372 2367
 		$partID = urldecode($_GET['partID']);
2373
-		if (!empty($_GET['mailbox'])) $mailbox  = base64_decode($_GET['mailbox']);
2368
+		if (!empty($_GET['mailbox'])) $mailbox = base64_decode($_GET['mailbox']);
2374 2369
 
2375 2370
 		//error_log(__METHOD__.__LINE__.":$uid, $cid, $partID");
2376 2371
 		$this->mail_bo->reopen($mailbox);
2377 2372
 
2378
-		$attachment = $this->mail_bo->getAttachmentByCID($uid, $cid, $partID, true);	// true get contents as stream
2373
+		$attachment = $this->mail_bo->getAttachmentByCID($uid, $cid, $partID, true); // true get contents as stream
2379 2374
 
2380 2375
 		$this->mail_bo->closeConnection();
2381 2376
 
@@ -2383,8 +2378,8 @@  discard block
 block discarded – undo
2383 2378
 
2384 2379
 		if ($attachment)
2385 2380
 		{
2386
-			header("Content-Type: ". $attachment->getType());
2387
-			header('Content-Disposition: inline; filename="'. $attachment->getDispositionParameter('filename') .'"');
2381
+			header("Content-Type: ".$attachment->getType());
2382
+			header('Content-Disposition: inline; filename="'.$attachment->getDispositionParameter('filename').'"');
2388 2383
 			//header("Expires: 0");
2389 2384
 			// the next headers are for IE and SSL
2390 2385
 			//header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
@@ -2402,7 +2397,7 @@  discard block
 block discarded – undo
2402 2397
 
2403 2398
 	function getAttachment()
2404 2399
 	{
2405
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
2400
+		if (isset($_GET['id'])) $rowID = $_GET['id'];
2406 2401
 
2407 2402
 		$hA = self::splitRowID($rowID);
2408 2403
 		$uid = $hA['msgUID'];
@@ -2414,11 +2409,11 @@  discard block
 block discarded – undo
2414 2409
 			//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
2415 2410
 			$this->changeProfile($icServerID);
2416 2411
 		}
2417
-		$part		= $_GET['part'];
2412
+		$part = $_GET['part'];
2418 2413
 		$is_winmail = $_GET['is_winmail'] ? $_GET['is_winmail'] : 0;
2419 2414
 
2420 2415
 		$this->mail_bo->reopen($mailbox);
2421
-		$attachment = $this->mail_bo->getAttachment($uid,$part,$is_winmail,false);
2416
+		$attachment = $this->mail_bo->getAttachment($uid, $part, $is_winmail, false);
2422 2417
 		$this->mail_bo->closeConnection();
2423 2418
 		if ($rememberServerID != $this->mail_bo->profileID)
2424 2419
 		{
@@ -2433,7 +2428,7 @@  discard block
 block discarded – undo
2433 2428
 			if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY' || empty($attachment['type']))
2434 2429
 			{
2435 2430
 				$sfxMimeType = $attachment['type'];
2436
-				$buff = explode('.',$attachment['filename']);
2431
+				$buff = explode('.', $attachment['filename']);
2437 2432
 				$suffix = '';
2438 2433
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
2439 2434
 				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -2445,10 +2440,10 @@  discard block
 block discarded – undo
2445 2440
 			{
2446 2441
 				//error_log(__METHOD__."about to call calendar_ical");
2447 2442
 				$calendar_ical = new calendar_ical();
2448
-				$eventid = $calendar_ical->search($attachment['attachment'],-1);
2443
+				$eventid = $calendar_ical->search($attachment['attachment'], -1);
2449 2444
 				//error_log(__METHOD__.array2string($eventid));
2450 2445
 				if (!$eventid) $eventid = -1;
2451
-				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true,0,'',null,$attachment['charset']);
2446
+				$event = $calendar_ical->importVCal($attachment['attachment'], (is_array($eventid) ? $eventid[0] : $eventid), null, true, 0, '', null, $attachment['charset']);
2452 2447
 				//error_log(__METHOD__.$event);
2453 2448
 				if ((int)$event > 0)
2454 2449
 				{
@@ -2456,7 +2451,7 @@  discard block
 block discarded – undo
2456 2451
 						'menuaction'      => 'calendar.calendar_uiforms.edit',
2457 2452
 						'cal_id'      => $event,
2458 2453
 					);
2459
-					Egw::redirect_link('../index.php',$vars);
2454
+					Egw::redirect_link('../index.php', $vars);
2460 2455
 				}
2461 2456
 				//Import failed, download content anyway
2462 2457
 			}
@@ -2471,13 +2466,13 @@  discard block
 block discarded – undo
2471 2466
 				{
2472 2467
 					$vcard['uid'] = trim($vcard['uid']);
2473 2468
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
2474
-					$contact = $addressbook_vcal->find_contact($vcard,false);
2469
+					$contact = $addressbook_vcal->find_contact($vcard, false);
2475 2470
 				}
2476 2471
 				if (!$contact) $contact = null;
2477 2472
 				// if there are not enough fields in the vcard (or the parser was unable to correctly parse the vcard (as of VERSION:3.0 created by MSO))
2478
-				if ($contact || count($vcard)>2)
2473
+				if ($contact || count($vcard) > 2)
2479 2474
 				{
2480
-					$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true,$attachment['charset']);
2475
+					$contact = $addressbook_vcal->addVCard($attachment['attachment'], (is_array($contact) ? array_shift($contact) : $contact), true, $attachment['charset']);
2481 2476
 				}
2482 2477
 				if ((int)$contact > 0)
2483 2478
 				{
@@ -2485,14 +2480,14 @@  discard block
 block discarded – undo
2485 2480
 						'menuaction'	=> 'addressbook.addressbook_ui.edit',
2486 2481
 						'contact_id'	=> $contact,
2487 2482
 					);
2488
-					Egw::redirect_link('../index.php',$vars);
2483
+					Egw::redirect_link('../index.php', $vars);
2489 2484
 				}
2490 2485
 				//Import failed, download content anyway
2491 2486
 			}
2492 2487
 		}
2493 2488
 		//error_log(__METHOD__.__LINE__.'->'.array2string($attachment));
2494
-		$filename = ($attachment['name']?$attachment['name']:($attachment['filename']?$attachment['filename']:$mailbox.'_uid'.$uid.'_part'.$part));
2495
-		Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size=0, True, $_GET['mode'] == "save");
2489
+		$filename = ($attachment['name'] ? $attachment['name'] : ($attachment['filename'] ? $attachment['filename'] : $mailbox.'_uid'.$uid.'_part'.$part));
2490
+		Api\Header\Content::safe($attachment['attachment'], $filename, $attachment['type'], $size = 0, True, $_GET['mode'] == "save");
2496 2491
 		echo $attachment['attachment'];
2497 2492
 
2498 2493
 		exit();
@@ -2507,9 +2502,9 @@  discard block
 block discarded – undo
2507 2502
 	function saveMessage()
2508 2503
 	{
2509 2504
 		$display = false;
2510
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
2511
-		if(isset($_GET['part'])) $partID = $_GET['part'];
2512
-		if (isset($_GET['location'])&& ($_GET['location']=='display'||$_GET['location']=='filemanager')) $display	= $_GET['location'];
2505
+		if (isset($_GET['id'])) $rowID = $_GET['id'];
2506
+		if (isset($_GET['part'])) $partID = $_GET['part'];
2507
+		if (isset($_GET['location']) && ($_GET['location'] == 'display' || $_GET['location'] == 'filemanager')) $display = $_GET['location'];
2513 2508
 
2514 2509
 		$hA = self::splitRowID($rowID);
2515 2510
 		$uid = $hA['msgUID'];
@@ -2537,14 +2532,14 @@  discard block
 block discarded – undo
2537 2532
 		if (!$display)
2538 2533
 		{
2539 2534
 			$headers = Horde_Mime_Headers::parseHeaders($message);
2540
-			$subject = str_replace('$$','__',Mail::decode_header($headers['SUBJECT']));
2541
-			Api\Header\Content::safe($message, $subject.".eml", $mime='message/rfc822', $size=0, true, true);
2535
+			$subject = str_replace('$$', '__', Mail::decode_header($headers['SUBJECT']));
2536
+			Api\Header\Content::safe($message, $subject.".eml", $mime = 'message/rfc822', $size = 0, true, true);
2542 2537
 			echo $message;
2543 2538
 		}
2544 2539
 		else
2545 2540
 		{
2546
-			Api\Header\Content::safe($message, $subject.".eml", $mime='text/html', $size=0, true, false);
2547
-			print '<pre>'. htmlspecialchars($message, ENT_NOQUOTES|ENT_SUBSTITUTE, 'utf-8') .'</pre>';
2541
+			Api\Header\Content::safe($message, $subject.".eml", $mime = 'text/html', $size = 0, true, false);
2542
+			print '<pre>'.htmlspecialchars($message, ENT_NOQUOTES|ENT_SUBSTITUTE, 'utf-8').'</pre>';
2548 2543
 		}
2549 2544
 	}
2550 2545
 
@@ -2556,18 +2551,18 @@  discard block
 block discarded – undo
2556 2551
 	 * @param boolean $close Return javascript to close the window
2557 2552
 	 * @return string|boolean javascript eg. to close the selector window if $close is true, or success/fail if $close is false
2558 2553
 	 */
2559
-	function vfsSaveMessage($ids,$path, $close = true)
2554
+	function vfsSaveMessage($ids, $path, $close = true)
2560 2555
 	{
2561 2556
 		//error_log(__METHOD__.' IDs:'.array2string($ids).' SaveToPath:'.$path);
2562 2557
 
2563 2558
 		if (is_array($ids) && !Vfs::is_writable($path) || !is_array($ids) && !Vfs::is_writable(dirname($path)))
2564 2559
 		{
2565
-			return 'alert("'.addslashes(lang('%1 is NOT writable by you!',$path)).'"); Egw(window).close();';
2560
+			return 'alert("'.addslashes(lang('%1 is NOT writable by you!', $path)).'"); Egw(window).close();';
2566 2561
 		}
2567 2562
 		Api\Translation::add_app('mail');
2568 2563
 
2569 2564
 		$rememberServerID = $this->mail_bo->profileID;
2570
-		foreach((array)$ids as $id)
2565
+		foreach ((array)$ids as $id)
2571 2566
 		{
2572 2567
 			$hA = self::splitRowID($id);
2573 2568
 			$uid = $hA['msgUID'];
@@ -2578,20 +2573,20 @@  discard block
 block discarded – undo
2578 2573
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
2579 2574
 				$this->changeProfile($icServerID);
2580 2575
 			}
2581
-			$message = $this->mail_bo->getMessageRawBody($uid, $partID='', $mailbox);
2582
-			$err=null;
2583
-			if(Vfs::is_dir($path))
2576
+			$message = $this->mail_bo->getMessageRawBody($uid, $partID = '', $mailbox);
2577
+			$err = null;
2578
+			if (Vfs::is_dir($path))
2584 2579
 			{
2585
-				$headers = $this->mail_bo->getMessageHeader($uid,$partID,true,false,$mailbox);
2586
-				$file = $path . '/'.preg_replace('/[\f\n\t\v\\:*#?<>\|]/',"_",$headers['SUBJECT']).'.eml';
2580
+				$headers = $this->mail_bo->getMessageHeader($uid, $partID, true, false, $mailbox);
2581
+				$file = $path.'/'.preg_replace('/[\f\n\t\v\\:*#?<>\|]/', "_", $headers['SUBJECT']).'.eml';
2587 2582
 			}
2588 2583
 			else
2589 2584
 			{
2590 2585
 				$file = $path;
2591 2586
 			}
2592
-			if (!($fp = Vfs::fopen($file,'wb')) || !fwrite($fp,$message))
2587
+			if (!($fp = Vfs::fopen($file, 'wb')) || !fwrite($fp, $message))
2593 2588
 			{
2594
-				$err .= lang('Error saving %1!',$file);
2589
+				$err .= lang('Error saving %1!', $file);
2595 2590
 				$succeeded = false;
2596 2591
 			}
2597 2592
 			else
@@ -2601,10 +2596,10 @@  discard block
 block discarded – undo
2601 2596
 			if ($fp) fclose($fp);
2602 2597
 			if ($succeeded)
2603 2598
 			{
2604
-				unset($headers['SUBJECT']);//already in filename
2599
+				unset($headers['SUBJECT']); //already in filename
2605 2600
 				$infoSection = Mail::createHeaderInfoSection($headers, 'SUPPRESS', false);
2606
-				$props = array(array('name' => 'comment','val' => $infoSection));
2607
-				Vfs::proppatch($file,$props);
2601
+				$props = array(array('name' => 'comment', 'val' => $infoSection));
2602
+				Vfs::proppatch($file, $props);
2608 2603
 			}
2609 2604
 		}
2610 2605
 		if ($rememberServerID != $this->mail_bo->profileID)
@@ -2613,9 +2608,9 @@  discard block
 block discarded – undo
2613 2608
 			$this->changeProfile($rememberServerID);
2614 2609
 		}
2615 2610
 
2616
-		if($close)
2611
+		if ($close)
2617 2612
 		{
2618
-			Framework::window_close(($err?$err:null));
2613
+			Framework::window_close(($err ? $err : null));
2619 2614
 		}
2620 2615
 		else
2621 2616
 		{
@@ -2630,15 +2625,15 @@  discard block
 block discarded – undo
2630 2625
 	 * @param string $path path in vfs (no Vfs::PREFIX!), only directory for multiple id's ($ids is an array)
2631 2626
 	 * @return string javascript eg. to close the selector window
2632 2627
 	 */
2633
-	function vfsSaveAttachment($ids,$path)
2628
+	function vfsSaveAttachment($ids, $path)
2634 2629
 	{
2635 2630
 		//error_log(__METHOD__.__LINE__.'("'.array2string($ids).'","'.$path."\")');");
2636 2631
 
2637 2632
 		if (is_array($ids) && !Vfs::is_writable($path) || !is_array($ids) && !Vfs::is_writable(dirname($path)))
2638 2633
 		{
2639
-			return 'alert("'.addslashes(lang('%1 is NOT writable by you!',$path)).'"); Egw(window).close();';
2634
+			return 'alert("'.addslashes(lang('%1 is NOT writable by you!', $path)).'"); Egw(window).close();';
2640 2635
 		}
2641
-		$err=null;
2636
+		$err = null;
2642 2637
 		$dupe_count = array();
2643 2638
 		$rememberServerID = $this->mail_bo->profileID;
2644 2639
 
@@ -2648,12 +2643,12 @@  discard block
 block discarded – undo
2648 2643
 		 *
2649 2644
 		 * @return array an array of parameters
2650 2645
 		 */
2651
-		$getParams = function ($id) {
2652
-			list($app,$user,$serverID,$mailbox,$uid,$part,$is_winmail,$name) = explode('::',$id,8);
2653
-			$lId = implode('::',array($app,$user,$serverID,$mailbox,$uid));
2646
+		$getParams = function($id) {
2647
+			list($app, $user, $serverID, $mailbox, $uid, $part, $is_winmail, $name) = explode('::', $id, 8);
2648
+			$lId = implode('::', array($app, $user, $serverID, $mailbox, $uid));
2654 2649
 			$hA = mail_ui::splitRowID($lId);
2655 2650
 			return array(
2656
-				'is_winmail' => $is_winmail == "null" || !$is_winmail?false:$is_winmail,
2651
+				'is_winmail' => $is_winmail == "null" || !$is_winmail ? false : $is_winmail,
2657 2652
 				'user' => $user,
2658 2653
 				'name' => $name,
2659 2654
 				'part' => $part,
@@ -2665,8 +2660,8 @@  discard block
 block discarded – undo
2665 2660
 
2666 2661
 		//Examine the first attachment to see if attachment
2667 2662
 		//is winmail.dat embedded attachments.
2668
-		$isMultipleDownload=is_array($ids);
2669
-		$p = $getParams((is_array($ids)?$ids[0]:$ids));
2663
+		$isMultipleDownload = is_array($ids);
2664
+		$p = $getParams((is_array($ids) ? $ids[0] : $ids));
2670 2665
 		if ($p['is_winmail'])
2671 2666
 		{
2672 2667
 			if ($p['icServer'] && $p['icServer'] != $this->mail_bo->profileID)
@@ -2677,14 +2672,14 @@  discard block
 block discarded – undo
2677 2672
 			// Retrive all embedded attachments at once
2678 2673
 			// avoids to fetch heavy winmail.dat content
2679 2674
 			// for each file.
2680
-			$attachments = $this->mail_bo->getTnefAttachments($p['uid'],$p['part']);
2675
+			$attachments = $this->mail_bo->getTnefAttachments($p['uid'], $p['part']);
2681 2676
 		}
2682 2677
 
2683
-		foreach((array)$ids as $id)
2678
+		foreach ((array)$ids as $id)
2684 2679
 		{
2685 2680
 			$params = $getParams($id);
2686 2681
 			// when downloading a single file, name is not set
2687
-			if (!$params['name']&&isset($_GET['name'])&&!$isMultipleDownload) $params['name'] = $_GET['name'];
2682
+			if (!$params['name'] && isset($_GET['name']) && !$isMultipleDownload) $params['name'] = $_GET['name'];
2688 2683
 			if ($params['icServer'] && $params['icServer'] != $this->mail_bo->profileID)
2689 2684
 			{
2690 2685
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@@ -2702,25 +2697,25 @@  discard block
 block discarded – undo
2702 2697
 			}
2703 2698
 			else
2704 2699
 			{
2705
-				$attachment = $this->mail_bo->getAttachment($params['uid'],$params['part'],$params['is_winmail'],false);
2700
+				$attachment = $this->mail_bo->getAttachment($params['uid'], $params['part'], $params['is_winmail'], false);
2706 2701
 			}
2707 2702
 
2708 2703
 			$file = $params['name'];
2709 2704
 			// when $isMultipleDownload the path holds no filename
2710
-			while(Vfs::file_exists($path.($file && $isMultipleDownload ? '/'.$file : '')))
2705
+			while (Vfs::file_exists($path.($file && $isMultipleDownload ? '/'.$file : '')))
2711 2706
 			{
2712 2707
 				$dupe_count[$params['name']]++;
2713
-				$file = pathinfo($params['name'], PATHINFO_FILENAME) .
2714
-					' ('.($dupe_count[$params['name']] + 1).')' . '.' .
2708
+				$file = pathinfo($params['name'], PATHINFO_FILENAME).
2709
+					' ('.($dupe_count[$params['name']] + 1).')'.'.'.
2715 2710
 					pathinfo($params['name'], PATHINFO_EXTENSION);
2716 2711
 			}
2717 2712
 			$params['name'] = $file;
2718 2713
 			//error_log(__METHOD__.__LINE__.array2string($attachment));
2719 2714
 			// when $isMultipleDownload the path holds no filename
2720
-			if (!($fp = Vfs::fopen($file=$path.($params['name'] && $isMultipleDownload ? '/'.$params['name'] : ''),'wb')) ||
2721
-				!fwrite($fp,$attachment['attachment']))
2715
+			if (!($fp = Vfs::fopen($file = $path.($params['name'] && $isMultipleDownload ? '/'.$params['name'] : ''), 'wb')) ||
2716
+				!fwrite($fp, $attachment['attachment']))
2722 2717
 			{
2723
-				$err .= lang('Error saving %1!',$file);
2718
+				$err .= lang('Error saving %1!', $file);
2724 2719
 			}
2725 2720
 			if ($fp)
2726 2721
 			{
@@ -2733,21 +2728,21 @@  discard block
 block discarded – undo
2733 2728
 			//error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID);
2734 2729
 			$this->changeProfile($rememberServerID);
2735 2730
 		}
2736
-		Framework::window_close(($err?$err:null));
2731
+		Framework::window_close(($err ? $err : null));
2737 2732
 	}
2738 2733
 
2739 2734
 	/**
2740 2735
 	 * Zip all attachments and send to user
2741 2736
 	 * @param string $message_id = null
2742 2737
 	 */
2743
-	function download_zip($message_id=null)
2738
+	function download_zip($message_id = null)
2744 2739
 	{
2745 2740
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
2746 2741
 		// First, get all attachment IDs
2747
-		if(isset($_GET['id'])) $message_id	= $_GET['id'];
2742
+		if (isset($_GET['id'])) $message_id = $_GET['id'];
2748 2743
 		//error_log(__METHOD__.__LINE__.$message_id);
2749 2744
 		$rememberServerID = $this->mail_bo->profileID;
2750
-		if(!is_numeric($message_id))
2745
+		if (!is_numeric($message_id))
2751 2746
 		{
2752 2747
 			$hA = self::splitRowID($message_id);
2753 2748
 			$message_id = $hA['msgUID'];
@@ -2765,30 +2760,30 @@  discard block
 block discarded – undo
2765 2760
 		}
2766 2761
 		// always fetch all, even inline (images)
2767 2762
 		$fetchEmbeddedImages = true;
2768
-		$attachments = $this->mail_bo->getMessageAttachments($message_id,null, null, $fetchEmbeddedImages, true,true,$mailbox);
2763
+		$attachments = $this->mail_bo->getMessageAttachments($message_id, null, null, $fetchEmbeddedImages, true, true, $mailbox);
2769 2764
 		// put them in VFS so they can be zipped
2770
-		$header = $this->mail_bo->getMessageHeader($message_id,'',true,false,$mailbox);
2765
+		$header = $this->mail_bo->getMessageHeader($message_id, '', true, false, $mailbox);
2771 2766
 		//get_home_dir may fetch the users startfolder if set; if not writeable, action will fail. TODO: use temp_dir
2772 2767
 		$homedir = '/home/'.$GLOBALS['egw_info']['user']['account_lid'];
2773
-		$temp_path = $homedir/*Vfs::get_home_dir()*/ . "/.mail_$message_id";
2774
-		if(Vfs::is_dir($temp_path)) Vfs::remove ($temp_path);
2768
+		$temp_path = $homedir/*Vfs::get_home_dir()*/."/.mail_$message_id";
2769
+		if (Vfs::is_dir($temp_path)) Vfs::remove($temp_path);
2775 2770
 
2776 2771
 		// Add subject to path, so it gets used as the file name
2777
-		$path = $temp_path . '/' . ($header['SUBJECT'] ? Vfs::encodePathComponent($header['SUBJECT']) : lang('mail')) .'/';
2778
-		if(!Vfs::mkdir($path, 0700, true))
2772
+		$path = $temp_path.'/'.($header['SUBJECT'] ? Vfs::encodePathComponent($header['SUBJECT']) : lang('mail')).'/';
2773
+		if (!Vfs::mkdir($path, 0700, true))
2779 2774
 		{
2780
-			Framework::message("Unable to open temp directory $path",'error');
2775
+			Framework::message("Unable to open temp directory $path", 'error');
2781 2776
 			return;
2782 2777
 		}
2783 2778
 
2784 2779
 		$file_list = array();
2785 2780
 		$dupe_count = array();
2786 2781
 		$this->mail_bo->reopen($mailbox);
2787
-		if ($attachments[0]['is_winmail'] && $attachments[0]['is_winmail']!='null')
2782
+		if ($attachments[0]['is_winmail'] && $attachments[0]['is_winmail'] != 'null')
2788 2783
 		{
2789
-			$tnefAttachments = $this->mail_bo->getTnefAttachments($message_id, $attachments[0]['partID'],true);
2784
+			$tnefAttachments = $this->mail_bo->getTnefAttachments($message_id, $attachments[0]['partID'], true);
2790 2785
 		}
2791
-		foreach($attachments as $file)
2786
+		foreach ($attachments as $file)
2792 2787
 		{
2793 2788
 			if ($file['is_winmail'])
2794 2789
 			{
@@ -2801,22 +2796,22 @@  discard block
 block discarded – undo
2801 2796
 			}
2802 2797
 			else
2803 2798
 			{
2804
-				$attachment = $this->mail_bo->getAttachment($message_id,$file['partID'],$file['is_winmail'],false,true);
2799
+				$attachment = $this->mail_bo->getAttachment($message_id, $file['partID'], $file['is_winmail'], false, true);
2805 2800
 			}
2806
-			$success=true;
2801
+			$success = true;
2807 2802
 			if (empty($file['filename'])) $file['filename'] = $file['name'];
2808
-			if(in_array($path.$file['filename'], $file_list))
2803
+			if (in_array($path.$file['filename'], $file_list))
2809 2804
 			{
2810 2805
 				$dupe_count[$path.$file['filename']]++;
2811
-				$file['filename'] = pathinfo($file['filename'], PATHINFO_FILENAME) .
2812
-					' ('.($dupe_count[$path.$file['filename']] + 1).')' . '.' .
2806
+				$file['filename'] = pathinfo($file['filename'], PATHINFO_FILENAME).
2807
+					' ('.($dupe_count[$path.$file['filename']] + 1).')'.'.'.
2813 2808
 					pathinfo($file['filename'], PATHINFO_EXTENSION);
2814 2809
 			}
2815
-			if (!($fp = Vfs::fopen($path.$file['filename'],'wb')) ||
2810
+			if (!($fp = Vfs::fopen($path.$file['filename'], 'wb')) ||
2816 2811
 				!(!fseek($attachment['attachment'], 0, SEEK_SET) && stream_copy_to_stream($attachment['attachment'], $fp)))
2817 2812
 			{
2818
-				$success=false;
2819
-				Framework::message("Unable to zip {$file['filename']}",'error');
2813
+				$success = false;
2814
+				Framework::message("Unable to zip {$file['filename']}", 'error');
2820 2815
 			}
2821 2816
 			if ($success) $file_list[] = $path.$file['filename'];
2822 2817
 			if ($fp) fclose($fp);
@@ -2837,7 +2832,7 @@  discard block
 block discarded – undo
2837 2832
 		exit();
2838 2833
 	}
2839 2834
 
2840
-	function get_load_email_data($uid, $partID, $mailbox,$htmlOptions=null)
2835
+	function get_load_email_data($uid, $partID, $mailbox, $htmlOptions = null)
2841 2836
 	{
2842 2837
 		// seems to be needed, as if we open a mail from notification popup that is
2843 2838
 		// located in a different folder, we experience: could not parse message
@@ -2849,19 +2844,19 @@  discard block
 block discarded – undo
2849 2844
 		if (empty($htmlOptions)) $htmlOptions = $this->mail_bo->htmlOptions;
2850 2845
 		// fetching structure now, to supply it to getMessageBody and getMessageAttachment, so it does not get fetched twice
2851 2846
 		$structure = $this->mail_bo->getStructure($uid, $partID, $mailbox, false);
2852
-		$bodyParts	= $this->mail_bo->getMessageBody($uid, ($htmlOptions?$htmlOptions:''), $partID, $structure, false, $mailbox);
2847
+		$bodyParts	= $this->mail_bo->getMessageBody($uid, ($htmlOptions ? $htmlOptions : ''), $partID, $structure, false, $mailbox);
2853 2848
 
2854 2849
 		//error_log(__METHOD__.__LINE__.array2string($bodyParts));
2855 2850
 		// attachments here are only fetched to determine if there is a meeting request
2856 2851
 		// and if. use the appropriate action. so we do not need embedded images
2857 2852
 		$fetchEmbeddedImages = false;
2858
-		$attachments = (array)$this->mail_bo->getMessageAttachments($uid, $partID, $structure, $fetchEmbeddedImages, true,true,$mailbox);
2853
+		$attachments = (array)$this->mail_bo->getMessageAttachments($uid, $partID, $structure, $fetchEmbeddedImages, true, true, $mailbox);
2859 2854
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
2860 2855
 		foreach ($attachments as &$attach)
2861 2856
 		{
2862 2857
 			if (strtolower($attach['mimeType']) == 'text/calendar' &&
2863 2858
 				isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
2864
-				($attachment = $this->mail_bo->getAttachment($uid, $attach['partID'],$attach['is_winmail'],(strtolower($attach['mimeType']) == 'text/calendar'?false:true))))
2859
+				($attachment = $this->mail_bo->getAttachment($uid, $attach['partID'], $attach['is_winmail'], (strtolower($attach['mimeType']) == 'text/calendar' ? false : true))))
2865 2860
 			{
2866 2861
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
2867 2862
 				Api\Cache::setSession('calendar', 'ical', array(
@@ -2872,28 +2867,28 @@  discard block
 block discarded – undo
2872 2867
 				));
2873 2868
 				$this->mail_bo->htmlOptions = $bufferHtmlOptions;
2874 2869
 				Api\Translation::add_app('calendar');
2875
-				return ExecMethod( 'calendar.calendar_uiforms.meeting',
2876
-					array('event'=>null,'msg'=>'','useSession'=>true)
2870
+				return ExecMethod('calendar.calendar_uiforms.meeting',
2871
+					array('event'=>null, 'msg'=>'', 'useSession'=>true)
2877 2872
 				);
2878 2873
 			}
2879 2874
 		}
2880 2875
 		// Compose the content of the frame
2881 2876
 		$frameHtml =
2882 2877
 			$this->get_email_header($this->mail_bo->getStyles($bodyParts)).
2883
-			$this->showBody($this->getdisplayableBody($bodyParts,true,false), false);
2878
+			$this->showBody($this->getdisplayableBody($bodyParts, true, false), false);
2884 2879
 		//IE10 eats away linebreaks preceeded by a whitespace in PRE sections
2885
-		$frameHtml = str_replace(" \r\n","\r\n",$frameHtml);
2880
+		$frameHtml = str_replace(" \r\n", "\r\n", $frameHtml);
2886 2881
 		$this->mail_bo->htmlOptions = $bufferHtmlOptions;
2887 2882
 
2888 2883
 		return $frameHtml;
2889 2884
 	}
2890 2885
 
2891
-	static function get_email_header($additionalStyle='')
2886
+	static function get_email_header($additionalStyle = '')
2892 2887
 	{
2893 2888
 		// egw_info[flags][css] already include <style> tags
2894 2889
 		$GLOBALS['egw_info']['flags']['css'] = preg_replace('|</?style[^>]*>|i', '', $additionalStyle);
2895
-		$GLOBALS['egw_info']['flags']['nofooter']=true;
2896
-		$GLOBALS['egw_info']['flags']['nonavbar']=true;
2890
+		$GLOBALS['egw_info']['flags']['nofooter'] = true;
2891
+		$GLOBALS['egw_info']['flags']['nonavbar'] = true;
2897 2892
 		// do NOT include any default CSS
2898 2893
 		Framework::includeCSS('mail', 'preview', true, true);
2899 2894
 
@@ -2904,35 +2899,35 @@  discard block
 block discarded – undo
2904 2899
 		return $GLOBALS['egw']->framework->header();
2905 2900
 	}
2906 2901
 
2907
-	function showBody(&$body, $print=true,$fullPageTags=true)
2902
+	function showBody(&$body, $print = true, $fullPageTags = true)
2908 2903
 	{
2909 2904
 		$BeginBody = '<div class="mailDisplayBody">
2910 2905
 <table width="100%" style="table-layout:fixed"><tr><td class="td_display">';
2911 2906
 
2912 2907
 		$EndBody = '</td></tr></table></div>';
2913 2908
 		if ($fullPageTags) $EndBody .= "</body></html>";
2914
-		if ($print)	{
2915
-			print $BeginBody. $body .$EndBody;
2909
+		if ($print) {
2910
+			print $BeginBody.$body.$EndBody;
2916 2911
 		} else {
2917
-			return $BeginBody. $body .$EndBody;
2912
+			return $BeginBody.$body.$EndBody;
2918 2913
 		}
2919 2914
 	}
2920 2915
 
2921
-	function &getdisplayableBody($_bodyParts,$modifyURI=true,$useTidy = true)
2916
+	function &getdisplayableBody($_bodyParts, $modifyURI = true, $useTidy = true)
2922 2917
 	{
2923
-		$bodyParts	= $_bodyParts;
2918
+		$bodyParts = $_bodyParts;
2924 2919
 
2925
-		$nonDisplayAbleCharacters = array('[\016]','[\017]',
2926
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2927
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
2920
+		$nonDisplayAbleCharacters = array('[\016]', '[\017]',
2921
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
2922
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2928 2923
 
2929 2924
 		$body = '';
2930 2925
 
2931 2926
 		//error_log(__METHOD__.array2string($bodyParts)); //exit;
2932 2927
 		if (empty($bodyParts)) return "";
2933
-		foreach((array)$bodyParts as $singleBodyPart) {
2928
+		foreach ((array)$bodyParts as $singleBodyPart) {
2934 2929
 			if (!isset($singleBodyPart['body'])) {
2935
-				$singleBodyPart['body'] = $this->getdisplayableBody($singleBodyPart,$modifyURI,$useTidy);
2930
+				$singleBodyPart['body'] = $this->getdisplayableBody($singleBodyPart, $modifyURI, $useTidy);
2936 2931
 				$body .= $singleBodyPart['body'];
2937 2932
 				continue;
2938 2933
 			}
@@ -2942,7 +2937,7 @@  discard block
 block discarded – undo
2942 2937
 				$body .= '';
2943 2938
 				continue;
2944 2939
 			}
2945
-			if(!empty($body)) {
2940
+			if (!empty($body)) {
2946 2941
 				$body .= '<hr style="border:dotted 1px silver;">';
2947 2942
 			}
2948 2943
 			//error_log($singleBodyPart['body']);
@@ -2967,22 +2962,22 @@  discard block
 block discarded – undo
2967 2962
 				'(R)',
2968 2963
 			);
2969 2964
 
2970
-			if(($singleBodyPart['mimeType'] == 'text/html' || $singleBodyPart['mimeType'] == 'text/plain') &&
2965
+			if (($singleBodyPart['mimeType'] == 'text/html' || $singleBodyPart['mimeType'] == 'text/plain') &&
2971 2966
 				strtoupper($singleBodyPart['charSet']) != 'UTF-8')
2972 2967
 			{
2973
-				$singleBodyPart['body'] = preg_replace($sar,$rar,$singleBodyPart['body']);
2968
+				$singleBodyPart['body'] = preg_replace($sar, $rar, $singleBodyPart['body']);
2974 2969
 			}
2975 2970
 			//error_log(__METHOD__.__LINE__.'reports:'.$singleBodyPart['charSet']);
2976
-			$singleBodyPart['body'] = Api\Translation::convert_jsonsafe($singleBodyPart['body'],$singleBodyPart['charSet']);
2971
+			$singleBodyPart['body'] = Api\Translation::convert_jsonsafe($singleBodyPart['body'], $singleBodyPart['charSet']);
2977 2972
 			//error_log(__METHOD__.__LINE__.array2string($singleBodyPart));
2978
-			if($singleBodyPart['mimeType'] == 'text/plain')
2973
+			if ($singleBodyPart['mimeType'] == 'text/plain')
2979 2974
 			{
2980
-				$newBody	= @htmlentities($singleBodyPart['body'],ENT_QUOTES, strtoupper(Mail::$displayCharset));
2975
+				$newBody = @htmlentities($singleBodyPart['body'], ENT_QUOTES, strtoupper(Mail::$displayCharset));
2981 2976
 				//error_log(__METHOD__.__LINE__.'..'.$newBody);
2982 2977
 				// if empty and charset is utf8 try sanitizing the string in question
2983
-				if (empty($newBody) && strtolower($singleBodyPart['charSet'])=='utf-8') $newBody = @htmlentities(iconv('utf-8', 'utf-8', $singleBodyPart['body']),ENT_QUOTES, strtoupper(Mail::$displayCharset));
2978
+				if (empty($newBody) && strtolower($singleBodyPart['charSet']) == 'utf-8') $newBody = @htmlentities(iconv('utf-8', 'utf-8', $singleBodyPart['body']), ENT_QUOTES, strtoupper(Mail::$displayCharset));
2984 2979
 				// if the conversion to htmlentities fails somehow, try without specifying the charset, which defaults to iso-
2985
-				if (empty($newBody)) $newBody    = htmlentities($singleBodyPart['body'],ENT_QUOTES);
2980
+				if (empty($newBody)) $newBody = htmlentities($singleBodyPart['body'], ENT_QUOTES);
2986 2981
 
2987 2982
 				// search http[s] links and make them as links available again
2988 2983
 				// to understand what's going on here, have a look at
@@ -3010,20 +3005,20 @@  discard block
 block discarded – undo
3010 3005
 				// since we do not display the message as HTML anymore we may want to insert good linebreaking (for visibility).
3011 3006
 				//error_log(__METHOD__.__LINE__.'..'.$newBody);
3012 3007
 				// dont break lines that start with > (&gt; as the text was processed with htmlentities before)
3013
-				$newBody	= "<pre>".Mail::wordwrap($newBody,90,"\n",'&gt;')."</pre>";
3008
+				$newBody = "<pre>".Mail::wordwrap($newBody, 90, "\n", '&gt;')."</pre>";
3014 3009
 			}
3015 3010
 			else
3016 3011
 			{
3017
-				$alreadyHtmlLawed=false;
3018
-				$newBody	= $singleBodyPart['body'];
3012
+				$alreadyHtmlLawed = false;
3013
+				$newBody = $singleBodyPart['body'];
3019 3014
 				//TODO:$newBody	= $this->highlightQuotes($newBody);
3020 3015
 				#error_log(print_r($newBody,true));
3021 3016
 				if ($useTidy && extension_loaded('tidy'))
3022 3017
 				{
3023 3018
 					$tidy = new tidy();
3024
-					$cleaned = $tidy->repairString($newBody, Mail::$tidy_config,'utf8');
3019
+					$cleaned = $tidy->repairString($newBody, Mail::$tidy_config, 'utf8');
3025 3020
 					// Found errors. Strip it all so there's some output
3026
-					if($tidy->getStatus() == 2)
3021
+					if ($tidy->getStatus() == 2)
3027 3022
 					{
3028 3023
 						error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
3029 3024
 					}
@@ -3034,7 +3029,7 @@  discard block
 block discarded – undo
3034 3029
 					if (!$preserveHTML)	// ToDo KL: $preserveHTML is NOT initialised, so always if is dead code
3035 3030
 					{
3036 3031
 						// filter only the 'body', as we only want that part, if we throw away the Api\Html
3037
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3032
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
3038 3033
 						if ($matches[2])
3039 3034
 						{
3040 3035
 							$hasOther = true;
@@ -3045,7 +3040,7 @@  discard block
 block discarded – undo
3045 3040
 				else
3046 3041
 				{
3047 3042
 					// htmLawed filter only the 'body'
3048
-					preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3043
+					preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
3049 3044
 					if ($matches[2])
3050 3045
 					{
3051 3046
 						$hasOther = true;
@@ -3054,10 +3049,10 @@  discard block
 block discarded – undo
3054 3049
 					$htmLawed = new Api\Html\HtmLawed();
3055 3050
 					// the next line should not be needed, but produces better results on HTML 2 Text conversion,
3056 3051
 					// as we switched off HTMLaweds tidy functionality
3057
-					$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
3058
-					$newBody = $htmLawed->run($newBody,Mail::$htmLawed_config);
3059
-					if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
3060
-					$alreadyHtmlLawed=true;
3052
+					$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
3053
+					$newBody = $htmLawed->run($newBody, Mail::$htmLawed_config);
3054
+					if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
3055
+					$alreadyHtmlLawed = true;
3061 3056
 				}
3062 3057
 				// do the cleanup, set for the use of purifier
3063 3058
 				//$newBodyBuff = $newBody;
@@ -3079,8 +3074,8 @@  discard block
 block discarded – undo
3079 3074
 				}
3080 3075
 */
3081 3076
 				// removes stuff between http and ?http
3082
-				$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))';    // only http:// gets removed, other protocolls are shown
3083
-				$newBody = preg_replace('~'.$Protocol.'[^>]*\?'.$Protocol.'~sim','$1',$newBody); // removes stuff between http:// and ?http://
3077
+				$Protocol = '(http:\/\/|(ftp:\/\/|https:\/\/))'; // only http:// gets removed, other protocolls are shown
3078
+				$newBody = preg_replace('~'.$Protocol.'[^>]*\?'.$Protocol.'~sim', '$1', $newBody); // removes stuff between http:// and ?http://
3084 3079
 				// TRANSFORM MAILTO LINKS TO EMAILADDRESS ONLY, WILL BE SUBSTITUTED BY parseEmail TO CLICKABLE LINK
3085 3080
 				$newBody = preg_replace('/(?<!"|href=|href\s=\s|href=\s|href\s=)'.'mailto:([a-z0-9._-]+)@([a-z0-9_-]+)\.([a-z0-9._-]+)/i',
3086 3081
 					"\\1@\\2.\\3",
@@ -3093,7 +3088,7 @@  discard block
 block discarded – undo
3093 3088
 				// create links for inline images
3094 3089
 				if ($modifyURI)
3095 3090
 				{
3096
-					$newBody = self::resolve_inline_images ($newBody, $this->mailbox, $this->uid, $this->partID);
3091
+					$newBody = self::resolve_inline_images($newBody, $this->mailbox, $this->uid, $this->partID);
3097 3092
 				}
3098 3093
 				// email addresses / mailto links get now activated on client-side
3099 3094
 			}
@@ -3105,7 +3100,7 @@  discard block
 block discarded – undo
3105 3100
 		$body = preg_replace("/(\\\\\\\\)([\w,\\\\,-]+)/i",
3106 3101
 			"<a href=\"file:$1$2\" target=\"_blank\"><font color=\"blue\">$1$2</font></a>", $body);
3107 3102
 
3108
-		$body = preg_replace($nonDisplayAbleCharacters,'',$body);
3103
+		$body = preg_replace($nonDisplayAbleCharacters, '', $body);
3109 3104
 
3110 3105
 		return $body;
3111 3106
 	}
@@ -3120,7 +3115,7 @@  discard block
 block discarded – undo
3120 3115
 	 * @param string $_messageType = 'html', message type is either html or plain
3121 3116
 	 * @return string message body including all CID images replaced
3122 3117
 	 */
3123
-	public static function resolve_inline_images ($_body,$_mailbox, $_uid, $_partID, $_messageType = 'html')
3118
+	public static function resolve_inline_images($_body, $_mailbox, $_uid, $_partID, $_messageType = 'html')
3124 3119
 	{
3125 3120
 		if ($_messageType === 'plain')
3126 3121
 		{
@@ -3128,7 +3123,7 @@  discard block
 block discarded – undo
3128 3123
 		}
3129 3124
 		else
3130 3125
 		{
3131
-			foreach(array('src','url','background') as $type)
3126
+			foreach (array('src', 'url', 'background') as $type)
3132 3127
 			{
3133 3128
 				$_body = self::resolve_inline_image_byType($_body, $_mailbox, $_uid, $_partID, $type);
3134 3129
 			}
@@ -3147,7 +3142,7 @@  discard block
 block discarded – undo
3147 3142
 	 *	- types: {plain|src|url|background}
3148 3143
 	 * @return string returns body content including all CID replacements
3149 3144
 	 */
3150
-	public static function resolve_inline_image_byType ($_body,$_mailbox, $_uid, $_partID, $_type ='src')
3145
+	public static function resolve_inline_image_byType($_body, $_mailbox, $_uid, $_partID, $_type = 'src')
3151 3146
 	{
3152 3147
 		/**
3153 3148
 		 * Callback for preg_replace_callback function
@@ -3159,7 +3154,7 @@  discard block
 block discarded – undo
3159 3154
 		 * @param string $_type
3160 3155
 		 * @return string|boolean returns the replace
3161 3156
 		*/
3162
-		$replace_callback = function ($matches) use ($_mailbox,$_uid, $_partID,  $_type)
3157
+		$replace_callback = function($matches) use ($_mailbox, $_uid, $_partID, $_type)
3163 3158
 		{
3164 3159
 			if (!$_type)	return false;
3165 3160
 			$CID = '';
@@ -3181,11 +3176,11 @@  discard block
 block discarded – undo
3181 3176
 					break;
3182 3177
 			}
3183 3178
 
3184
-			static $cache = array();	// some caching, if mails containing the same image multiple times
3179
+			static $cache = array(); // some caching, if mails containing the same image multiple times
3185 3180
 
3186 3181
 			if (is_array($matches) && $CID)
3187 3182
 			{
3188
-				$linkData = array (
3183
+				$linkData = array(
3189 3184
 					'menuaction'    => 'mail.mail_ui.displayImage',
3190 3185
 					'uid'		=> $_uid,
3191 3186
 					'mailbox'	=> base64_encode($_mailbox),
@@ -3198,7 +3193,7 @@  discard block
 block discarded – undo
3198 3193
 				{
3199 3194
 					if (!isset($cache[$imageURL]))
3200 3195
 					{
3201
-						if ($_type !="background")
3196
+						if ($_type != "background")
3202 3197
 						{
3203 3198
 							$bo = Mail::getInstance(false, mail_ui::$icServerID);
3204 3199
 							$attachment = $bo->getAttachmentByCID($_uid, $CID, $_partID);
@@ -3239,16 +3234,16 @@  discard block
 block discarded – undo
3239 3234
 		};
3240 3235
 
3241 3236
 		// return new body content base on chosen type
3242
-		switch($_type)
3237
+		switch ($_type)
3243 3238
 		{
3244 3239
 			case"plain":
3245
-				return preg_replace_callback("/\[cid:(.*)\]/iU",$replace_callback,$_body);
3240
+				return preg_replace_callback("/\[cid:(.*)\]/iU", $replace_callback, $_body);
3246 3241
 			case "src":
3247
-				return preg_replace_callback("/src=(\"|\')cid:(.*)(\"|\')/iU",$replace_callback,$_body);
3242
+				return preg_replace_callback("/src=(\"|\')cid:(.*)(\"|\')/iU", $replace_callback, $_body);
3248 3243
 			case "url":
3249
-				return preg_replace_callback("/url\(cid:(.*)\);/iU",$replace_callback,$_body);
3244
+				return preg_replace_callback("/url\(cid:(.*)\);/iU", $replace_callback, $_body);
3250 3245
 			case "background":
3251
-				return preg_replace_callback("/background=(\"|\')cid:(.*)(\"|\')/iU",$replace_callback,$_body);
3246
+				return preg_replace_callback("/background=(\"|\')cid:(.*)(\"|\')/iU", $replace_callback, $_body);
3252 3247
 		}
3253 3248
 	}
3254 3249
 
@@ -3256,7 +3251,7 @@  discard block
 block discarded – undo
3256 3251
 	 * importMessage
3257 3252
 	 * @param array $content = null an array of content
3258 3253
 	 */
3259
-	function importMessage($content=null)
3254
+	function importMessage($content = null)
3260 3255
 	{
3261 3256
 		//error_log(__METHOD__.__LINE__.$this->mail_bo->getDraftFolder());
3262 3257
 
@@ -3278,7 +3273,7 @@  discard block
 block discarded – undo
3278 3273
 			}
3279 3274
 			$destination = $content['FOLDER'][0];
3280 3275
 
3281
-			if (stripos($destination,self::$delimiter)!==false) list($icServerID,$destination) = explode(self::$delimiter,$destination,2);
3276
+			if (stripos($destination, self::$delimiter) !== false) list($icServerID, $destination) = explode(self::$delimiter, $destination, 2);
3282 3277
 			if ($icServerID && $icServerID != $this->mail_bo->profileID)
3283 3278
 			{
3284 3279
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@@ -3289,32 +3284,31 @@  discard block
 block discarded – undo
3289 3284
 			$importFailed = false;
3290 3285
 			try
3291 3286
 			{
3292
-				$messageUid = $this->importMessageToFolder($file,$destination,$importID);
3293
-			    $linkData = array
3294
-			    (
3287
+				$messageUid = $this->importMessageToFolder($file, $destination, $importID);
3288
+			    $linkData = array(
3295 3289
 					'id' => $this->createRowID($destination, $messageUid, true),
3296 3290
 			    );
3297 3291
 			}
3298 3292
 			catch (Api\Exception\WrongUserinput $e)
3299 3293
 			{
3300
-					$importFailed=true;
3301
-					$content['msg']		= $e->getMessage();
3294
+					$importFailed = true;
3295
+					$content['msg'] = $e->getMessage();
3302 3296
 			}
3303 3297
 			if (!$importFailed)
3304 3298
 			{
3305 3299
 				list($width, $height) = explode('x', Link::get_registry('mail', 'add_popup'));
3306 3300
 				if ($width > 0 && $height > 0) Api\Json\Response::get()->call('resizeTo', $width, $height);
3307
-				ExecMethod2('mail.mail_ui.displayMessage',$linkData);
3301
+				ExecMethod2('mail.mail_ui.displayMessage', $linkData);
3308 3302
 				return;
3309 3303
 			}
3310 3304
 		}
3311 3305
 		if (!is_array($content)) $content = array();
3312
-		if (empty($content['FOLDER'])) $content['FOLDER']=(array)$this->mail_bo->getDraftFolder();
3313
-		if (!empty($content['FOLDER'])) $sel_options['FOLDER']=mail_compose::ajax_searchFolder(0,true);
3306
+		if (empty($content['FOLDER'])) $content['FOLDER'] = (array)$this->mail_bo->getDraftFolder();
3307
+		if (!empty($content['FOLDER'])) $sel_options['FOLDER'] = mail_compose::ajax_searchFolder(0, true);
3314 3308
 
3315 3309
 		$etpl = new Etemplate('mail.importMessage');
3316
-		$etpl->setElementAttribute('uploadForImport','onFinish','app.mail.uploadForImport');
3317
-		$etpl->exec('mail.mail_ui.importMessage',$content,$sel_options,array(),array(),2);
3310
+		$etpl->setElementAttribute('uploadForImport', 'onFinish', 'app.mail.uploadForImport');
3311
+		$etpl->exec('mail.mail_ui.importMessage', $content, $sel_options, array(), array(), 2);
3318 3312
 	}
3319 3313
 
3320 3314
 	/**
@@ -3326,7 +3320,7 @@  discard block
 block discarded – undo
3326 3320
 	 * @param string $importID ID for the imported message, used by attachments to identify them unambiguously
3327 3321
 	 * @return mixed $messageUID or exception
3328 3322
 	 */
3329
-	function importMessageToFolder($_formData,&$_folder,$importID='')
3323
+	function importMessageToFolder($_formData, &$_folder, $importID = '')
3330 3324
 	{
3331 3325
 		$importfailed = false;
3332 3326
 		//error_log(__METHOD__.__LINE__.array2string($_formData));
@@ -3334,7 +3328,7 @@  discard block
 block discarded – undo
3334 3328
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
3335 3329
 		try
3336 3330
 		{
3337
-			$tmpFileName = Mail::checkFileBasics($_formData,$importID);
3331
+			$tmpFileName = Mail::checkFileBasics($_formData, $importID);
3338 3332
 		}
3339 3333
 		catch (Api\Exception\WrongUserinput $e)
3340 3334
 		{
@@ -3358,29 +3352,29 @@  discard block
 block discarded – undo
3358 3352
 			if (empty($_folder))
3359 3353
 			{
3360 3354
 				$importfailed = true;
3361
-				$alert_msg .= lang("Import of message %1 failed. Destination Folder not set.",$_formData['name']);
3355
+				$alert_msg .= lang("Import of message %1 failed. Destination Folder not set.", $_formData['name']);
3362 3356
 			}
3363 3357
 			$delimiter = $this->mail_bo->getHierarchyDelimiter();
3364
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
3358
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
3365 3359
 			if ($importfailed === false)
3366 3360
 			{
3367
-				if ($this->mail_bo->folderExists($_folder,true)) {
3361
+				if ($this->mail_bo->folderExists($_folder, true)) {
3368 3362
 					try
3369 3363
 					{
3370 3364
 						$messageUid = $this->mail_bo->appendMessage($_folder,
3371 3365
 							$mailObject->getRaw(),
3372
-							null,'\\Seen');
3366
+							null, '\\Seen');
3373 3367
 					}
3374 3368
 					catch (Api\Exception\WrongUserinput $e)
3375 3369
 					{
3376 3370
 						$importfailed = true;
3377
-						$alert_msg .= lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$_formData['name'],$_folder,$e->getMessage());
3371
+						$alert_msg .= lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $_formData['name'], $_folder, $e->getMessage());
3378 3372
 					}
3379 3373
 				}
3380 3374
 				else
3381 3375
 				{
3382 3376
 					$importfailed = true;
3383
-					$alert_msg .= lang("Import of message %1 failed. Destination Folder %2 does not exist.",$_formData['name'],$_folder);
3377
+					$alert_msg .= lang("Import of message %1 failed. Destination Folder %2 does not exist.", $_formData['name'], $_folder);
3384 3378
 				}
3385 3379
 			}
3386 3380
 		}
@@ -3406,9 +3400,9 @@  discard block
 block discarded – undo
3406 3400
 	 *								 $formData['size']	= 2136;
3407 3401
 	 * @return void
3408 3402
 	 */
3409
-	function importMessageFromVFS2DraftAndEdit($formData='')
3403
+	function importMessageFromVFS2DraftAndEdit($formData = '')
3410 3404
 	{
3411
-		$this->importMessageFromVFS2DraftAndDisplay($formData,'edit');
3405
+		$this->importMessageFromVFS2DraftAndDisplay($formData, 'edit');
3412 3406
 	}
3413 3407
 
3414 3408
 	/**
@@ -3423,7 +3417,7 @@  discard block
 block discarded – undo
3423 3417
 	 * @param string $mode mode to open ImportedMessage display and edit are supported
3424 3418
 	 * @return void
3425 3419
 	 */
3426
-	function importMessageFromVFS2DraftAndDisplay($formData='',$mode='display')
3420
+	function importMessageFromVFS2DraftAndDisplay($formData = '', $mode = 'display')
3427 3421
 	{
3428 3422
 		if (empty($formData)) if (isset($_REQUEST['formData'])) $formData = $_REQUEST['formData'];
3429 3423
 		//error_log(__METHOD__.__LINE__.':'.array2string($formData).' Mode:'.$mode.'->'.function_backtrace());
@@ -3436,43 +3430,42 @@  discard block
 block discarded – undo
3436 3430
 			$formData['file'] = 'egw-data://'.$formData['data'];
3437 3431
 		}
3438 3432
 		// name should be set to meet the requirements of checkFileBasics
3439
-		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && empty($formData['name']))
3433
+		if (parse_url($formData['file'], PHP_URL_SCHEME) == 'vfs' && empty($formData['name']))
3440 3434
 		{
3441
-			$buff = explode('/',$formData['file']);
3435
+			$buff = explode('/', $formData['file']);
3442 3436
 			if (is_array($buff)) $formData['name'] = array_pop($buff); // take the last part as name
3443 3437
 		}
3444 3438
 		// type should be set to meet the requirements of checkFileBasics
3445
-		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && empty($formData['type']))
3439
+		if (parse_url($formData['file'], PHP_URL_SCHEME) == 'vfs' && empty($formData['type']))
3446 3440
 		{
3447
-			$buff = explode('.',$formData['file']);
3441
+			$buff = explode('.', $formData['file']);
3448 3442
 			$suffix = '';
3449 3443
 			if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
3450 3444
 			if (!empty($suffix)) $formData['type'] = Api\MimeMagic::ext2mime($suffix);
3451 3445
 		}
3452 3446
 		// size should be set to meet the requirements of checkFileBasics
3453
-		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && !isset($formData['size']))
3447
+		if (parse_url($formData['file'], PHP_URL_SCHEME) == 'vfs' && !isset($formData['size']))
3454 3448
 		{
3455 3449
 			$formData['size'] = strlen($formData['file']); // set some size, to meet requirements of checkFileBasics
3456 3450
 		}
3457 3451
 		try
3458 3452
 		{
3459
-			$messageUid = $this->importMessageToFolder($formData,$draftFolder,$importID);
3460
-			$linkData = array
3461
-			(
3462
-		        'menuaction'    => ($mode=='display'?'mail.mail_ui.displayMessage':'mail.mail_compose.composeFromDraft'),
3463
-				'id'		=> $this->createRowID($draftFolder,$messageUid,true),
3453
+			$messageUid = $this->importMessageToFolder($formData, $draftFolder, $importID);
3454
+			$linkData = array(
3455
+		        'menuaction'    => ($mode == 'display' ? 'mail.mail_ui.displayMessage' : 'mail.mail_compose.composeFromDraft'),
3456
+				'id'		=> $this->createRowID($draftFolder, $messageUid, true),
3464 3457
 				'deleteDraftOnClose' => 1,
3465 3458
 			);
3466
-			if ($mode!='display')
3459
+			if ($mode != 'display')
3467 3460
 			{
3468 3461
 				unset($linkData['deleteDraftOnClose']);
3469
-				$linkData['method']	='importMessageToMergeAndSend';
3462
+				$linkData['method'] = 'importMessageToMergeAndSend';
3470 3463
 			}
3471 3464
 			else
3472 3465
 			{
3473
-				$linkData['mode']=$mode;
3466
+				$linkData['mode'] = $mode;
3474 3467
 			}
3475
-			Egw::redirect_link('/index.php',$linkData);
3468
+			Egw::redirect_link('/index.php', $linkData);
3476 3469
 		}
3477 3470
 		catch (Api\Exception\WrongUserinput $e)
3478 3471
 		{
@@ -3487,13 +3480,13 @@  discard block
 block discarded – undo
3487 3480
 	 *
3488 3481
 	 * @return xajax response
3489 3482
 	 */
3490
-	function loadEmailBody($_messageID=null,$_partID=null,$_htmloptions=null)
3483
+	function loadEmailBody($_messageID = null, $_partID = null, $_htmloptions = null)
3491 3484
 	{
3492 3485
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
3493 3486
 		if (!$_messageID && !empty($_GET['_messageID'])) $_messageID = $_GET['_messageID'];
3494 3487
 		if (!$_partID && !empty($_GET['_partID'])) $_partID = $_GET['_partID'];
3495 3488
 		if (!$_htmloptions && !empty($_GET['_htmloptions'])) $_htmloptions = $_GET['_htmloptions'];
3496
-		if(Mail::$debug) error_log(__METHOD__."->".print_r($_messageID,true).",$_partID,$_htmloptions");
3489
+		if (Mail::$debug) error_log(__METHOD__."->".print_r($_messageID, true).",$_partID,$_htmloptions");
3497 3490
 		if (empty($_messageID)) return "";
3498 3491
 		$uidA = self::splitRowID($_messageID);
3499 3492
 		$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
@@ -3507,7 +3500,7 @@  discard block
 block discarded – undo
3507 3500
 			$this->changeProfile($icServerID);
3508 3501
 		}
3509 3502
 
3510
-		$bodyResponse = $this->get_load_email_data($messageID,$_partID,$folder,$_htmloptions);
3503
+		$bodyResponse = $this->get_load_email_data($messageID, $_partID, $folder, $_htmloptions);
3511 3504
 		Api\Session::cache_control(true);
3512 3505
 		//error_log(array2string($bodyResponse));
3513 3506
 		echo $bodyResponse;
@@ -3530,7 +3523,7 @@  discard block
 block discarded – undo
3530 3523
 			$oA = array();
3531 3524
 			foreach ($_folder as $_folderName)
3532 3525
 			{
3533
-				list($profileID,$folderName) = explode(self::$delimiter,$_folderName,2);
3526
+				list($profileID, $folderName) = explode(self::$delimiter, $_folderName, 2);
3534 3527
 				if (is_numeric($profileID))
3535 3528
 				{
3536 3529
 					if ($profileID != $this->mail_bo->profileID) continue; // only current connection
@@ -3538,19 +3531,19 @@  discard block
 block discarded – undo
3538 3531
 					{
3539 3532
 						try
3540 3533
 						{
3541
-							$fS = $this->mail_bo->getFolderStatus($folderName,false,false,false);
3534
+							$fS = $this->mail_bo->getFolderStatus($folderName, false, false, false);
3542 3535
 						}
3543 3536
 						catch (Exception $e)
3544 3537
 						{
3545 3538
 							continue;
3546 3539
 						}
3547
-						if (in_array($fS['shortDisplayName'],Mail::$autoFolders)) $fS['shortDisplayName']=lang($fS['shortDisplayName']);
3540
+						if (in_array($fS['shortDisplayName'], Mail::$autoFolders)) $fS['shortDisplayName'] = lang($fS['shortDisplayName']);
3548 3541
 						//error_log(__METHOD__.__LINE__.array2string($fS));
3549 3542
 						if ($fS['unseen'])
3550 3543
 						{
3551 3544
 							$oA[$_folderName] = $fS['shortDisplayName'].' ('.$fS['unseen'].')';
3552 3545
 						}
3553
-						if ($fS['unseen']==0 && $fS['shortDisplayName'])
3546
+						if ($fS['unseen'] == 0 && $fS['shortDisplayName'])
3554 3547
 						{
3555 3548
 							$oA[$_folderName] = $fS['shortDisplayName'];
3556 3549
 						}
@@ -3561,7 +3554,7 @@  discard block
 block discarded – undo
3561 3554
 			if ($oA)
3562 3555
 			{
3563 3556
 				$response = Api\Json\Response::get();
3564
-				$response->call('app.mail.mail_setFolderStatus',$oA);
3557
+				$response->call('app.mail.mail_setFolderStatus', $oA);
3565 3558
 			}
3566 3559
 		}
3567 3560
 	}
@@ -3575,14 +3568,14 @@  discard block
 block discarded – undo
3575 3568
 	function ajax_addFolder($_parentFolderName, $_newName)
3576 3569
 	{
3577 3570
 		//error_log(__METHOD__.__LINE__.' ParentFolderName:'.array2string($_parentFolderName).' NewName/Folder:'.array2string($_newName));
3578
-		$errorMessage='';
3571
+		$errorMessage = '';
3579 3572
 		if ($_parentFolderName)
3580 3573
 		{
3581 3574
 			$created = false;
3582 3575
 			$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_parentFolderName);
3583 3576
 			//the conversion is handeled by horde, frontend interaction is all utf-8
3584 3577
 			$_newName = $this->mail_bo->decodeEntityFolderName($_newName);
3585
-			list($profileID,$parentFolderName) = explode(self::$delimiter,$decodedFolderName,2);
3578
+			list($profileID, $parentFolderName) = explode(self::$delimiter, $decodedFolderName, 2);
3586 3579
 			if (is_numeric($profileID))
3587 3580
 			{
3588 3581
 				if ($profileID != $this->mail_bo->profileID) return; // only current connection
@@ -3622,10 +3615,10 @@  discard block
 block discarded – undo
3622 3615
 
3623 3616
 				if (empty($del)) $del = $this->mail_bo->getHierarchyDelimiter(false);
3624 3617
 				*/
3625
-				$nA = explode($del,$_newName);
3618
+				$nA = explode($del, $_newName);
3626 3619
 
3627 3620
 				//error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName");
3628
-				if (!!empty($parentFolderName)) $oldFolderInfo = $this->mail_bo->getFolderStatus($parentFolderName,false);
3621
+				if (!!empty($parentFolderName)) $oldFolderInfo = $this->mail_bo->getFolderStatus($parentFolderName, false);
3629 3622
 				//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
3630 3623
 
3631 3624
 				$this->mail_bo->reopen('INBOX');
@@ -3633,11 +3626,11 @@  discard block
 block discarded – undo
3633 3626
 				// if newName has delimiter ($del) in it, we need to create the subtree
3634 3627
 				if (!empty($nA))
3635 3628
 				{
3636
-					$c=0;
3637
-					foreach($nA as $sTName)
3629
+					$c = 0;
3630
+					foreach ($nA as $sTName)
3638 3631
 					{
3639
-						$error=null;
3640
-						if(($parentFolderName = $this->mail_bo->createFolder($parentFolderName, $sTName, $error)))
3632
+						$error = null;
3633
+						if (($parentFolderName = $this->mail_bo->createFolder($parentFolderName, $sTName, $error)))
3641 3634
 						{
3642 3635
 							$c++;
3643 3636
 						}
@@ -3646,16 +3639,16 @@  discard block
 block discarded – undo
3646 3639
 							$errorMessage .= $error;
3647 3640
 						}
3648 3641
 					}
3649
-					if ($c==count($nA)) $created=true;
3642
+					if ($c == count($nA)) $created = true;
3650 3643
 				}
3651 3644
 				if (!empty($parentName)) $this->mail_bo->reopen($parentName);
3652 3645
 			}
3653 3646
 			//error_log(__METHOD__.__LINE__.array2string($oA));
3654
-			if ($created===true)
3647
+			if ($created === true)
3655 3648
 			{
3656 3649
 				$this->mail_bo->resetFolderObjectCache($profileID);
3657 3650
 				$response = Api\Json\Response::get();
3658
-				if ( $oldFolderInfo['shortDisplayName'])
3651
+				if ($oldFolderInfo['shortDisplayName'])
3659 3652
 				{
3660 3653
 					$nodeInfo = array($_parentFolderName=>$oldFolderInfo['shortDisplayName']);
3661 3654
 				}
@@ -3663,14 +3656,14 @@  discard block
 block discarded – undo
3663 3656
 				{
3664 3657
 					$nodeInfo = array($profileID=>lang('INBOX'));
3665 3658
 				}
3666
-				$response->call('app.mail.mail_reloadNode',$nodeInfo);
3659
+				$response->call('app.mail.mail_reloadNode', $nodeInfo);
3667 3660
 			}
3668 3661
 			else
3669 3662
 			{
3670 3663
 				if ($errorMessage)
3671 3664
 				{
3672 3665
 					$response = Api\Json\Response::get();
3673
-					$response->call('egw.message',$errorMessage);
3666
+					$response->call('egw.message', $errorMessage);
3674 3667
 				}
3675 3668
 			}
3676 3669
 		}
@@ -3692,22 +3685,22 @@  discard block
 block discarded – undo
3692 3685
 			$_newName = $this->mail_bo->decodeEntityFolderName($_newName);
3693 3686
 			$del = $this->mail_bo->getHierarchyDelimiter(false);
3694 3687
 			$oA = array();
3695
-			list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
3688
+			list($profileID, $folderName) = explode(self::$delimiter, $decodedFolderName, 2);
3696 3689
 			$hasChildren = false;
3697 3690
 			if (is_numeric($profileID))
3698 3691
 			{
3699 3692
 				if ($profileID != $this->mail_bo->profileID) return; // only current connection
3700
-				$pA = explode($del,$folderName);
3693
+				$pA = explode($del, $folderName);
3701 3694
 				array_pop($pA);
3702
-				$parentFolder = implode($del,$pA);
3703
-				if (strtoupper($folderName)!= 'INBOX')
3695
+				$parentFolder = implode($del, $pA);
3696
+				if (strtoupper($folderName) != 'INBOX')
3704 3697
 				{
3705 3698
 					//error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName");
3706
-					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName,false);
3699
+					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName, false);
3707 3700
 					//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
3708
-					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']),'\hasnochildren')=== false)
3701
+					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']), '\hasnochildren') === false)
3709 3702
 					{
3710
-						$hasChildren=true; // translates to: hasChildren -> dynamicLoading
3703
+						$hasChildren = true; // translates to: hasChildren -> dynamicLoading
3711 3704
 						$delimiter = $this->mail_bo->getHierarchyDelimiter();
3712 3705
 						$nameSpace = $this->mail_bo->_getNameSpaces();
3713 3706
 						$prefix = $this->mail_bo->getFolderPrefixFromNamespace($nameSpace, $folderName);
@@ -3724,7 +3717,7 @@  discard block
 block discarded – undo
3724 3717
 							else
3725 3718
 							{
3726 3719
 								$rv = $this->mail_bo->icServer->subscribeMailbox($folder, false);
3727
-								$fragments[$profileID.self::$delimiter.$folder] = substr($folder,strlen($folderName));
3720
+								$fragments[$profileID.self::$delimiter.$folder] = substr($folder, strlen($folderName));
3728 3721
 							}
3729 3722
 						}
3730 3723
 						//error_log(__METHOD__.__LINE__.' Fetched Subfolders->'.array2string($fragments));
@@ -3734,7 +3727,7 @@  discard block
 block discarded – undo
3734 3727
 					$success = false;
3735 3728
 					try
3736 3729
 					{
3737
-						if(($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)))
3730
+						if (($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)))
3738 3731
 						{
3739 3732
 							$this->mail_bo->resetFolderObjectCache($profileID);
3740 3733
 							//enforce the subscription to the newly named server, as it seems to fail for names with umlauts
@@ -3745,11 +3738,11 @@  discard block
 block discarded – undo
3745 3738
 					}
3746 3739
 					catch (Exception $e)
3747 3740
 					{
3748
-						$newFolderName=$folderName;
3741
+						$newFolderName = $folderName;
3749 3742
 						$msg = $e->getMessage();
3750 3743
 					}
3751 3744
 					$this->mail_bo->reopen($newFolderName);
3752
-					$fS = $this->mail_bo->getFolderStatus($newFolderName,false);
3745
+					$fS = $this->mail_bo->getFolderStatus($newFolderName, false);
3753 3746
 					//error_log(__METHOD__.__LINE__.array2string($fS));
3754 3747
 					if ($hasChildren)
3755 3748
 					{
@@ -3780,12 +3773,12 @@  discard block
 block discarded – undo
3780 3773
 					{
3781 3774
 						$oA[$_folderName]['desc'] = $fS['shortDisplayName'];
3782 3775
 					}
3783
-					foreach($fragments as $oldFolderName => $fragment)
3776
+					foreach ($fragments as $oldFolderName => $fragment)
3784 3777
 					{
3785 3778
 						//error_log(__METHOD__.__LINE__.':'.$oldFolderName.'->'.$profileID.self::$delimiter.$newFolderName.$fragment);
3786 3779
 						$oA[$oldFolderName]['id'] = $profileID.self::$delimiter.$newFolderName.$fragment;
3787 3780
 						$oA[$oldFolderName]['olddesc'] = '#skip-user-interaction-message#';
3788
-						$fS = $this->mail_bo->getFolderStatus($newFolderName.$fragment,false);
3781
+						$fS = $this->mail_bo->getFolderStatus($newFolderName.$fragment, false);
3789 3782
 						if ($fS['unseen'])
3790 3783
 						{
3791 3784
 							$oA[$oldFolderName]['desc'] = $fS['shortDisplayName'].' ('.$fS['unseen'].')';
@@ -3798,20 +3791,20 @@  discard block
 block discarded – undo
3798 3791
 					}
3799 3792
 				}
3800 3793
 			}
3801
-			if ($folderName==$this->mail_bo->sessionData['mailbox'])
3794
+			if ($folderName == $this->mail_bo->sessionData['mailbox'])
3802 3795
 			{
3803
-				$this->mail_bo->sessionData['mailbox']=$newFolderName;
3796
+				$this->mail_bo->sessionData['mailbox'] = $newFolderName;
3804 3797
 				$this->mail_bo->saveSessionData();
3805 3798
 			}
3806 3799
 			//error_log(__METHOD__.__LINE__.array2string($oA));
3807 3800
 			$response = Api\Json\Response::get();
3808 3801
 			if ($oA && $success)
3809 3802
 			{
3810
-				$response->call('app.mail.mail_setLeaf',$oA);
3803
+				$response->call('app.mail.mail_setLeaf', $oA);
3811 3804
 			}
3812 3805
 			else
3813 3806
 			{
3814
-				$response->call('egw.refresh',lang('failed to rename %1 ! Reason: %2',$oldFolderName,$msg),'mail');
3807
+				$response->call('egw.refresh', lang('failed to rename %1 ! Reason: %2', $oldFolderName, $msg), 'mail');
3815 3808
 			}
3816 3809
 		}
3817 3810
 	}
@@ -3823,7 +3816,7 @@  discard block
 block discarded – undo
3823 3816
 	 * @param boolean $_subscribedOnly = true
3824 3817
 	 * @return void
3825 3818
 	 */
3826
-	function ajax_reloadNode($_folderName,$_subscribedOnly=true)
3819
+	function ajax_reloadNode($_folderName, $_subscribedOnly = true)
3827 3820
 	{
3828 3821
 		Api\Translation::add_app('mail');
3829 3822
 		$oldPrefForSubscribedOnly = !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'];
@@ -3834,20 +3827,20 @@  discard block
 block discarded – undo
3834 3827
 
3835 3828
 		$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
3836 3829
 		$this->mail_bo->getHierarchyDelimiter(false);
3837
-		list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
3830
+		list($profileID, $folderName) = explode(self::$delimiter, $decodedFolderName, 2);
3838 3831
 		// if pref and required mode dont match -> reset the folderObject cache to ensure
3839 3832
 		// that we get what we request
3840 3833
 		if ($_subscribedOnly != $oldPrefForSubscribedOnly) $this->mail_bo->resetFolderObjectCache($profileID);
3841 3834
 		if ($profileID != $this->mail_bo->profileID) return; // only current connection
3842 3835
 		if (!empty($folderName))
3843 3836
 		{
3844
-			$parentFolder=(!empty($folderName)?$folderName:'INBOX');
3845
-			$folderInfo = $this->mail_bo->getFolderStatus($parentFolder,false,false,false);
3837
+			$parentFolder = (!empty($folderName) ? $folderName : 'INBOX');
3838
+			$folderInfo = $this->mail_bo->getFolderStatus($parentFolder, false, false, false);
3846 3839
 			if ($folderInfo['unseen'])
3847 3840
 			{
3848 3841
 				$folderInfo['shortDisplayName'] = $folderInfo['shortDisplayName'].' ('.$folderInfo['unseen'].')';
3849 3842
 			}
3850
-			if ($folderInfo['unseen']==0 && $folderInfo['shortDisplayName'])
3843
+			if ($folderInfo['unseen'] == 0 && $folderInfo['shortDisplayName'])
3851 3844
 			{
3852 3845
 				$folderInfo['shortDisplayName'] = $folderInfo['shortDisplayName'];
3853 3846
 			}
@@ -3863,11 +3856,11 @@  discard block
 block discarded – undo
3863 3856
 		}
3864 3857
 		// Send full info back in the response
3865 3858
 		$response = Api\Json\Response::get();
3866
-		foreach($refreshData as $folder => &$name)
3859
+		foreach ($refreshData as $folder => &$name)
3867 3860
 		{
3868
-			$name = $this->mail_tree->getTree($folder,$profileID,1,false, $_subscribedOnly,true);
3861
+			$name = $this->mail_tree->getTree($folder, $profileID, 1, false, $_subscribedOnly, true);
3869 3862
 		}
3870
-		$response->call('app.mail.mail_reloadNode',$refreshData);
3863
+		$response->call('app.mail.mail_reloadNode', $refreshData);
3871 3864
 
3872 3865
 	}
3873 3866
 
@@ -3883,7 +3876,7 @@  discard block
 block discarded – undo
3883 3876
 	 * @param type $_rowid row id from nm
3884 3877
 	 *
3885 3878
 	 */
3886
-	function ajax_resolveWinmail ($_rowid)
3879
+	function ajax_resolveWinmail($_rowid)
3887 3880
 	{
3888 3881
 		$response = Api\Json\Response::get();
3889 3882
 
@@ -3891,7 +3884,7 @@  discard block
 block discarded – undo
3891 3884
 		$uid = $idParts['msgUID'];
3892 3885
 		$mbox = $idParts['folder'];
3893 3886
 
3894
-		$attachments = $this->mail_bo->getMessageAttachments($uid, null, null, false,true,true,$mbox);
3887
+		$attachments = $this->mail_bo->getMessageAttachments($uid, null, null, false, true, true, $mbox);
3895 3888
 		if (is_array($attachments))
3896 3889
 		{
3897 3890
 			$attachments = $this->createAttachmentBlock($attachments, $_rowid, $uid, $mbox, false);
@@ -3919,30 +3912,30 @@  discard block
 block discarded – undo
3919 3912
 			$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
3920 3913
 			$_newLocation2 = $this->mail_bo->decodeEntityFolderName($_target);
3921 3914
 			$del = $this->mail_bo->getHierarchyDelimiter(false);
3922
-			list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
3923
-			list($newProfileID,$_newLocation) = explode(self::$delimiter,$_newLocation2,2);
3915
+			list($profileID, $folderName) = explode(self::$delimiter, $decodedFolderName, 2);
3916
+			list($newProfileID, $_newLocation) = explode(self::$delimiter, $_newLocation2, 2);
3924 3917
 			$hasChildren = false;
3925 3918
 			if (is_numeric($profileID))
3926 3919
 			{
3927 3920
 				if ($profileID != $this->mail_bo->profileID || $profileID != $newProfileID) return; // only current connection
3928
-				$pA = explode($del,$folderName);
3921
+				$pA = explode($del, $folderName);
3929 3922
 				$namePart = array_pop($pA);
3930 3923
 				$_newName = $namePart;
3931
-				$oldParentFolder = implode($del,$pA);
3924
+				$oldParentFolder = implode($del, $pA);
3932 3925
 				$parentFolder = $_newLocation;
3933 3926
 
3934
-				if (strtoupper($folderName)!= 'INBOX' &&
3927
+				if (strtoupper($folderName) != 'INBOX' &&
3935 3928
 					(($oldParentFolder === $parentFolder) || //$oldParentFolder == $parentFolder means move on same level
3936 3929
 					(($oldParentFolder != $parentFolder &&
3937
-					strlen($parentFolder)>0 && strlen($folderName)>0 &&
3938
-					strpos($parentFolder,$folderName)===false)))) // indicates that we move the older up the tree within its own branch
3930
+					strlen($parentFolder) > 0 && strlen($folderName) > 0 &&
3931
+					strpos($parentFolder, $folderName) === false)))) // indicates that we move the older up the tree within its own branch
3939 3932
 				{
3940 3933
 					//error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName");
3941
-					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName,false,false,false);
3934
+					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName, false, false, false);
3942 3935
 					//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
3943
-					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']),'\hasnochildren')=== false)
3936
+					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']), '\hasnochildren') === false)
3944 3937
 					{
3945
-						$hasChildren=true; // translates to: hasChildren -> dynamicLoading
3938
+						$hasChildren = true; // translates to: hasChildren -> dynamicLoading
3946 3939
 						$delimiter = $this->mail_bo->getHierarchyDelimiter();
3947 3940
 						$nameSpace = $this->mail_bo->_getNameSpaces();
3948 3941
 						$prefix = $this->mail_bo->getFolderPrefixFromNamespace($nameSpace, $folderName);
@@ -3967,7 +3960,7 @@  discard block
 block discarded – undo
3967 3960
 					$success = false;
3968 3961
 					try
3969 3962
 					{
3970
-						if(($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)))
3963
+						if (($newFolderName = $this->mail_bo->renameFolder($folderName, $parentFolder, $_newName)))
3971 3964
 						{
3972 3965
 							$this->mail_bo->resetFolderObjectCache($profileID);
3973 3966
 							//enforce the subscription to the newly named server, as it seems to fail for names with umlauts
@@ -3979,11 +3972,11 @@  discard block
 block discarded – undo
3979 3972
 					}
3980 3973
 					catch (Exception $e)
3981 3974
 					{
3982
-						$newFolderName=$folderName;
3975
+						$newFolderName = $folderName;
3983 3976
 						$msg = $e->getMessage();
3984 3977
 					}
3985 3978
 					$this->mail_bo->reopen($parentFolder);
3986
-					$this->mail_bo->getFolderStatus($parentFolder,false,false,false);
3979
+					$this->mail_bo->getFolderStatus($parentFolder, false, false, false);
3987 3980
 					//error_log(__METHOD__.__LINE__.array2string($fS));
3988 3981
 					if ($hasChildren)
3989 3982
 					{
@@ -4004,9 +3997,9 @@  discard block
 block discarded – undo
4004 3997
 					}
4005 3998
 				}
4006 3999
 			}
4007
-			if ($folderName==$this->mail_bo->sessionData['mailbox'])
4000
+			if ($folderName == $this->mail_bo->sessionData['mailbox'])
4008 4001
 			{
4009
-				$this->mail_bo->sessionData['mailbox']=$newFolderName;
4002
+				$this->mail_bo->sessionData['mailbox'] = $newFolderName;
4010 4003
 				$this->mail_bo->saveSessionData();
4011 4004
 			}
4012 4005
 			//error_log(__METHOD__.__LINE__.array2string($oA));
@@ -4015,26 +4008,26 @@  discard block
 block discarded – undo
4015 4008
 			{
4016 4009
 				Api\Translation::add_app('mail');
4017 4010
 
4018
-				$oldFolderInfo = $this->mail_bo->getFolderStatus($oldParentFolder,false,false,false);
4019
-				$folderInfo = $this->mail_bo->getFolderStatus($parentFolder,false,false,false);
4011
+				$oldFolderInfo = $this->mail_bo->getFolderStatus($oldParentFolder, false, false, false);
4012
+				$folderInfo = $this->mail_bo->getFolderStatus($parentFolder, false, false, false);
4020 4013
 				$refreshData = array(
4021 4014
 					$profileID.self::$delimiter.$oldParentFolder=>$oldFolderInfo['shortDisplayName'],
4022 4015
 					$profileID.self::$delimiter.$parentFolder=>$folderInfo['shortDisplayName']);
4023 4016
 				// if we move the folder within the same parent-branch of the tree, there is no need no refresh the upper part
4024
-				if (strlen($parentFolder)>strlen($oldParentFolder) && strpos($parentFolder,$oldParentFolder)!==false) unset($refreshData[$profileID.self::$delimiter.$parentFolder]);
4025
-				if (count($refreshData)>1 && strlen($oldParentFolder)>strlen($parentFolder) && strpos($oldParentFolder,$parentFolder)!==false) unset($refreshData[$profileID.self::$delimiter.$oldParentFolder]);
4017
+				if (strlen($parentFolder) > strlen($oldParentFolder) && strpos($parentFolder, $oldParentFolder) !== false) unset($refreshData[$profileID.self::$delimiter.$parentFolder]);
4018
+				if (count($refreshData) > 1 && strlen($oldParentFolder) > strlen($parentFolder) && strpos($oldParentFolder, $parentFolder) !== false) unset($refreshData[$profileID.self::$delimiter.$oldParentFolder]);
4026 4019
 
4027 4020
 				// Send full info back in the response
4028
-				foreach($refreshData as $folder => &$name)
4021
+				foreach ($refreshData as $folder => &$name)
4029 4022
 				{
4030
-					$name = $this->mail_tree->getTree($folder,$profileID,1,false,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'],true);
4023
+					$name = $this->mail_tree->getTree($folder, $profileID, 1, false, !$this->mail_bo->mailPreferences['showAllFoldersInFolderPane'], true);
4031 4024
 				}
4032
-				$response->call('app.mail.mail_reloadNode',$refreshData);
4025
+				$response->call('app.mail.mail_reloadNode', $refreshData);
4033 4026
 
4034 4027
 			}
4035 4028
 			else
4036 4029
 			{
4037
-				$response->call('egw.refresh',lang('failed to move %1 ! Reason: %2',$folderName,$msg),'mail');
4030
+				$response->call('egw.refresh', lang('failed to move %1 ! Reason: %2', $folderName, $msg), 'mail');
4038 4031
 			}
4039 4032
 		}
4040 4033
 	}
@@ -4054,23 +4047,23 @@  discard block
 block discarded – undo
4054 4047
 			$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
4055 4048
 			$del = $this->mail_bo->getHierarchyDelimiter(false);
4056 4049
 			$oA = array();
4057
-			list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
4050
+			list($profileID, $folderName) = explode(self::$delimiter, $decodedFolderName, 2);
4058 4051
 			$hasChildren = false;
4059 4052
 			if (is_numeric($profileID))
4060 4053
 			{
4061 4054
 				if ($profileID != $this->mail_bo->profileID) return; // only current connection
4062
-				$pA = explode($del,$folderName);
4055
+				$pA = explode($del, $folderName);
4063 4056
 				array_pop($pA);
4064
-				if (strtoupper($folderName)!= 'INBOX')
4057
+				if (strtoupper($folderName) != 'INBOX')
4065 4058
 				{
4066 4059
 					//error_log(__METHOD__.__LINE__."$folderName,  implode($del,$pA), $_newName");
4067 4060
 					$oA = array();
4068 4061
 					$subFolders = array();
4069
-					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName,false,false,false);
4062
+					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName, false, false, false);
4070 4063
 					//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
4071
-					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']),'\hasnochildren')=== false)
4064
+					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']), '\hasnochildren') === false)
4072 4065
 					{
4073
-						$hasChildren=true; // translates to: hasChildren -> dynamicLoading
4066
+						$hasChildren = true; // translates to: hasChildren -> dynamicLoading
4074 4067
 						$ftD = array();
4075 4068
 						$delimiter = $this->mail_bo->getHierarchyDelimiter();
4076 4069
 						$nameSpace = $this->mail_bo->_getNameSpaces();
@@ -4080,24 +4073,24 @@  discard block
 block discarded – undo
4080 4073
 						//error_log(__METHOD__.__LINE__.'->'."$folderName, $delimiter, $prefix");
4081 4074
 						foreach ($subFolders as $k => $f)
4082 4075
 						{
4083
-							$ftD[substr_count($f,$delimiter)][]=$f;
4076
+							$ftD[substr_count($f, $delimiter)][] = $f;
4084 4077
 						}
4085
-						krsort($ftD,SORT_NUMERIC);//sort per level
4078
+						krsort($ftD, SORT_NUMERIC); //sort per level
4086 4079
 						//we iterate per level of depth of the subtree, deepest nesting is to be deleted first, and then up the tree
4087
-						foreach($ftD as $k => $lc)//collection per level
4080
+						foreach ($ftD as $k => $lc)//collection per level
4088 4081
 						{
4089
-							foreach($lc as $f)//folders contained in that level
4082
+							foreach ($lc as $f)//folders contained in that level
4090 4083
 							{
4091 4084
 								try
4092 4085
 								{
4093 4086
 									//error_log(__METHOD__.__LINE__.array2string($f).'<->'.$folderName);
4094 4087
 									$this->mail_bo->deleteFolder($f);
4095 4088
 									$success = true;
4096
-									if ($f==$folderName) $oA[$_folderName] = $oldFolderInfo['shortDisplayName'];
4089
+									if ($f == $folderName) $oA[$_folderName] = $oldFolderInfo['shortDisplayName'];
4097 4090
 								}
4098 4091
 								catch (Exception $e)
4099 4092
 								{
4100
-									$msg .= ($msg?' ':'').lang("Failed to delete %1. Server responded:",$f).$e->getMessage();
4093
+									$msg .= ($msg ? ' ' : '').lang("Failed to delete %1. Server responded:", $f).$e->getMessage();
4101 4094
 									$success = false;
4102 4095
 								}
4103 4096
 							}
@@ -4128,11 +4121,11 @@  discard block
 block discarded – undo
4128 4121
 			if ($success)
4129 4122
 			{
4130 4123
 				//error_log(__METHOD__.__LINE__.array2string($oA));
4131
-				$response->call('app.mail.mail_removeLeaf',$oA);
4124
+				$response->call('app.mail.mail_removeLeaf', $oA);
4132 4125
 			}
4133 4126
 			else
4134 4127
 			{
4135
-				$response->call('egw.refresh',lang('failed to delete %1 ! Reason: %2',$oldFolderInfo['shortDisplayName'],$msg),'mail');
4128
+				$response->call('egw.refresh', lang('failed to delete %1 ! Reason: %2', $oldFolderInfo['shortDisplayName'], $msg), 'mail');
4136 4129
 			}
4137 4130
 		}
4138 4131
 	}
@@ -4146,7 +4139,7 @@  discard block
 block discarded – undo
4146 4139
 	 * @param bool $getFolders The client needs the folders for the profile
4147 4140
 	 * @return nothing
4148 4141
 	 */
4149
-	public static function ajax_changeProfile($icServerID, $getFolders = true, $exec_id=null)
4142
+	public static function ajax_changeProfile($icServerID, $getFolders = true, $exec_id = null)
4150 4143
 	{
4151 4144
 		$response = Api\Json\Response::get();
4152 4145
 
@@ -4154,7 +4147,7 @@  discard block
 block discarded – undo
4154 4147
 
4155 4148
 		if ($icServerID && $icServerID != $previous_id)
4156 4149
 		{
4157
-			$mail_ui = new mail_ui(false);	// do NOT run constructor, as we call changeProfile anyway
4150
+			$mail_ui = new mail_ui(false); // do NOT run constructor, as we call changeProfile anyway
4158 4151
 			try
4159 4152
 			{
4160 4153
 				$mail_ui->changeProfile($icServerID);
@@ -4170,23 +4163,23 @@  discard block
 block discarded – undo
4170 4163
 				}
4171 4164
 			}
4172 4165
 			catch (Exception $e) {
4173
-				self::callWizard($e->getMessage(),true, 'error');
4166
+				self::callWizard($e->getMessage(), true, 'error');
4174 4167
 			}
4175 4168
 		}
4176 4169
 		else
4177 4170
 		{
4178
-			$mail_ui = new mail_ui(true);	// run constructor
4171
+			$mail_ui = new mail_ui(true); // run constructor
4179 4172
 		}
4180 4173
 
4181 4174
 		// Send full info back in the response
4182
-		if($getFolders)
4175
+		if ($getFolders)
4183 4176
 		{
4184 4177
 			Api\Translation::add_app('mail');
4185 4178
 
4186 4179
 			$refreshData = array(
4187
-				$icServerID => $mail_ui->mail_tree->getTree(null,$icServerID,1,false,!$mail_ui->mail_bo->mailPreferences['showAllFoldersInFolderPane'],!$mail_ui->mail_bo->mailPreferences['showAllFoldersInFolderPane'])
4180
+				$icServerID => $mail_ui->mail_tree->getTree(null, $icServerID, 1, false, !$mail_ui->mail_bo->mailPreferences['showAllFoldersInFolderPane'], !$mail_ui->mail_bo->mailPreferences['showAllFoldersInFolderPane'])
4188 4181
 			);
4189
-			$response->call('app.mail.mail_reloadNode',$refreshData);
4182
+			$response->call('app.mail.mail_reloadNode', $refreshData);
4190 4183
 		}
4191 4184
 	}
4192 4185
 
@@ -4197,7 +4190,7 @@  discard block
 block discarded – undo
4197 4190
 	 *						if other than active profile; nothing is done!
4198 4191
 	 * @return nothing
4199 4192
 	 */
4200
-	public static function ajax_refreshVacationNotice($icServerID=null)
4193
+	public static function ajax_refreshVacationNotice($icServerID = null)
4201 4194
 	{
4202 4195
 		//Get vacation from cache if it's available
4203 4196
 		$cachedVacations = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'vacationNotice'.$GLOBALS['egw_info']['user']['account_lid']);
@@ -4215,28 +4208,28 @@  discard block
 block discarded – undo
4215 4208
 
4216 4209
 				$vacation = $mail->gatherVacation($cachedVacations);
4217 4210
 			} catch (Exception $e) {
4218
-				$vacation=false;
4211
+				$vacation = false;
4219 4212
 				error_log(__METHOD__.__LINE__." ".$e->getMessage());
4220 4213
 				unset($e);
4221 4214
 			}
4222 4215
 		}
4223 4216
 
4224
-		if($vacation) {
4225
-			if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date'))
4217
+		if ($vacation) {
4218
+			if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status'] == 'by_date'))
4226 4219
 			{
4227 4220
 				$dtfrmt = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
4228 4221
 				$refreshData['vacationnotice'] = lang('Vacation notice is active');
4229
-				$refreshData['vacationrange'] = ($vacation['status']=='by_date'? Api\DateTime::server2user($vacation['start_date'],$dtfrmt,true).($vacation['end_date']>$vacation['start_date']?'->'.Api\DateTime::server2user($vacation['end_date']+ 24*3600-1,$dtfrmt,true):''):'');
4230
-				if ($vacation['status'] == 'by_date' && $vacation['end_date']+ 24*3600 < time())$refreshData = '';
4222
+				$refreshData['vacationrange'] = ($vacation['status'] == 'by_date' ? Api\DateTime::server2user($vacation['start_date'], $dtfrmt, true).($vacation['end_date'] > $vacation['start_date'] ? '->'.Api\DateTime::server2user($vacation['end_date'] + 24 * 3600 - 1, $dtfrmt, true) : '') : '');
4223
+				if ($vacation['status'] == 'by_date' && $vacation['end_date'] + 24 * 3600 < time())$refreshData = '';
4231 4224
 			}
4232 4225
 		}
4233
-		if ($vacation==false)
4226
+		if ($vacation == false)
4234 4227
 		{
4235
-			$refreshData['vacationnotice'] =  '';
4236
-			$refreshData['vacationrange'] =  '';
4228
+			$refreshData['vacationnotice'] = '';
4229
+			$refreshData['vacationrange'] = '';
4237 4230
 		}
4238 4231
 		$response = Api\Json\Response::get();
4239
-		$response->call('app.mail.mail_refreshVacationNotice',$refreshData);
4232
+		$response->call('app.mail.mail_refreshVacationNotice', $refreshData);
4240 4233
 	}
4241 4234
 
4242 4235
 	/**
@@ -4246,43 +4239,43 @@  discard block
 block discarded – undo
4246 4239
 	 *						if other than active profile; nothing is done!
4247 4240
 	 * @return nothing
4248 4241
 	 */
4249
-	function ajax_refreshFilters($icServerID=null)
4242
+	function ajax_refreshFilters($icServerID = null)
4250 4243
 	{
4251 4244
 		//error_log(__METHOD__.__LINE__.array2string($icServerId));
4252 4245
 		if (empty($icServerID)) $icServerID = $this->mail_bo->profileID;
4253 4246
 		if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4254 4247
 		{
4255
-			Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4256
-			if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4248
+			Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
4249
+			if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID] = true;
4257 4250
 		}
4258 4251
 		if (!Mail::$supportsORinQuery[$this->mail_bo->profileID])
4259 4252
 		{
4260 4253
 			unset($this->searchTypes['quick']);
4261 4254
 			unset($this->searchTypes['quickwithcc']);
4262 4255
 		}
4263
-		if ( $this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
4256
+		if ($this->mail_bo->icServer->hasCapability('SUPPORTS_KEYWORDS'))
4264 4257
 		{
4265
-			$this->statusTypes = array_merge($this->statusTypes,array(
4266
-				'keyword1'	=> 'important',//lang('important'),
4267
-				'keyword2'	=> 'job',	//lang('job'),
4268
-				'keyword3'	=> 'personal',//lang('personal'),
4269
-				'keyword4'	=> 'to do',	//lang('to do'),
4270
-				'keyword5'	=> 'later',	//lang('later'),
4258
+			$this->statusTypes = array_merge($this->statusTypes, array(
4259
+				'keyword1'	=> 'important', //lang('important'),
4260
+				'keyword2'	=> 'job', //lang('job'),
4261
+				'keyword3'	=> 'personal', //lang('personal'),
4262
+				'keyword4'	=> 'to do', //lang('to do'),
4263
+				'keyword5'	=> 'later', //lang('later'),
4271 4264
 			));
4272 4265
 		}
4273 4266
 		else
4274 4267
 		{
4275
-			$keywords = array('keyword1','keyword2','keyword3','keyword4','keyword5');
4276
-			foreach($keywords as &$k)
4268
+			$keywords = array('keyword1', 'keyword2', 'keyword3', 'keyword4', 'keyword5');
4269
+			foreach ($keywords as &$k)
4277 4270
 			{
4278
-				if (array_key_exists($k,$this->statusTypes)) unset($this->statusTypes[$k]);
4271
+				if (array_key_exists($k, $this->statusTypes)) unset($this->statusTypes[$k]);
4279 4272
 			}
4280 4273
 		}
4281 4274
 
4282 4275
 		$response = Api\Json\Response::get();
4283
-		$response->call('app.mail.mail_refreshCatIdOptions',$this->searchTypes);
4284
-		$response->call('app.mail.mail_refreshFilterOptions',$this->statusTypes);
4285
-		$response->call('app.mail.mail_refreshFilter2Options',array(''=>lang('No details'),1=>lang('Details')));
4276
+		$response->call('app.mail.mail_refreshCatIdOptions', $this->searchTypes);
4277
+		$response->call('app.mail.mail_refreshFilterOptions', $this->statusTypes);
4278
+		$response->call('app.mail.mail_refreshFilter2Options', array(''=>lang('No details'), 1=>lang('Details')));
4286 4279
 
4287 4280
 	}
4288 4281
 
@@ -4291,7 +4284,7 @@  discard block
 block discarded – undo
4291 4284
 	 *
4292 4285
 	 * @return nothing
4293 4286
 	 */
4294
-	function ajax_refreshQuotaDisplay($icServerID=null)
4287
+	function ajax_refreshQuotaDisplay($icServerID = null)
4295 4288
 	{
4296 4289
 		//error_log(__METHOD__.__LINE__.array2string($icServerID));
4297 4290
 		Api\Translation::add_app('mail');
@@ -4311,10 +4304,10 @@  discard block
 block discarded – undo
4311 4304
 			unset($e);
4312 4305
 		}
4313 4306
 
4314
-		if($quota !== false && $quota['limit'] != 'NOT SET') {
4307
+		if ($quota !== false && $quota['limit'] != 'NOT SET') {
4315 4308
 			$quotainfo = $this->quotaDisplay($quota['usage'], $quota['limit']);
4316 4309
 			$content['quota'] = $sel_options[self::$nm_index]['quota'] = $quotainfo['text'];
4317
-			$content['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] =  (string)$quotainfo['percent'];
4310
+			$content['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] = (string)$quotainfo['percent'];
4318 4311
 			$content['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = $quotainfo['class'];
4319 4312
 			$content['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "";
4320 4313
 		} else {
@@ -4334,7 +4327,7 @@  discard block
 block discarded – undo
4334 4327
 			}
4335 4328
 		}
4336 4329
 		$response = Api\Json\Response::get();
4337
-		$response->call('app.mail.mail_setQuotaDisplay',array('data'=>$content));
4330
+		$response->call('app.mail.mail_setQuotaDisplay', array('data'=>$content));
4338 4331
 	}
4339 4332
 
4340 4333
 	/**
@@ -4356,34 +4349,34 @@  discard block
 block discarded – undo
4356 4349
 			$this->changeProfile($icServerID);
4357 4350
 		}
4358 4351
 		$junkFolder = $this->mail_bo->getJunkFolder();
4359
-		if(!empty($junkFolder)) {
4352
+		if (!empty($junkFolder)) {
4360 4353
 			if ($selectedFolder == $icServerID.self::$delimiter.$junkFolder)
4361 4354
 			{
4362 4355
 				// Lock the tree if the active folder is junk folder
4363 4356
 				$response->call('app.mail.lock_tree');
4364 4357
 			}
4365
-			$this->mail_bo->deleteMessages('all',$junkFolder,'remove_immediately');
4358
+			$this->mail_bo->deleteMessages('all', $junkFolder, 'remove_immediately');
4366 4359
 
4367 4360
 			$heirarchyDelimeter = $this->mail_bo->getHierarchyDelimiter(true);
4368
-			$fShortName =  array_pop(explode($heirarchyDelimeter, $junkFolder));
4361
+			$fShortName = array_pop(explode($heirarchyDelimeter, $junkFolder));
4369 4362
 			$fStatus = array(
4370 4363
 				$icServerID.self::$delimiter.$junkFolder => lang($fShortName)
4371 4364
 			);
4372 4365
 			//Call to reset folder status counter, after junkFolder triggered not from Junk folder
4373 4366
 			//-as we don't have junk folder specific information available on client-side we need to deal with it on server
4374
-			$response->call('app.mail.mail_setFolderStatus',$fStatus);
4367
+			$response->call('app.mail.mail_setFolderStatus', $fStatus);
4375 4368
 		}
4376 4369
 		if ($rememberServerID != $this->mail_bo->profileID)
4377 4370
 		{
4378
-			$oldFolderInfo = $this->mail_bo->getFolderStatus($junkFolder,false,false,false);
4379
-			$response->call('egw.message',lang('empty junk'));
4380
-			$response->call('app.mail.mail_reloadNode',array($icServerID.self::$delimiter.$junkFolder=>$oldFolderInfo['shortDisplayName']));
4371
+			$oldFolderInfo = $this->mail_bo->getFolderStatus($junkFolder, false, false, false);
4372
+			$response->call('egw.message', lang('empty junk'));
4373
+			$response->call('app.mail.mail_reloadNode', array($icServerID.self::$delimiter.$junkFolder=>$oldFolderInfo['shortDisplayName']));
4381 4374
 			//error_log(__METHOD__.__LINE__.' change Profile to ->'.$rememberServerID);
4382 4375
 			$this->changeProfile($rememberServerID);
4383 4376
 		}
4384 4377
 		else if ($selectedFolder == $icServerID.self::$delimiter.$junkFolder)
4385 4378
 		{
4386
-			$response->call('egw.refresh',lang('empty junk'),'mail');
4379
+			$response->call('egw.refresh', lang('empty junk'), 'mail');
4387 4380
 		}
4388 4381
 	}
4389 4382
 
@@ -4406,7 +4399,7 @@  discard block
 block discarded – undo
4406 4399
 			$this->changeProfile($icServerID);
4407 4400
 		}
4408 4401
 		$trashFolder = $this->mail_bo->getTrashFolder();
4409
-		if(!empty($trashFolder)) {
4402
+		if (!empty($trashFolder)) {
4410 4403
 			if ($selectedFolder == $icServerID.self::$delimiter.$trashFolder)
4411 4404
 			{
4412 4405
 				// Lock the tree if the active folder is Trash folder
@@ -4415,25 +4408,25 @@  discard block
 block discarded – undo
4415 4408
 			$this->mail_bo->compressFolder($trashFolder);
4416 4409
 
4417 4410
 			$heirarchyDelimeter = $this->mail_bo->getHierarchyDelimiter(true);
4418
-			$fShortName =  array_pop(explode($heirarchyDelimeter, $trashFolder));
4411
+			$fShortName = array_pop(explode($heirarchyDelimeter, $trashFolder));
4419 4412
 			$fStatus = array(
4420 4413
 				$icServerID.self::$delimiter.$trashFolder => lang($fShortName)
4421 4414
 			);
4422 4415
 			//Call to reset folder status counter, after emptyTrash triggered not from Trash folder
4423 4416
 			//-as we don't have trash folder specific information available on client-side we need to deal with it on server
4424
-			$response->call('app.mail.mail_setFolderStatus',$fStatus);
4417
+			$response->call('app.mail.mail_setFolderStatus', $fStatus);
4425 4418
 		}
4426 4419
 		if ($rememberServerID != $this->mail_bo->profileID)
4427 4420
 		{
4428
-			$oldFolderInfo = $this->mail_bo->getFolderStatus($trashFolder,false,false,false);
4429
-			$response->call('egw.message',lang('empty trash'));
4430
-			$response->call('app.mail.mail_reloadNode',array($icServerID.self::$delimiter.$trashFolder=>$oldFolderInfo['shortDisplayName']));
4421
+			$oldFolderInfo = $this->mail_bo->getFolderStatus($trashFolder, false, false, false);
4422
+			$response->call('egw.message', lang('empty trash'));
4423
+			$response->call('app.mail.mail_reloadNode', array($icServerID.self::$delimiter.$trashFolder=>$oldFolderInfo['shortDisplayName']));
4431 4424
 			//error_log(__METHOD__.__LINE__.' change Profile to ->'.$rememberServerID);
4432 4425
 			$this->changeProfile($rememberServerID);
4433 4426
 		}
4434 4427
 		else if ($selectedFolder == $icServerID.self::$delimiter.$trashFolder)
4435 4428
 		{
4436
-			$response->call('egw.refresh',lang('empty trash'),'mail');
4429
+			$response->call('egw.refresh', lang('empty trash'), 'mail');
4437 4430
 		}
4438 4431
 	}
4439 4432
 
@@ -4450,7 +4443,7 @@  discard block
 block discarded – undo
4450 4443
 
4451 4444
 		$this->mail_bo->restoreSessionData();
4452 4445
 		$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
4453
-		list($icServerID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
4446
+		list($icServerID, $folderName) = explode(self::$delimiter, $decodedFolderName, 2);
4454 4447
 
4455 4448
 		if (empty($folderName)) $folderName = $this->mail_bo->sessionData['mailbox'];
4456 4449
 		if ($this->mail_bo->folderExists($folderName))
@@ -4461,7 +4454,7 @@  discard block
 block discarded – undo
4461 4454
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
4462 4455
 				$this->changeProfile($icServerID);
4463 4456
 			}
4464
-			if(!empty($_folderName)) {
4457
+			if (!empty($_folderName)) {
4465 4458
 				$this->mail_bo->compressFolder($folderName);
4466 4459
 			}
4467 4460
 			if ($rememberServerID != $this->mail_bo->profileID)
@@ -4470,7 +4463,7 @@  discard block
 block discarded – undo
4470 4463
 				$this->changeProfile($rememberServerID);
4471 4464
 			}
4472 4465
 			$response = Api\Json\Response::get();
4473
-			$response->call('egw.refresh',lang('compress folder').': '.$folderName,'mail');
4466
+			$response->call('egw.refresh', lang('compress folder').': '.$folderName, 'mail');
4474 4467
 		}
4475 4468
 	}
4476 4469
 
@@ -4483,10 +4476,10 @@  discard block
 block discarded – undo
4483 4476
 	 */
4484 4477
 	function ajax_sendMDN($_messageList)
4485 4478
 	{
4486
-		if(Mail::$debug) error_log(__METHOD__."->".array2string($_messageList));
4479
+		if (Mail::$debug) error_log(__METHOD__."->".array2string($_messageList));
4487 4480
 		$uidA = self::splitRowID($_messageList['msg'][0]);
4488 4481
 		$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
4489
-		$this->mail_bo->sendMDN($uidA['msgUID'],$folder);
4482
+		$this->mail_bo->sendMDN($uidA['msgUID'], $folder);
4490 4483
 	}
4491 4484
 
4492 4485
 	/**
@@ -4498,14 +4491,14 @@  discard block
 block discarded – undo
4498 4491
 	 *
4499 4492
 	 * @return xajax response
4500 4493
 	 */
4501
-	function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse=true)
4494
+	function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse = true)
4502 4495
 	{
4503
-		if(Mail::$debug) error_log(__METHOD__."->".$_flag.':'.array2string($_messageList));
4496
+		if (Mail::$debug) error_log(__METHOD__."->".$_flag.':'.array2string($_messageList));
4504 4497
 		Api\Translation::add_app('mail');
4505
-		$alreadyFlagged=false;
4506
-		$flag2check='';
4498
+		$alreadyFlagged = false;
4499
+		$flag2check = '';
4507 4500
 		$filter2toggle = $query = array();
4508
-		if ($_messageList=='all' || !empty($_messageList['msg']))
4501
+		if ($_messageList == 'all' || !empty($_messageList['msg']))
4509 4502
 		{
4510 4503
 			if (isset($_messageList['all']) && $_messageList['all'])
4511 4504
 			{
@@ -4515,34 +4508,34 @@  discard block
 block discarded – undo
4515 4508
 				if (isset($_messageList['activeFilters']) && $_messageList['activeFilters'])
4516 4509
 				{
4517 4510
 					$query = $_messageList['activeFilters'];
4518
-					if (!empty($query['search']) || !empty($query['filter'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate']))))
4511
+					if (!empty($query['search']) || !empty($query['filter']) || ($query['cat_id'] == 'bydate' && (!empty($query['startdate']) || !empty($query['enddate']))))
4519 4512
 					{
4520 4513
 						//([filterName] => Schnellsuche[type] => quick[string] => ebay[status] => any
4521 4514
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4522 4515
 						{
4523
-							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4524
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4516
+							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
4517
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID] = true;
4525 4518
 						}
4526 4519
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']);
4527 4520
 						$cutoffdate = $cutoffdate2 = null;
4528
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4529
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
4521
+						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'], 'ts'); //SINCE, enddate
4522
+						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'], 'ts'); //BEFORE, startdate
4530 4523
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4531 4524
 						$filter = array(
4532
-							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
4533
-							'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')),
4525
+							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? lang('quicksearch') : lang('subject')),
4526
+							'type' => ($query['cat_id'] ? $query['cat_id'] : (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? 'quick' : 'subject')),
4534 4527
 							'string' => $query['search'],
4535
-							'status' => 'any',//this is a status change. status will be manipulated later on
4528
+							'status' => 'any', //this is a status change. status will be manipulated later on
4536 4529
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4537 4530
 						);
4538
-						if ($query['enddate']||$query['startdate']) {
4531
+						if ($query['enddate'] || $query['startdate']) {
4539 4532
 							$filter['range'] = "BETWEEN";
4540 4533
 							if ($cutoffdate) {
4541
-								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4534
+								$filter[(empty($cutoffdate2) ? 'date' : 'since')] = date("d-M-Y", $cutoffdate);
4542 4535
 								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
4543 4536
 							}
4544 4537
 							if ($cutoffdate2) {
4545
-								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4538
+								$filter[(empty($cutoffdate) ? 'date' : 'before')] = date("d-M-Y", $cutoffdate2);
4546 4539
 								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
4547 4540
 							}
4548 4541
 						}
@@ -4555,70 +4548,70 @@  discard block
 block discarded – undo
4555 4548
 					// flags read,flagged,label1,label2,label3,label4,label5 can be toggled: handle this when all mails in a folder
4556 4549
 					// should be affected serverside. here.
4557 4550
 					$messageList = $messageListForToggle = array();
4558
-					$flag2check = ($_flag=='read'?'seen':$_flag);
4559
-					if (in_array($_flag,array('read','flagged','label1','label2','label3','label4','label5')) &&
4560
-						!($flag2check==$query['filter'] || stripos($query['filter'],$flag2check)!==false))
4551
+					$flag2check = ($_flag == 'read' ? 'seen' : $_flag);
4552
+					if (in_array($_flag, array('read', 'flagged', 'label1', 'label2', 'label3', 'label4', 'label5')) &&
4553
+						!($flag2check == $query['filter'] || stripos($query['filter'], $flag2check) !== false))
4561 4554
 					{
4562 4555
 						$filter2toggle['status'] = array('un'.$_flag);
4563
-						if ($query['filter'] && $query['filter']!='any')
4556
+						if ($query['filter'] && $query['filter'] != 'any')
4564 4557
 						{
4565 4558
 							$filter2toggle['status'][] = $query['filter'];
4566 4559
 						}
4567 4560
 						$_sRt = $this->mail_bo->getSortedList(
4568 4561
 							$folder,
4569
-							$sort=0,
4570
-							$reverse=1,
4562
+							$sort = 0,
4563
+							$reverse = 1,
4571 4564
 							$filter2toggle,
4572
-							$rByUid=true,
4565
+							$rByUid = true,
4573 4566
 							false
4574 4567
 						);
4575 4568
 						$messageListForToggle = $_sRt['match']->ids;
4576 4569
 						$filter['status'] = array($_flag);
4577
-						if ($query['filter'] && $query['filter'] !='any')
4570
+						if ($query['filter'] && $query['filter'] != 'any')
4578 4571
 						{
4579 4572
 							$filter['status'][] = $query['filter'];
4580 4573
 						}
4581 4574
 						$_sR = $this->mail_bo->getSortedList(
4582 4575
 							$folder,
4583
-							$sort=0,
4584
-							$reverse=1,
4576
+							$sort = 0,
4577
+							$reverse = 1,
4585 4578
 							$filter,
4586
-							$rByUid=true,
4579
+							$rByUid = true,
4587 4580
 							false
4588 4581
 						);
4589 4582
 						$messageList = $_sR['match']->ids;
4590
-						if (count($messageListForToggle)>0)
4583
+						if (count($messageListForToggle) > 0)
4591 4584
 						{
4592 4585
 							$flag2set = (strtolower($_flag));
4593
-							if(Mail::$debug) error_log(__METHOD__.__LINE__." toggle un$_flag -> $flag2set ".array2string($filter2toggle).array2string($messageListForToggle));
4594
-							$this->mail_bo->flagMessages($flag2set, $messageListForToggle,$folder);
4586
+							if (Mail::$debug) error_log(__METHOD__.__LINE__." toggle un$_flag -> $flag2set ".array2string($filter2toggle).array2string($messageListForToggle));
4587
+							$this->mail_bo->flagMessages($flag2set, $messageListForToggle, $folder);
4595 4588
 						}
4596
-						if (count($messageList)>0)
4589
+						if (count($messageList) > 0)
4597 4590
 						{
4598 4591
 							$flag2set = 'un'.$_flag;
4599
-							if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag -> $flag2set ".array2string($filter).array2string($messageList));
4600
-							$this->mail_bo->flagMessages($flag2set, $messageList,$folder);
4592
+							if (Mail::$debug) error_log(__METHOD__.__LINE__." $_flag -> $flag2set ".array2string($filter).array2string($messageList));
4593
+							$this->mail_bo->flagMessages($flag2set, $messageList, $folder);
4601 4594
 						}
4602
-						$alreadyFlagged=true;
4595
+						$alreadyFlagged = true;
4603 4596
 					}
4604 4597
 					elseif (!empty($filter) &&
4605
-						(!in_array($_flag,array('read','flagged','label1','label2','label3','label4','label5')) ||
4606
-						(in_array($_flag,array('read','flagged','label1','label2','label3','label4','label5')) &&
4607
-						($flag2check==$query['filter'] || stripos($query['filter'],$flag2check)!==false))))
4598
+						(!in_array($_flag, array('read', 'flagged', 'label1', 'label2', 'label3', 'label4', 'label5')) ||
4599
+						(in_array($_flag, array('read', 'flagged', 'label1', 'label2', 'label3', 'label4', 'label5')) &&
4600
+						($flag2check == $query['filter'] || stripos($query['filter'], $flag2check) !== false))))
4608 4601
 					{
4609
-						if ($query['filter'] && $query['filter'] !='any')
4602
+						if ($query['filter'] && $query['filter'] != 'any')
4610 4603
 						{
4611 4604
 							$filter['status'] = $query['filter'];
4612 4605
 							// since we toggle and we toggle by the filtered flag we must must change _flag
4613
-							$_flag = ($query['filter']=='unseen' && $_flag=='read' ? 'read' : ($query['filter']=='seen'&& $_flag=='read'?'unread':($_flag==$query['filter']?'un'.$_flag:$_flag)));
4606
+							$_flag = ($query['filter'] == 'unseen' && $_flag == 'read' ? 'read' : ($query['filter'] == 'seen' && $_flag == 'read' ? 'unread' : ($_flag == $query['filter'] ? 'un'.$_flag : $_flag)));
4614 4607
 						}
4615
-						if(Mail::$debug) error_log(__METHOD__.__LINE__." flag all with $_flag on filter used:".array2string($filter));
4608
+						if (Mail::$debug) error_log(__METHOD__.__LINE__." flag all with $_flag on filter used:".array2string($filter));
4616 4609
 						$_sR = $this->mail_bo->getSortedList(
4617 4610
 							$folder,
4618
-							$sort=0,
4619
-							$reverse=1,
4611
+							$sort = 0,
4612
+							$reverse = 1,
4620 4613
 							$filter,
4621
-							$rByUid=true,
4614
+							$rByUid = true,
4622 4615
 							false
4623 4616
 						);
4624 4617
 						$messageList = $_sR['match']->ids;
@@ -4627,8 +4620,8 @@  discard block
 block discarded – undo
4627 4620
 					}
4628 4621
 					else
4629 4622
 					{
4630
-						if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag all ".array2string($filter));
4631
-						$alreadyFlagged=true;
4623
+						if (Mail::$debug) error_log(__METHOD__.__LINE__." $_flag all ".array2string($filter));
4624
+						$alreadyFlagged = true;
4632 4625
 						$uidA = self::splitRowID($_messageList['msg'][0]);
4633 4626
 						$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
4634 4627
 						$this->mail_bo->flagMessages($_flag, 'all', $folder);
@@ -4642,41 +4635,41 @@  discard block
 block discarded – undo
4642 4635
 			}
4643 4636
 			if (!$alreadyFlagged)
4644 4637
 			{
4645
-				foreach($_messageList['msg'] as $rowID)
4638
+				foreach ($_messageList['msg'] as $rowID)
4646 4639
 				{
4647 4640
 					$hA = self::splitRowID($rowID);
4648 4641
 					$messageList[] = $hA['msgUID'];
4649 4642
 				}
4650
-				if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag in $folder:".array2string(((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList)));
4651
-				$this->mail_bo->flagMessages($_flag, ((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList),$folder);
4643
+				if (Mail::$debug) error_log(__METHOD__.__LINE__." $_flag in $folder:".array2string(((isset($_messageList['all']) && $_messageList['all']) ? 'all' : $messageList)));
4644
+				$this->mail_bo->flagMessages($_flag, ((isset($_messageList['all']) && $_messageList['all']) ? 'all' : $messageList), $folder);
4652 4645
 			}
4653 4646
 		}
4654 4647
 		else
4655 4648
 		{
4656
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
4649
+			if (Mail::$debug) error_log(__METHOD__."-> No messages selected.");
4657 4650
 		}
4658 4651
 
4659 4652
 		if ($_sendJsonResponse)
4660 4653
 		{
4661
-			$flag=array(
4662
-				'label1'	=> 'important',//lang('important'),
4663
-				'label2'	=> 'job',	//lang('job'),
4664
-				'label3'	=> 'personal',//lang('personal'),
4665
-				'label4'	=> 'to do',	//lang('to do'),
4666
-				'label5'	=> 'later',	//lang('later'),
4654
+			$flag = array(
4655
+				'label1'	=> 'important', //lang('important'),
4656
+				'label2'	=> 'job', //lang('job'),
4657
+				'label3'	=> 'personal', //lang('personal'),
4658
+				'label4'	=> 'to do', //lang('to do'),
4659
+				'label5'	=> 'later', //lang('later'),
4667 4660
 			);
4668 4661
 			$response = Api\Json\Response::get();
4669 4662
 			if (isset($_messageList['msg']) && $_messageList['popup'])
4670 4663
 			{
4671
-				$response->call('egw.refresh',lang('flagged %1 messages as %2 in %3',$_messageList['msg'],lang(($flag[$_flag]?$flag[$_flag]:$_flag)),$folder),'mail', $_messageList['msg'], 'update');
4664
+				$response->call('egw.refresh', lang('flagged %1 messages as %2 in %3', $_messageList['msg'], lang(($flag[$_flag] ? $flag[$_flag] : $_flag)), $folder), 'mail', $_messageList['msg'], 'update');
4672 4665
 			}
4673
-			else if ((isset($_messageList['all']) && $_messageList['all']) || ($query['filter'] && ($flag2check==$query['filter'] || stripos($query['filter'],$flag2check)!==false)))
4666
+			else if ((isset($_messageList['all']) && $_messageList['all']) || ($query['filter'] && ($flag2check == $query['filter'] || stripos($query['filter'], $flag2check) !== false)))
4674 4667
 			{
4675
-				$response->call('egw.refresh',lang('flagged %1 messages as %2 in %3',(isset($_messageList['all']) && $_messageList['all']?lang('all'):count($_messageList['msg'])),lang(($flag[$_flag]?$flag[$_flag]:$_flag)),$folder),'mail');
4668
+				$response->call('egw.refresh', lang('flagged %1 messages as %2 in %3', (isset($_messageList['all']) && $_messageList['all'] ? lang('all') : count($_messageList['msg'])), lang(($flag[$_flag] ? $flag[$_flag] : $_flag)), $folder), 'mail');
4676 4669
 			}
4677 4670
 			else
4678 4671
 			{
4679
-				$response->call('egw.message',lang('flagged %1 messages as %2 in %3',(isset($_messageList['all']) && $_messageList['all']?lang('all'):count($_messageList['msg'])),lang(($flag[$_flag]?$flag[$_flag]:$_flag)),$folder));
4672
+				$response->call('egw.message', lang('flagged %1 messages as %2 in %3', (isset($_messageList['all']) && $_messageList['all'] ? lang('all') : count($_messageList['msg'])), lang(($flag[$_flag] ? $flag[$_flag] : $_flag)), $folder));
4680 4673
 			}
4681 4674
 		}
4682 4675
 	}
@@ -4688,12 +4681,12 @@  discard block
 block discarded – undo
4688 4681
 	 * @param string _forceDeleteMethod - method of deletion to be enforced
4689 4682
 	 * @return xajax response
4690 4683
 	 */
4691
-	function ajax_deleteMessages($_messageList,$_forceDeleteMethod=null)
4684
+	function ajax_deleteMessages($_messageList, $_forceDeleteMethod = null)
4692 4685
 	{
4693
-		if(Mail::$debug) error_log(__METHOD__."->".print_r($_messageList,true).' Method:'.$_forceDeleteMethod);
4686
+		if (Mail::$debug) error_log(__METHOD__."->".print_r($_messageList, true).' Method:'.$_forceDeleteMethod);
4694 4687
 		$error = null;
4695
-		$filtered =  false;
4696
-		if ($_messageList=='all' || !empty($_messageList['msg']))
4688
+		$filtered = false;
4689
+		if ($_messageList == 'all' || !empty($_messageList['msg']))
4697 4690
 		{
4698 4691
 			if (isset($_messageList['all']) && $_messageList['all'])
4699 4692
 			{
@@ -4703,34 +4696,34 @@  discard block
 block discarded – undo
4703 4696
 				if (isset($_messageList['activeFilters']) && $_messageList['activeFilters'])
4704 4697
 				{
4705 4698
 					$query = $_messageList['activeFilters'];
4706
-					if (!empty($query['search']) || !empty($query['filter'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate']))))
4699
+					if (!empty($query['search']) || !empty($query['filter']) || ($query['cat_id'] == 'bydate' && (!empty($query['startdate']) || !empty($query['enddate']))))
4707 4700
 					{
4708 4701
 						//([filterName] => Schnellsuche[type] => quick[string] => ebay[status] => any
4709 4702
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4710 4703
 						{
4711
-							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4712
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4704
+							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
4705
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID] = true;
4713 4706
 						}
4714
-						$filtered =  true;
4707
+						$filtered = true;
4715 4708
 						$cutoffdate = $cutoffdate2 = null;
4716
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4717
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
4709
+						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'], 'ts'); //SINCE, enddate
4710
+						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'], 'ts'); //BEFORE, startdate
4718 4711
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4719 4712
 						$filter = array(
4720
-							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
4721
-							'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')),
4713
+							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? lang('quicksearch') : lang('subject')),
4714
+							'type' => ($query['cat_id'] ? $query['cat_id'] : (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? 'quick' : 'subject')),
4722 4715
 							'string' => $query['search'],
4723
-							'status' => (!empty($query['filter'])?$query['filter']:'any'),
4716
+							'status' => (!empty($query['filter']) ? $query['filter'] : 'any'),
4724 4717
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4725 4718
 						);
4726
-						if ($query['enddate']||$query['startdate']) {
4719
+						if ($query['enddate'] || $query['startdate']) {
4727 4720
 							$filter['range'] = "BETWEEN";
4728 4721
 							if ($cutoffdate) {
4729
-								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4722
+								$filter[(empty($cutoffdate2) ? 'date' : 'since')] = date("d-M-Y", $cutoffdate);
4730 4723
 								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
4731 4724
 							}
4732 4725
 							if ($cutoffdate2) {
4733
-								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4726
+								$filter[(empty($cutoffdate) ? 'date' : 'before')] = date("d-M-Y", $cutoffdate2);
4734 4727
 								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
4735 4728
 							}
4736 4729
 						}
@@ -4744,7 +4737,7 @@  discard block
 block discarded – undo
4744 4737
 					$rByUid = true;
4745 4738
 					$_sR = $this->mail_bo->getSortedList(
4746 4739
 						$folder,
4747
-						$sort=0,
4740
+						$sort = 0,
4748 4741
 						$reverse,
4749 4742
 						$filter,
4750 4743
 						$rByUid,
@@ -4754,23 +4747,23 @@  discard block
 block discarded – undo
4754 4747
 				}
4755 4748
 				else
4756 4749
 				{
4757
-					$messageList='all';
4750
+					$messageList = 'all';
4758 4751
 				}
4759 4752
 				try
4760 4753
 				{
4761 4754
 					//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod);
4762
-					$this->mail_bo->deleteMessages(($messageList=='all' ? 'all':$messageList),$folder,(empty($_forceDeleteMethod)?'no':$_forceDeleteMethod));
4755
+					$this->mail_bo->deleteMessages(($messageList == 'all' ? 'all' : $messageList), $folder, (empty($_forceDeleteMethod) ? 'no' : $_forceDeleteMethod));
4763 4756
 				}
4764 4757
 				catch (Api\Exception $e)
4765 4758
 				{
4766
-					$error = str_replace('"',"'",$e->getMessage());
4759
+					$error = str_replace('"', "'", $e->getMessage());
4767 4760
 				}
4768 4761
 			}
4769 4762
 			else
4770 4763
 			{
4771 4764
 				$uidA = self::splitRowID($_messageList['msg'][0]);
4772 4765
 				$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
4773
-				foreach($_messageList['msg'] as $rowID)
4766
+				foreach ($_messageList['msg'] as $rowID)
4774 4767
 				{
4775 4768
 					$hA = self::splitRowID($rowID);
4776 4769
 					$messageList[] = $hA['msgUID'];
@@ -4778,27 +4771,27 @@  discard block
 block discarded – undo
4778 4771
 				try
4779 4772
 				{
4780 4773
 					//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod);
4781
-					$this->mail_bo->deleteMessages($messageList,$folder,(empty($_forceDeleteMethod)?'no':$_forceDeleteMethod));
4774
+					$this->mail_bo->deleteMessages($messageList, $folder, (empty($_forceDeleteMethod) ? 'no' : $_forceDeleteMethod));
4782 4775
 				}
4783 4776
 				catch (Api\Exception $e)
4784 4777
 				{
4785
-					$error = str_replace('"',"'",$e->getMessage());
4778
+					$error = str_replace('"', "'", $e->getMessage());
4786 4779
 				}
4787 4780
 			}
4788 4781
 			$response = Api\Json\Response::get();
4789 4782
 			if (empty($error))
4790 4783
 			{
4791
-				$response->call('app.mail.mail_deleteMessagesShowResult',array('egw_message'=>lang('deleted %1 messages in %2',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($_messageList['msg'])),$folder),'msg'=>$_messageList['msg']));
4784
+				$response->call('app.mail.mail_deleteMessagesShowResult', array('egw_message'=>lang('deleted %1 messages in %2', ($messageList == 'all' || $_messageList['all'] ? ($filtered ? lang('all filtered') : lang('all')) : count($_messageList['msg'])), $folder), 'msg'=>$_messageList['msg']));
4792 4785
 			}
4793 4786
 			else
4794 4787
 			{
4795
-				$error = str_replace('\n',"\n",lang('mailserver reported:\n%1 \ndo you want to proceed by deleting the selected messages immediately (click ok)?\nif not, please try to empty your trashfolder before continuing. (click cancel)',$error));
4796
-				$response->call('app.mail.mail_retryForcedDelete',array('response'=>$error,'messageList'=>$_messageList));
4788
+				$error = str_replace('\n', "\n", lang('mailserver reported:\n%1 \ndo you want to proceed by deleting the selected messages immediately (click ok)?\nif not, please try to empty your trashfolder before continuing. (click cancel)', $error));
4789
+				$response->call('app.mail.mail_retryForcedDelete', array('response'=>$error, 'messageList'=>$_messageList));
4797 4790
 			}
4798 4791
 		}
4799 4792
 		else
4800 4793
 		{
4801
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
4794
+			if (Mail::$debug) error_log(__METHOD__."-> No messages selected.");
4802 4795
 		}
4803 4796
 	}
4804 4797
 
@@ -4812,48 +4805,48 @@  discard block
 block discarded – undo
4812 4805
 	 *
4813 4806
 	 * @return xajax response
4814 4807
 	 */
4815
-	function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_')
4808
+	function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove = 'copy', $_move2ArchiveMarker = '_')
4816 4809
 	{
4817
-		if(Mail::$debug) error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList,true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
4810
+		if (Mail::$debug) error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList, true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
4818 4811
 		Api\Translation::add_app('mail');
4819 4812
 		$folderName = $this->mail_bo->decodeEntityFolderName($_folderName);
4820 4813
 		// only copy or move are supported as method
4821
-		if (!($_copyOrMove=='copy' || $_copyOrMove=='move')) $_copyOrMove='copy';
4822
-		list($targetProfileID,$targetFolder) = explode(self::$delimiter,$folderName,2);
4814
+		if (!($_copyOrMove == 'copy' || $_copyOrMove == 'move')) $_copyOrMove = 'copy';
4815
+		list($targetProfileID, $targetFolder) = explode(self::$delimiter, $folderName, 2);
4823 4816
 		// check if move2archive was called with the correct archiveFolder
4824 4817
 		$archiveFolder = $this->mail_bo->getArchiveFolder();
4825
-		if ($_move2ArchiveMarker=='2' && $targetFolder != $archiveFolder)
4818
+		if ($_move2ArchiveMarker == '2' && $targetFolder != $archiveFolder)
4826 4819
 		{
4827 4820
 			error_log(__METHOD__.__LINE__."#Move to Archive called with:"."$targetProfileID,$targetFolder");
4828 4821
 			$targetProfileID = $this->mail_bo->profileID;
4829 4822
 			$targetFolder = $archiveFolder;
4830 4823
 			error_log(__METHOD__.__LINE__."#Fixed ArchiveFolder:"."$targetProfileID,$targetFolder");
4831 4824
 		}
4832
-		$lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*1);
4825
+		$lastFoldersUsedForMoveCont = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 1);
4833 4826
 		$changeFolderActions = false;
4834 4827
 		//error_log(__METHOD__.__LINE__."#"."$targetProfileID,$targetFolder");
4835 4828
 		//error_log(__METHOD__.__LINE__.array2string($lastFoldersUsedForMoveCont));
4836 4829
 		if (!isset($lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]))
4837 4830
 		{
4838 4831
 			//error_log(__METHOD__.__LINE__.array2string($lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]));
4839
-			if ($lastFoldersUsedForMoveCont[$targetProfileID] && count($lastFoldersUsedForMoveCont[$targetProfileID])>3)
4832
+			if ($lastFoldersUsedForMoveCont[$targetProfileID] && count($lastFoldersUsedForMoveCont[$targetProfileID]) > 3)
4840 4833
 			{
4841 4834
 				$keys = array_keys($lastFoldersUsedForMoveCont[$targetProfileID]);
4842
-				foreach( $keys as &$f)
4835
+				foreach ($keys as &$f)
4843 4836
 				{
4844
-					if (count($lastFoldersUsedForMoveCont[$targetProfileID])>9) unset($lastFoldersUsedForMoveCont[$targetProfileID][$f]);
4837
+					if (count($lastFoldersUsedForMoveCont[$targetProfileID]) > 9) unset($lastFoldersUsedForMoveCont[$targetProfileID][$f]);
4845 4838
 					else break;
4846 4839
 				}
4847 4840
 				//error_log(__METHOD__.__LINE__.array2string($lastFoldersUsedForMoveCont[$targetProfileID]));
4848 4841
 			}
4849 4842
 			//error_log(__METHOD__.__LINE__."#"."$targetProfileID,$targetFolder = $_folderName");
4850
-			$lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]=$folderName;
4843
+			$lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder] = $folderName;
4851 4844
 			$changeFolderActions = true;
4852 4845
 		}
4853 4846
 		$filtered = false;
4854
-		if ($_messageList=='all' || !empty($_messageList['msg']))
4847
+		if ($_messageList == 'all' || !empty($_messageList['msg']))
4855 4848
 		{
4856
-			$error=false;
4849
+			$error = false;
4857 4850
 			if (isset($_messageList['all']) && $_messageList['all'])
4858 4851
 			{
4859 4852
 				// we have both messageIds AND allFlag folder information
@@ -4863,34 +4856,34 @@  discard block
 block discarded – undo
4863 4856
 				if (isset($_messageList['activeFilters']) && $_messageList['activeFilters'])
4864 4857
 				{
4865 4858
 					$query = $_messageList['activeFilters'];
4866
-					if (!empty($query['search']) || !empty($query['filter'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate']))))
4859
+					if (!empty($query['search']) || !empty($query['filter']) || ($query['cat_id'] == 'bydate' && (!empty($query['startdate']) || !empty($query['enddate']))))
4867 4860
 					{
4868 4861
 						//([filterName] => Schnellsuche[type] => quick[string] => ebay[status] => any
4869 4862
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4870 4863
 						{
4871
-							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4872
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4864
+							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
4865
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID] = true;
4873 4866
 						}
4874 4867
 						$filtered = true;
4875 4868
 						$cutoffdate = $cutoffdate2 = null;
4876
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4877
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
4869
+						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'], 'ts'); //SINCE, enddate
4870
+						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'], 'ts'); //BEFORE, startdate
4878 4871
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4879 4872
 						$filter = array(
4880
-							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
4881
-							'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')),
4873
+							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? lang('quicksearch') : lang('subject')),
4874
+							'type' => ($query['cat_id'] ? $query['cat_id'] : (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID] ? 'quick' : 'subject')),
4882 4875
 							'string' => $query['search'],
4883
-							'status' => (!empty($query['filter'])?$query['filter']:'any'),
4876
+							'status' => (!empty($query['filter']) ? $query['filter'] : 'any'),
4884 4877
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4885 4878
 						);
4886
-						if ($query['enddate']||$query['startdate']) {
4879
+						if ($query['enddate'] || $query['startdate']) {
4887 4880
 							$filter['range'] = "BETWEEN";
4888 4881
 							if ($cutoffdate) {
4889
-								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4882
+								$filter[(empty($cutoffdate2) ? 'date' : 'since')] = date("d-M-Y", $cutoffdate);
4890 4883
 								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
4891 4884
 							}
4892 4885
 							if ($cutoffdate2) {
4893
-								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4886
+								$filter[(empty($cutoffdate) ? 'date' : 'before')] = date("d-M-Y", $cutoffdate2);
4894 4887
 								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
4895 4888
 							}
4896 4889
 						}
@@ -4903,70 +4896,70 @@  discard block
 block discarded – undo
4903 4896
 					$rByUid = true;
4904 4897
 					$_sR = $this->mail_bo->getSortedList(
4905 4898
 						$folder,
4906
-						$sort=0,
4899
+						$sort = 0,
4907 4900
 						$reverse,
4908 4901
 						$filter,
4909
-						$rByUid=true,
4902
+						$rByUid = true,
4910 4903
 						false
4911 4904
 					);
4912 4905
 					$messageList = $_sR['match']->ids;
4913
-					foreach($messageList as $uID)
4906
+					foreach ($messageList as $uID)
4914 4907
 					{
4915 4908
 						//error_log(__METHOD__.__LINE__.$uID);
4916
-						if ($_copyOrMove=='move')
4909
+						if ($_copyOrMove == 'move')
4917 4910
 						{
4918
-							$messageListForRefresh[] = self::generateRowID($sourceProfileID, $folderName, $uID, $_prependApp=false);
4911
+							$messageListForRefresh[] = self::generateRowID($sourceProfileID, $folderName, $uID, $_prependApp = false);
4919 4912
 						}
4920 4913
 					}
4921 4914
 				}
4922 4915
 				else
4923 4916
 				{
4924
-					$messageList='all';
4917
+					$messageList = 'all';
4925 4918
 				}
4926 4919
 				try
4927 4920
 				{
4928 4921
 					//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod.' '.$targetProfileID.'/'.$sourceProfileID);
4929
-					$this->mail_bo->moveMessages($targetFolder,$messageList,($_copyOrMove=='copy'?false:true),$folder,false,$sourceProfileID,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
4922
+					$this->mail_bo->moveMessages($targetFolder, $messageList, ($_copyOrMove == 'copy' ? false : true), $folder, false, $sourceProfileID, ($targetProfileID != $sourceProfileID ? $targetProfileID : null));
4930 4923
 				}
4931 4924
 				catch (Api\Exception $e)
4932 4925
 				{
4933
-					$error = str_replace('"',"'",$e->getMessage());
4926
+					$error = str_replace('"', "'", $e->getMessage());
4934 4927
 				}
4935 4928
 			}
4936 4929
 			else
4937 4930
 			{
4938 4931
 				$messageList = array();
4939
-				while(count($_messageList['msg']) > 0)
4932
+				while (count($_messageList['msg']) > 0)
4940 4933
 				{
4941 4934
 					$uidA = self::splitRowID($_messageList['msg'][0]);
4942 4935
 					$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
4943 4936
 					$sourceProfileID = $uidA['profileID'];
4944 4937
 					$moveList = array();
4945
-					foreach($_messageList['msg'] as $rowID)
4938
+					foreach ($_messageList['msg'] as $rowID)
4946 4939
 					{
4947 4940
 						$hA = self::splitRowID($rowID);
4948 4941
 
4949 4942
 						// If folder changes, stop and move what we've got
4950
-						if($hA['folder'] != $folder) break;
4943
+						if ($hA['folder'] != $folder) break;
4951 4944
 
4952 4945
 						array_shift($_messageList['msg']);
4953 4946
 						$messageList[] = $hA['msgUID'];
4954 4947
 						$moveList[] = $hA['msgUID'];
4955
-						if ($_copyOrMove=='move')
4948
+						if ($_copyOrMove == 'move')
4956 4949
 						{
4957
-							$helpvar = explode(self::$delimiter,$rowID);
4950
+							$helpvar = explode(self::$delimiter, $rowID);
4958 4951
 							array_shift($helpvar);
4959
-							$messageListForRefresh[]= implode(self::$delimiter,$helpvar);
4952
+							$messageListForRefresh[] = implode(self::$delimiter, $helpvar);
4960 4953
 						}
4961 4954
 					}
4962 4955
 					try
4963 4956
 					{
4964 4957
 						//error_log(__METHOD__.__LINE__."->".print_r($moveList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod.' '.$targetProfileID.'/'.$sourceProfileID);
4965
-						$this->mail_bo->moveMessages($targetFolder,$moveList,($_copyOrMove=='copy'?false:true),$folder,false,$sourceProfileID,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
4958
+						$this->mail_bo->moveMessages($targetFolder, $moveList, ($_copyOrMove == 'copy' ? false : true), $folder, false, $sourceProfileID, ($targetProfileID != $sourceProfileID ? $targetProfileID : null));
4966 4959
 					}
4967 4960
 					catch (Api\Exception $e)
4968 4961
 					{
4969
-						$error = str_replace('"',"'",$e->getMessage());
4962
+						$error = str_replace('"', "'", $e->getMessage());
4970 4963
 					}
4971 4964
 				}
4972 4965
 			}
@@ -4979,30 +4972,30 @@  discard block
 block discarded – undo
4979 4972
 					unset($lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]);
4980 4973
 					$changeFolderActions = true;
4981 4974
 				}
4982
-				$response->call('egw.message',$error,"error");
4975
+				$response->call('egw.message', $error, "error");
4983 4976
 			}
4984 4977
 			else
4985 4978
 			{
4986
-				if ($_copyOrMove=='copy')
4979
+				if ($_copyOrMove == 'copy')
4987 4980
 				{
4988
-					$response->call('egw.message',lang('copied %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder));
4981
+					$response->call('egw.message', lang('copied %1 message(s) from %2 to %3', ($messageList == 'all' || $_messageList['all'] ? ($filtered ? lang('all filtered') : lang('all')) : count($messageList)), $folder, $targetFolder));
4989 4982
 				}
4990 4983
 				else
4991 4984
 				{
4992
-					$response->call('egw.refresh',lang('moved %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder),'mail',$messageListForRefresh,'delete');
4985
+					$response->call('egw.refresh', lang('moved %1 message(s) from %2 to %3', ($messageList == 'all' || $_messageList['all'] ? ($filtered ? lang('all filtered') : lang('all')) : count($messageList)), $folder, $targetFolder), 'mail', $messageListForRefresh, 'delete');
4993 4986
 				}
4994 4987
 			}
4995 4988
 			if ($changeFolderActions == true)
4996 4989
 			{
4997 4990
 				//error_log(__METHOD__.__LINE__.array2string($lastFoldersUsedForMoveCont));
4998
-				Api\Cache::setCache(Api\Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']),$lastFoldersUsedForMoveCont, $expiration=60*60*1);
4991
+				Api\Cache::setCache(Api\Cache::INSTANCE, 'email', 'lastFolderUsedForMove'.trim($GLOBALS['egw_info']['user']['account_id']), $lastFoldersUsedForMoveCont, $expiration = 60 * 60 * 1);
4999 4992
 				$actionsnew = Etemplate\Widget\Nextmatch::egw_actions(self::get_actions());
5000
-				$response->call('app.mail.mail_rebuildActionsOnList',$actionsnew);
4993
+				$response->call('app.mail.mail_rebuildActionsOnList', $actionsnew);
5001 4994
 			}
5002 4995
 		}
5003 4996
 		else
5004 4997
 		{
5005
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
4998
+			if (Mail::$debug) error_log(__METHOD__."-> No messages selected.");
5006 4999
 		}
5007 5000
 	}
5008 5001
 
@@ -5012,11 +5005,11 @@  discard block
 block discarded – undo
5012 5005
 	 *
5013 5006
 	 * @param type $_id
5014 5007
 	 */
5015
-	function ajax_folderMgmtTree_autoloading ($_id = null)
5008
+	function ajax_folderMgmtTree_autoloading($_id = null)
5016 5009
 	{
5017 5010
 		$mail_ui = new mail_ui();
5018
-		$id = $_id? $_id : $_GET['id'];
5019
-		Etemplate\Widget\Tree::send_quote_json($mail_ui->mail_tree->getTree($id,'',1,true,false,false,false));
5011
+		$id = $_id ? $_id : $_GET['id'];
5012
+		Etemplate\Widget\Tree::send_quote_json($mail_ui->mail_tree->getTree($id, '', 1, true, false, false, false));
5020 5013
 	}
5021 5014
 
5022 5015
 	/**
@@ -5024,15 +5017,15 @@  discard block
 block discarded – undo
5024 5017
 	 *
5025 5018
 	 * @param array $content content of dialog
5026 5019
 	 */
5027
-	function folderManagement (array $content = null)
5020
+	function folderManagement(array $content = null)
5028 5021
 	{
5029 5022
 		$dtmpl = new Etemplate('mail.folder_management');
5030
-		$profileID = $_GET['acc_id']? $_GET['acc_id']: $content['acc_id'];
5031
-		$sel_options['tree'] = $this->mail_tree->getTree(null,$profileID, 1, true, false, false);
5023
+		$profileID = $_GET['acc_id'] ? $_GET['acc_id'] : $content['acc_id'];
5024
+		$sel_options['tree'] = $this->mail_tree->getTree(null, $profileID, 1, true, false, false);
5032 5025
 
5033 5026
 		if (!is_array($content))
5034 5027
 		{
5035
-			$content = array ('acc_id' => $profileID);
5028
+			$content = array('acc_id' => $profileID);
5036 5029
 		}
5037 5030
 
5038 5031
 		$readonlys = array();
@@ -5040,7 +5033,7 @@  discard block
 block discarded – undo
5040 5033
 		$preserv = array(
5041 5034
 			'acc_id' => $content['acc_id'] // preserve acc id to be used in client-side
5042 5035
 		);
5043
-		$dtmpl->exec('mail.mail_ui.folderManagement', $content,$sel_options,$readonlys,$preserv,2);
5036
+		$dtmpl->exec('mail.mail_ui.folderManagement', $content, $sel_options, $readonlys, $preserv, 2);
5044 5037
 	}
5045 5038
 
5046 5039
 	/**
@@ -5050,11 +5043,11 @@  discard block
 block discarded – undo
5050 5043
 	 *
5051 5044
 	 * @param type $_folderName
5052 5045
 	 */
5053
-	function ajax_folderMgmt_delete ($_folderName)
5046
+	function ajax_folderMgmt_delete($_folderName)
5054 5047
 	{
5055 5048
 		if ($_folderName)
5056 5049
 		{
5057
-			$success = $this->ajax_deleteFolder($_folderName,true);
5050
+			$success = $this->ajax_deleteFolder($_folderName, true);
5058 5051
 			$response = Api\Json\Response::get();
5059 5052
 			list(,$folderName) = explode(self::$delimiter, $_folderName);
5060 5053
 			if ($success)
@@ -5063,7 +5056,7 @@  discard block
 block discarded – undo
5063 5056
 			}
5064 5057
 			else
5065 5058
 			{
5066
-				$res = lang("Failed to delete %1",$folderName);
5059
+				$res = lang("Failed to delete %1", $folderName);
5067 5060
 			}
5068 5061
 			$response->data($res);
5069 5062
 		}
Please login to merge, or discard this patch.
Braces   +925 added lines, -257 removed lines patch added patch discarded remove patch
@@ -127,9 +127,15 @@  discard block
 block discarded – undo
127 127
 	function __construct($run_constructor=true)
128 128
 	{
129 129
 		$this->mail_tree = new mail_tree($this);
130
-		if (!$run_constructor) return;
130
+		if (!$run_constructor)
131
+		{
132
+			return;
133
+		}
131 134
 
132
-		if (Mail::$debugTimes) $starttime = microtime (true);
135
+		if (Mail::$debugTimes)
136
+		{
137
+			$starttime = microtime (true);
138
+		}
133 139
 		// no autohide of the sidebox, as we use it for folderlist now.
134 140
 		unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
135 141
 
@@ -140,13 +146,19 @@  discard block
 block discarded – undo
140 146
 		if ($_GET["resetConnection"])
141 147
 		{
142 148
 			unset($_GET["resetConnection"]);
143
-			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Connection Reset triggered: for Profile with ID:'.self::$icServerID);
149
+			if (Mail::$debug)
150
+			{
151
+				error_log(__METHOD__.__LINE__.' Connection Reset triggered: for Profile with ID:'.self::$icServerID);
152
+			}
144 153
 			Mail::unsetCachedObjects(self::$icServerID);
145 154
 		}
146 155
 
147 156
 		try {
148 157
 			$this->mail_bo = Mail::getInstance(true,self::$icServerID, true, false, true);
149
-			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
158
+			if (Mail::$debug)
159
+			{
160
+				error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
161
+			}
150 162
 			//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer));
151 163
 
152 164
 			// RegEx to minimize extra openConnection
@@ -167,9 +179,15 @@  discard block
 block discarded – undo
167 179
 				$response->call('egw.message',$e->getMessage(),'error');
168 180
 			}
169 181
 			// redirect to mail wizard to handle it (redirect works for ajax too), unless index is called. we want the sidebox
170
-			if ($_GET['menuaction'] != 'mail.mail_ui.index') self::callWizard($e->getMessage(),true,'error',false);
182
+			if ($_GET['menuaction'] != 'mail.mail_ui.index')
183
+			{
184
+				self::callWizard($e->getMessage(),true,'error',false);
185
+			}
186
+		}
187
+		if (Mail::$debugTimes)
188
+		{
189
+			Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
171 190
 		}
172
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
173 191
 	}
174 192
 
175 193
 	/**
@@ -229,16 +247,28 @@  discard block
 block discarded – undo
229 247
 	 */
230 248
 	function changeProfile($_icServerID,$unsetCache=false)
231 249
 	{
232
-		if (Mail::$debugTimes) $starttime = microtime (true);
250
+		if (Mail::$debugTimes)
251
+		{
252
+			$starttime = microtime (true);
253
+		}
233 254
 		if (self::$icServerID != $_icServerID)
234 255
 		{
235 256
 			self::$icServerID = $_icServerID;
236 257
 		}
237
-		if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.self::$icServerID.'<->'.$_icServerID);
258
+		if (Mail::$debug)
259
+		{
260
+			error_log(__METHOD__.__LINE__.'->'.self::$icServerID.'<->'.$_icServerID);
261
+		}
238 262
 
239
-		if ($unsetCache) Mail::unsetCachedObjects(self::$icServerID);
263
+		if ($unsetCache)
264
+		{
265
+			Mail::unsetCachedObjects(self::$icServerID);
266
+		}
240 267
 		$this->mail_bo = Mail::getInstance(false,self::$icServerID,true, false, true);
241
-		if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
268
+		if (Mail::$debug)
269
+		{
270
+			error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
271
+		}
242 272
 		// no icServer Object: something failed big time
243 273
 		if (!isset($this->mail_bo->icServer) || $this->mail_bo->icServer->ImapServerId<>$_icServerID)
244 274
 		{
@@ -248,14 +278,23 @@  discard block
 block discarded – undo
248 278
 
249 279
 		// save session varchar
250 280
 		$oldicServerID =& Api\Cache::getSession('mail','activeProfileID');
251
-		if ($oldicServerID <> self::$icServerID) $this->mail_bo->openConnection(self::$icServerID);
252
-		if (true) $oldicServerID = self::$icServerID;
281
+		if ($oldicServerID <> self::$icServerID)
282
+		{
283
+			$this->mail_bo->openConnection(self::$icServerID);
284
+		}
285
+		if (true)
286
+		{
287
+			$oldicServerID = self::$icServerID;
288
+		}
253 289
 		if (!Mail::storeActiveProfileIDToPref($this->mail_bo->icServer, self::$icServerID, true ))
254 290
 		{
255 291
 			throw new Api\Exception(__METHOD__." failed to change Profile to $_icServerID");
256 292
 		}
257 293
 
258
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
294
+		if (Mail::$debugTimes)
295
+		{
296
+			Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
297
+		}
259 298
 	}
260 299
 
261 300
 	/**
@@ -296,7 +335,8 @@  discard block
 block discarded – undo
296 335
 		// got subscribed or unsubscribed by the user
297 336
 		try {
298 337
 			$subscribed = $this->mail_bo->icServer->listSubscribedMailboxes('',0,true);
299
-		} catch (Exception $ex) {
338
+		}
339
+		catch (Exception $ex) {
300 340
 			Framework::message($ex->getMessage());
301 341
 		}
302 342
 
@@ -330,9 +370,18 @@  discard block
 block discarded – undo
330 370
 						list(,$node) = explode($profileId.self::$delimiter, $path);
331 371
 						if ($node)
332 372
 						{
333
-							if (is_array($subscribed) && $subscribed[$node] && !$value['value']) $to_unsubscribe []= $node;
334
-							if (is_array($subscribed) && !$subscribed[$node] && $value['value']) $to_subscribe [] = $node;
335
-							if ($value['value']) $cont[] = $path;
373
+							if (is_array($subscribed) && $subscribed[$node] && !$value['value'])
374
+							{
375
+								$to_unsubscribe []= $node;
376
+							}
377
+							if (is_array($subscribed) && !$subscribed[$node] && $value['value'])
378
+							{
379
+								$to_subscribe [] = $node;
380
+							}
381
+							if ($value['value'])
382
+							{
383
+								$cont[] = $path;
384
+							}
336 385
 						}
337 386
 
338 387
 					}
@@ -421,7 +470,10 @@  discard block
 block discarded – undo
421 470
 		//error_log(__METHOD__.__LINE__.array2string($content));
422 471
 		try	{
423 472
 				//error_log(__METHOD__.__LINE__.function_backtrace());
424
-				if (Mail::$debugTimes) $starttime = microtime (true);
473
+				if (Mail::$debugTimes)
474
+				{
475
+					$starttime = microtime (true);
476
+				}
425 477
 				$this->mail_bo->restoreSessionData();
426 478
 				$sessionFolder = $this->mail_bo->sessionData['mailbox'];
427 479
 				if ($this->mail_bo->folderExists($sessionFolder))
@@ -450,7 +502,10 @@  discard block
 block discarded – undo
450 502
 							'sort'           =>	'DESC',	// IO direction of the sort: 'ASC' or 'DESC'
451 503
 						);
452 504
 					}
453
-					if (Api\Header\UserAgent::mobile()) $content[self::$nm_index]['header_row'] = 'mail.index.header_right';
505
+					if (Api\Header\UserAgent::mobile())
506
+					{
507
+						$content[self::$nm_index]['header_row'] = 'mail.index.header_right';
508
+					}
454 509
 				}
455 510
 
456 511
 				// These must always be set, even if $content is an array
@@ -474,13 +529,16 @@  discard block
 block discarded – undo
474 529
 				}
475 530
 				// call getQuotaRoot asynchronously in getRows by initiating a client Server roundtrip
476 531
 				$quota = false;//$this->mail_bo->getQuotaRoot();
477
-				if($quota !== false && $quota['limit'] != 'NOT SET') {
532
+				if($quota !== false && $quota['limit'] != 'NOT SET')
533
+				{
478 534
 					$quotainfo = $this->quotaDisplay($quota['usage'], $quota['limit']);
479 535
 					$content[self::$nm_index]['quota'] = $sel_options[self::$nm_index]['quota'] = $quotainfo['text'];
480 536
 					$content[self::$nm_index]['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] =  (string)$quotainfo['percent'];
481 537
 					$content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = $quotainfo['class'];
482 538
 					$content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "";
483
-				} else {
539
+				}
540
+				else
541
+				{
484 542
 					$content[self::$nm_index]['quota'] = $sel_options[self::$nm_index]['quota'] = lang("Quota not provided by server");
485 543
 					$content[self::$nm_index]['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = "mail_DisplayNone";
486 544
 					$content[self::$nm_index]['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "mail_DisplayNone";
@@ -488,7 +546,8 @@  discard block
 block discarded – undo
488 546
 				// call gatherVacation asynchronously in getRows by initiating a client Server roundtrip
489 547
 				$vacation = false;//$this->gatherVacation();
490 548
 				//error_log(__METHOD__.__LINE__.' Server:'.self::$icServerID.' Sieve Enabled:'.array2string($vacation));
491
-				if($vacation) {
549
+				if($vacation)
550
+				{
492 551
 					if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date' && $vacation['end_date'] > time()))
493 552
 					{
494 553
 						$dtfrmt = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']/*.' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']!='24'?'h:i a':'H:i')*/;
@@ -522,19 +581,31 @@  discard block
 block discarded – undo
522 581
 					$keywords = array('keyword1','keyword2','keyword3','keyword4','keyword5');
523 582
 					foreach($keywords as &$k)
524 583
 					{
525
-						if (array_key_exists($k,$this->statusTypes)) unset($this->statusTypes[$k]);
584
+						if (array_key_exists($k,$this->statusTypes))
585
+						{
586
+							unset($this->statusTypes[$k]);
587
+						}
526 588
 					}
527 589
 				}
528 590
 
529
-				if (!isset($content[self::$nm_index]['foldertree'])) $content[self::$nm_index]['foldertree'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
530
-				if (!isset($content[self::$nm_index]['selectedFolder'])) $content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
591
+				if (!isset($content[self::$nm_index]['foldertree']))
592
+				{
593
+					$content[self::$nm_index]['foldertree'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
594
+				}
595
+				if (!isset($content[self::$nm_index]['selectedFolder']))
596
+				{
597
+					$content[self::$nm_index]['selectedFolder'] = $this->mail_bo->profileID.self::$delimiter.'INBOX';
598
+				}
531 599
 
532 600
 				$content[self::$nm_index]['foldertree'] = $content[self::$nm_index]['selectedFolder'];
533 601
 
534 602
 				if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
535 603
 				{
536 604
 					Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
537
-					if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
605
+					if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
606
+					{
607
+						Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
608
+					}
538 609
 				}
539 610
 				if (!Mail::$supportsORinQuery[$this->mail_bo->profileID])
540 611
 				{
@@ -556,10 +627,16 @@  discard block
 block discarded – undo
556 627
 				$etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions());
557 628
 
558 629
 				// sending preview toolbar actions
559
-				if ($content['mailSplitter']) $etpl->setElementAttribute('mailPreview[toolbar]', 'actions', $this->get_toolbar_actions());
630
+				if ($content['mailSplitter'])
631
+				{
632
+					$etpl->setElementAttribute('mailPreview[toolbar]', 'actions', $this->get_toolbar_actions());
633
+				}
560 634
 
561 635
 				// We need to send toolbar actions to client-side because view template needs them
562
-				if (Api\Header\UserAgent::mobile()) $sel_options['toolbar'] = $this->get_toolbar_actions();
636
+				if (Api\Header\UserAgent::mobile())
637
+				{
638
+					$sel_options['toolbar'] = $this->get_toolbar_actions();
639
+				}
563 640
 
564 641
 				//we use the category "filter" option as specifier where we want to search (quick, subject, from, to, etc. ....)
565 642
 				if (empty($content[self::$nm_index]['cat_id']) || empty($content[self::$nm_index]['search']))
@@ -567,7 +644,10 @@  discard block
 block discarded – undo
567 644
 					$content[self::$nm_index]['cat_id']=($content[self::$nm_index]['cat_id']?(!Mail::$supportsORinQuery[$this->mail_bo->profileID]&&($content[self::$nm_index]['cat_id']=='quick'||$content[self::$nm_index]['cat_id']=='quickwithcc')?'subject':$content[self::$nm_index]['cat_id']):(Mail::$supportsORinQuery[$this->mail_bo->profileID]?'quick':'subject'));
568 645
 				}
569 646
 				$readonlys = $preserv = array();
570
-				if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
647
+				if (Mail::$debugTimes)
648
+				{
649
+					Mail::logRunTimes($starttime,null,'',__METHOD__.__LINE__);
650
+				}
571 651
 		}
572 652
 		catch (Exception $e)
573 653
 		{
@@ -580,13 +660,19 @@  discard block
 block discarded – undo
580 660
 			}
581 661
 			$etpl->setElementAttribute(self::$nm_index.'[foldertree]','actions', $this->get_tree_actions(false));
582 662
 			$readonlys = $preserv = array();
583
-			if (empty($content)) $content=array();
663
+			if (empty($content))
664
+			{
665
+				$content=array();
666
+			}
584 667
 
585 668
 			self::callWizard($e->getMessage().$e->getMessage().($e->details?', '.$e->details:''),false, 'error',false);
586 669
 			//return false;
587 670
 		}
588 671
 		// Check preview pane is enabled, then show spliter
589
-		if ($this->mail_bo->mailPreferences['previewPane']) $etpl->setElementAttribute('mail.index.spliter', 'template', 'mail.index.nospliter');
672
+		if ($this->mail_bo->mailPreferences['previewPane'])
673
+		{
674
+			$etpl->setElementAttribute('mail.index.spliter', 'template', 'mail.index.nospliter');
675
+		}
590 676
 
591 677
 		return $etpl->exec('mail.mail_ui.index',$content,$sel_options,$readonlys,$preserv);
592 678
 	}
@@ -825,12 +911,18 @@  discard block
 block discarded – undo
825 911
 	public function ajax_foldertree($_nodeID = null,$_subscribedOnly=null)
826 912
 	{
827 913
 		$nodeID = $_GET['id'];
828
-		if (!is_null($_nodeID)) $nodeID = $_nodeID;
914
+		if (!is_null($_nodeID))
915
+		{
916
+			$nodeID = $_nodeID;
917
+		}
829 918
 		$subscribedOnly = (bool)(!is_null($_subscribedOnly)?$_subscribedOnly:!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
830 919
 		$fetchCounters = !is_null($_nodeID);
831 920
 		list($_profileID,$_folderName) = explode(self::$delimiter,$nodeID,2);
832 921
 
833
-		if (!empty($_folderName)) $fetchCounters = true;
922
+		if (!empty($_folderName))
923
+		{
924
+			$fetchCounters = true;
925
+		}
834 926
 
835 927
 		// Check if it is called for refresh root
836 928
 		// then we need to reinitialized the index tree
@@ -842,7 +934,10 @@  discard block
 block discarded – undo
842 934
 		{
843 935
 			$data = $this->mail_tree->getTree($nodeID,$_profileID,0, false,$subscribedOnly,!$this->mail_bo->mailPreferences['showAllFoldersInFolderPane']);
844 936
 		}
845
-		if (!is_null($_nodeID)) return $data;
937
+		if (!is_null($_nodeID))
938
+		{
939
+			return $data;
940
+		}
846 941
 		Etemplate\Widget\Tree::send_quote_json($data);
847 942
 	}
848 943
 
@@ -908,7 +1003,10 @@  discard block
 block discarded – undo
908 1003
 				$accArray[$acc_id] = str_replace(array('<','>'),array('[',']'),$identity_name);// as angle brackets are quoted, display in Javascript messages when used is ugly, so use square brackets instead
909 1004
 			}
910 1005
 		}
911
-		if (!is_array($lastFoldersUsedForMoveCont)) $lastFoldersUsedForMoveCont=array();
1006
+		if (!is_array($lastFoldersUsedForMoveCont))
1007
+		{
1008
+			$lastFoldersUsedForMoveCont=array();
1009
+		}
912 1010
 		foreach (array_keys($lastFoldersUsedForMoveCont) as $pid)
913 1011
 		{
914 1012
 			if ($this->mail_bo->profileID==$pid && isset($lastFoldersUsedForMoveCont[$this->mail_bo->profileID]))
@@ -924,9 +1022,12 @@  discard block
 block discarded – undo
924 1022
 						$moveaction .= $lastFolderUsedForMoveCont;
925 1023
 						//error_log(__METHOD__.__LINE__.'#'.$moveaction);
926 1024
 						//error_log(__METHOD__.__LINE__.'#'.$currentArchiveActionKey);
927
-						if ($this->mail_bo->folderExists($i)) // only 10 entries per mailaccount.Control this on setting the buffered folders
1025
+						if ($this->mail_bo->folderExists($i))
1026
+						{
1027
+							// only 10 entries per mailaccount.Control this on setting the buffered folders
928 1028
 						{
929 1029
 							$fS['profileID'] = $this->mail_bo->profileID;
1030
+						}
930 1031
 							$fS['profileName'] = $accArray[$this->mail_bo->profileID];
931 1032
 							$fS['shortDisplayName'] = $i;
932 1033
 							$moveactions[$moveaction] = $fS;
@@ -946,9 +1047,12 @@  discard block
 block discarded – undo
946 1047
 				foreach ($lastFoldersUsedForMoveCont[$pid] as $i => $lastFolderUsedForMoveCont)
947 1048
 				{
948 1049
 					//error_log(__METHOD__.__LINE__."$i => $lastFolderUsedForMoveCont");
949
-					if (!empty($lastFolderUsedForMoveCont)) // only 10 entries per mailaccount.Control this on setting the buffered folders
1050
+					if (!empty($lastFolderUsedForMoveCont))
1051
+					{
1052
+						// only 10 entries per mailaccount.Control this on setting the buffered folders
950 1053
 					{
951 1054
 						$moveaction = 'move_'.$lastFolderUsedForMoveCont;
1055
+					}
952 1056
 						//error_log(__METHOD__.__LINE__.'#'.$moveaction);
953 1057
 						$fS = array();
954 1058
 						$fS['profileID'] = $pid;
@@ -1051,7 +1155,9 @@  discard block
 block discarded – undo
1051 1155
 				'children' => $children,
1052 1156
 			);
1053 1157
 
1054
-		} else {
1158
+		}
1159
+		else
1160
+		{
1055 1161
 			$group++;
1056 1162
 		}
1057 1163
 
@@ -1327,7 +1433,10 @@  discard block
 block discarded – undo
1327 1433
 					$rows=array();
1328 1434
 					return 0;
1329 1435
 				}
1330
-				if (empty($folderName)) $query['selectedFolder'] = $_profileID.self::$delimiter.'INBOX';
1436
+				if (empty($folderName))
1437
+				{
1438
+					$query['selectedFolder'] = $_profileID.self::$delimiter.'INBOX';
1439
+				}
1331 1440
 			}
1332 1441
 		}
1333 1442
 		if (!isset($mail_ui))
@@ -1342,15 +1451,24 @@  discard block
 block discarded – undo
1342 1451
 				$rows=array();
1343 1452
 				return 0;
1344 1453
 			}
1345
-			if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX';
1454
+			if (empty($query['selectedFolder']))
1455
+			{
1456
+				$query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX';
1457
+			}
1346 1458
 		}
1347 1459
 		//error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort']));
1348 1460
 		//Mail::$debugTimes=true;
1349
-		if (Mail::$debugTimes) $starttime = microtime(true);
1461
+		if (Mail::$debugTimes)
1462
+		{
1463
+			$starttime = microtime(true);
1464
+		}
1350 1465
 		//$query['search'] is the phrase in the searchbox
1351 1466
 
1352 1467
 		$mail_ui->mail_bo->restoreSessionData();
1353
-		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$query['selectedFolder'];
1468
+		if (isset($query['selectedFolder']))
1469
+		{
1470
+			$mail_ui->mail_bo->sessionData['mailbox']=$query['selectedFolder'];
1471
+		}
1354 1472
 		$mail_ui->mail_bo->saveSessionData();
1355 1473
 
1356 1474
 		$sRToFetch = null;
@@ -1361,7 +1479,10 @@  discard block
 block discarded – undo
1361 1479
 			unset($app);
1362 1480
 		}
1363 1481
 		//save selected Folder to sessionData (mailbox)->currentFolder
1364
-		if (isset($query['selectedFolder'])) $mail_ui->mail_bo->sessionData['mailbox']=$_folderName;
1482
+		if (isset($query['selectedFolder']))
1483
+		{
1484
+			$mail_ui->mail_bo->sessionData['mailbox']=$_folderName;
1485
+		}
1365 1486
 		$toSchema = false;//decides to select list schema with column to selected (if false fromaddress is default)
1366 1487
 		if ($mail_ui->mail_bo->folderExists($_folderName))
1367 1488
 		{
@@ -1394,8 +1515,16 @@  discard block
 block discarded – undo
1394 1515
 			}
1395 1516
 			//error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']);
1396 1517
 			$cutoffdate = $cutoffdate2 = null;
1397
-			if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
1398
-			if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
1518
+			if ($query['startdate'])
1519
+			{
1520
+				$cutoffdate = Api\DateTime::to($query['startdate'],'ts');
1521
+			}
1522
+			//SINCE, enddate
1523
+			if ($query['enddate'])
1524
+			{
1525
+				$cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');
1526
+			}
1527
+			//BEFORE, startdate
1399 1528
 			//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
1400 1529
 			$filter = array(
1401 1530
 				'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
@@ -1404,15 +1533,24 @@  discard block
 block discarded – undo
1404 1533
 				'status' => 'any',
1405 1534
 				//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
1406 1535
 			);
1407
-			if ($query['enddate']||$query['startdate']) {
1536
+			if ($query['enddate']||$query['startdate'])
1537
+			{
1408 1538
 				$filter['range'] = "BETWEEN";
1409
-				if ($cutoffdate) {
1539
+				if ($cutoffdate)
1540
+				{
1410 1541
 					$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
1411
-					if (empty($cutoffdate2)) $filter['range'] = "SINCE";
1542
+					if (empty($cutoffdate2))
1543
+					{
1544
+						$filter['range'] = "SINCE";
1545
+					}
1412 1546
 				}
1413
-				if ($cutoffdate2) {
1547
+				if ($cutoffdate2)
1548
+				{
1414 1549
 					$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
1415
-					if (empty($cutoffdate)) $filter['range'] = "BEFORE";
1550
+					if (empty($cutoffdate))
1551
+					{
1552
+						$filter['range'] = "BEFORE";
1553
+					}
1416 1554
 				}
1417 1555
 			}
1418 1556
 		}
@@ -1464,7 +1602,10 @@  discard block
 block discarded – undo
1464 1602
 				$rowsFetched['messages'] = $_sR['count'];
1465 1603
 				$ids = $_sR['match']->ids;
1466 1604
 				// if $sR is false, something failed fundamentally
1467
-				if($reverse === true) $ids = ($ids===false?array():array_reverse((array)$ids));
1605
+				if($reverse === true)
1606
+				{
1607
+					$ids = ($ids===false?array():array_reverse((array)$ids));
1608
+				}
1468 1609
 				$sR = array_slice((array)$ids,($offset==0?0:$offset-1),$maxMessages); // we need only $maxMessages of uids
1469 1610
 				$sRToFetch = $sR;//array_slice($sR,0,50); // we fetch only the headers of a subset of the fetched uids
1470 1611
 				//error_log(__METHOD__.__LINE__.' Rows fetched (UID only):'.count($sR).' Data:'.array2string($sR));
@@ -1530,7 +1671,10 @@  discard block
 block discarded – undo
1530 1671
 				}
1531 1672
 				else
1532 1673
 				{
1533
-					if (!empty($v)) $sortResult['header'][] = array('uid'=>$v);
1674
+					if (!empty($v))
1675
+					{
1676
+						$sortResult['header'][] = array('uid'=>$v);
1677
+					}
1534 1678
 				}
1535 1679
 			}
1536 1680
 		}
@@ -1539,15 +1683,24 @@  discard block
 block discarded – undo
1539 1683
 			$sortResult = $sortResultwH;
1540 1684
 		}
1541 1685
 		$rowsFetched['rowsFetched'] = count($sortResult['header']);
1542
-		if (empty($rowsFetched['messages'])) $rowsFetched['messages'] = $rowsFetched['rowsFetched'];
1686
+		if (empty($rowsFetched['messages']))
1687
+		{
1688
+			$rowsFetched['messages'] = $rowsFetched['rowsFetched'];
1689
+		}
1543 1690
 
1544 1691
 		//error_log(__METHOD__.__LINE__.' Rows fetched:'.$rowsFetched.' Data:'.array2string($sortResult));
1545 1692
 		$cols = array('row_id','uid','status','attachments','subject','address','toaddress','fromaddress','ccaddress','additionaltoaddress','date','size','modified','bodypreview');
1546
-		if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE') unset($cols[0]);
1693
+		if ($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']=='EGW_SELECTMODE_TOGGLE')
1694
+		{
1695
+			unset($cols[0]);
1696
+		}
1547 1697
 		$rows = $mail_ui->header2gridelements($sortResult['header'],$cols, $_folderName, $folderType=$toSchema);
1548 1698
 		//error_log(__METHOD__.__LINE__.array2string($rows));
1549 1699
 
1550
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'],__METHOD__.__LINE__);
1700
+		if (Mail::$debugTimes)
1701
+		{
1702
+			Mail::logRunTimes($starttime,null,'Folder:'.$_folderName.' Start:'.$query['start'].' NumRows:'.$query['num_rows'],__METHOD__.__LINE__);
1703
+		}
1551 1704
 		return $rowsFetched['messages'];
1552 1705
 	}
1553 1706
 
@@ -1649,7 +1802,10 @@  discard block
 block discarded – undo
1649 1802
 					$actionsenabled[$act]= $actions['mark']['children']['setLabel']['children'][$act];
1650 1803
 					break;
1651 1804
 				default:
1652
-					if (isset($actions[$act])) $actionsenabled[$act]=$actions[$act];
1805
+					if (isset($actions[$act]))
1806
+					{
1807
+						$actionsenabled[$act]=$actions[$act];
1808
+					}
1653 1809
 			}
1654 1810
 		}
1655 1811
 		unset($actionsenabled['drag_mail']);
@@ -1671,7 +1827,10 @@  discard block
 block discarded – undo
1671 1827
 	 */
1672 1828
 	public function header2gridelements($_headers, $cols, $_folderName, $_folderType=0)
1673 1829
 	{
1674
-		if (Mail::$debugTimes) $starttime = microtime(true);
1830
+		if (Mail::$debugTimes)
1831
+		{
1832
+			$starttime = microtime(true);
1833
+		}
1675 1834
 		$rv = array();
1676 1835
 		$i=0;
1677 1836
 		foreach((array)$_headers as $header)
@@ -1684,17 +1843,50 @@  discard block
 block discarded – undo
1684 1843
 			$data['row_id']=$this->createRowID($_folderName,$message_uid);
1685 1844
 
1686 1845
 			$flags = "";
1687
-			if(!empty($header['recent'])) $flags .= "R";
1688
-			if(!empty($header['flagged'])) $flags .= "F";
1689
-			if(!empty($header['answered'])) $flags .= "A";
1690
-			if(!empty($header['forwarded'])) $flags .= "W";
1691
-			if(!empty($header['deleted'])) $flags .= "D";
1692
-			if(!empty($header['seen'])) $flags .= "S";
1693
-			if(!empty($header['label1'])) $flags .= "1";
1694
-			if(!empty($header['label2'])) $flags .= "2";
1695
-			if(!empty($header['label3'])) $flags .= "3";
1696
-			if(!empty($header['label4'])) $flags .= "4";
1697
-			if(!empty($header['label5'])) $flags .= "5";
1846
+			if(!empty($header['recent']))
1847
+			{
1848
+				$flags .= "R";
1849
+			}
1850
+			if(!empty($header['flagged']))
1851
+			{
1852
+				$flags .= "F";
1853
+			}
1854
+			if(!empty($header['answered']))
1855
+			{
1856
+				$flags .= "A";
1857
+			}
1858
+			if(!empty($header['forwarded']))
1859
+			{
1860
+				$flags .= "W";
1861
+			}
1862
+			if(!empty($header['deleted']))
1863
+			{
1864
+				$flags .= "D";
1865
+			}
1866
+			if(!empty($header['seen']))
1867
+			{
1868
+				$flags .= "S";
1869
+			}
1870
+			if(!empty($header['label1']))
1871
+			{
1872
+				$flags .= "1";
1873
+			}
1874
+			if(!empty($header['label2']))
1875
+			{
1876
+				$flags .= "2";
1877
+			}
1878
+			if(!empty($header['label3']))
1879
+			{
1880
+				$flags .= "3";
1881
+			}
1882
+			if(!empty($header['label4']))
1883
+			{
1884
+				$flags .= "4";
1885
+			}
1886
+			if(!empty($header['label5']))
1887
+			{
1888
+				$flags .= "5";
1889
+			}
1698 1890
 
1699 1891
 			$data["status"] = "<span class=\"status_img\"></span>";
1700 1892
 			//error_log(__METHOD__.array2string($header).' Flags:'.$flags);
@@ -1702,41 +1894,53 @@  discard block
 block discarded – undo
1702 1894
 			// the css for this row
1703 1895
 			$is_recent=false;
1704 1896
 			$css_styles = array("mail");
1705
-			if ($header['deleted']) {
1897
+			if ($header['deleted'])
1898
+			{
1706 1899
 				$css_styles[] = 'deleted';
1707 1900
 			}
1708
-			if ($header['recent'] && !($header['deleted'] || $header['seen'] || $header['answered'] || $header['forwarded'])) {
1901
+			if ($header['recent'] && !($header['deleted'] || $header['seen'] || $header['answered'] || $header['forwarded']))
1902
+			{
1709 1903
 				$css_styles[] = 'recent';
1710 1904
 				$is_recent=true;
1711 1905
 			}
1712
-			if ($header['priority'] < 3) {
1906
+			if ($header['priority'] < 3)
1907
+			{
1713 1908
 				$css_styles[] = 'prio_high';
1714 1909
 			}
1715
-			if ($header['flagged']) {
1910
+			if ($header['flagged'])
1911
+			{
1716 1912
 				$css_styles[] = 'flagged';
1717 1913
 			}
1718
-			if (!$header['seen']) {
1914
+			if (!$header['seen'])
1915
+			{
1719 1916
 				$css_styles[] = 'unseen'; // different status image for recent // solved via css !important
1720 1917
 			}
1721
-			if ($header['answered']) {
1918
+			if ($header['answered'])
1919
+			{
1722 1920
 				$css_styles[] = 'replied';
1723 1921
 			}
1724
-			if ($header['forwarded']) {
1922
+			if ($header['forwarded'])
1923
+			{
1725 1924
 				$css_styles[] = 'forwarded';
1726 1925
 			}
1727
-			if ($header['label1']) {
1926
+			if ($header['label1'])
1927
+			{
1728 1928
 				$css_styles[] = 'labelone';
1729 1929
 			}
1730
-			if ($header['label2']) {
1930
+			if ($header['label2'])
1931
+			{
1731 1932
 				$css_styles[] = 'labeltwo';
1732 1933
 			}
1733
-			if ($header['label3']) {
1934
+			if ($header['label3'])
1935
+			{
1734 1936
 				$css_styles[] = 'labelthree';
1735 1937
 			}
1736
-			if ($header['label4']) {
1938
+			if ($header['label4'])
1939
+			{
1737 1940
 				$css_styles[] = 'labelfour';
1738 1941
 			}
1739
-			if ($header['label5']) {
1942
+			if ($header['label5'])
1943
+			{
1740 1944
 				$css_styles[] = 'labelfive';
1741 1945
 			}
1742 1946
 
@@ -1753,10 +1957,13 @@  discard block
 block discarded – undo
1753 1957
 				$header['subject'] = preg_replace($search,$replace,$header['subject']);
1754 1958
 				// curly brackets get messed up by the template!
1755 1959
 
1756
-				if (!empty($header['subject'])) {
1960
+				if (!empty($header['subject']))
1961
+				{
1757 1962
 					// make the subject shorter if it is to long
1758 1963
 					$subject = $header['subject'];
1759
-				} else {
1964
+				}
1965
+				else
1966
+				{
1760 1967
 					$subject = '('. lang('no subject') .')';
1761 1968
 				}
1762 1969
 
@@ -1798,15 +2005,22 @@  discard block
 block discarded – undo
1798 2005
 					}
1799 2006
 
1800 2007
 					$attachmentFlag = $image;
1801
-				} else {
2008
+				}
2009
+				else
2010
+				{
1802 2011
 					$attachmentFlag ='&nbsp;';
1803 2012
 				}
1804 2013
 				// show priority flag
1805
-				if ($header['priority'] < 3) {
2014
+				if ($header['priority'] < 3)
2015
+				{
1806 2016
 					 $image = Api\Html::image('mail','prio_high');
1807
-				} elseif ($header['priority'] > 3) {
2017
+				}
2018
+				elseif ($header['priority'] > 3)
2019
+				{
1808 2020
 					$image = Api\Html::image('mail','prio_low');
1809
-				} else {
2021
+				}
2022
+				else
2023
+				{
1810 2024
 					$image = '';
1811 2025
 				}
1812 2026
 				// show a flag for flagged messages
@@ -1848,26 +2062,53 @@  discard block
 block discarded – undo
1848 2062
 			}
1849 2063
 
1850 2064
 			if (in_array("size", $cols))
1851
-				$data["size"] = $header['size']; /// size
2065
+			{
2066
+							$data["size"] = $header['size'];
2067
+			}
2068
+			/// size
1852 2069
 
1853 2070
 			$data["class"] = implode(' ', $css_styles);
1854 2071
 			//translate style-classes back to flags
1855 2072
 			$data['flags'] = Array();
1856
-			if ($header['seen']) $data["flags"]['read'] = 'read';
1857
-			foreach ($css_styles as &$flag) {
2073
+			if ($header['seen'])
2074
+			{
2075
+				$data["flags"]['read'] = 'read';
2076
+			}
2077
+			foreach ($css_styles as &$flag)
2078
+			{
1858 2079
 				if ($flag!='mail')
1859 2080
 				{
1860
-					if ($flag=='labelone') {$data["flags"]['label1'] = 'label1';}
1861
-					elseif ($flag=='labeltwo') {$data["flags"]['label2'] = 'label2';}
1862
-					elseif ($flag=='labelthree') {$data["flags"]['label3'] = 'label3';}
1863
-					elseif ($flag=='labelfour') {$data["flags"]['label4'] = 'label4';}
1864
-					elseif ($flag=='labelfive') {$data["flags"]['label5'] = 'label5';}
1865
-					elseif ($flag=='unseen') {unset($data["flags"]['read']);}
1866
-					else $data["flags"][$flag] = $flag;
2081
+					if ($flag=='labelone')
2082
+					{
2083
+$data["flags"]['label1'] = 'label1';}
2084
+					elseif ($flag=='labeltwo')
2085
+					{
2086
+$data["flags"]['label2'] = 'label2';}
2087
+					elseif ($flag=='labelthree')
2088
+					{
2089
+$data["flags"]['label3'] = 'label3';}
2090
+					elseif ($flag=='labelfour')
2091
+					{
2092
+$data["flags"]['label4'] = 'label4';}
2093
+					elseif ($flag=='labelfive')
2094
+					{
2095
+$data["flags"]['label5'] = 'label5';}
2096
+					elseif ($flag=='unseen')
2097
+					{
2098
+unset($data["flags"]['read']);}
2099
+					else {
2100
+						$data["flags"][$flag] = $flag;
2101
+					}
1867 2102
 				}
1868 2103
 			}
1869
-			if ($header['disposition-notification-to']) $data['dispositionnotificationto'] = $header['disposition-notification-to'];
1870
-			if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto'])) unset($data['dispositionnotificationto']);
2104
+			if ($header['disposition-notification-to'])
2105
+			{
2106
+				$data['dispositionnotificationto'] = $header['disposition-notification-to'];
2107
+			}
2108
+			if (($header['mdnsent']||$header['mdnnotsent']|$header['seen'])&&isset($data['dispositionnotificationto']))
2109
+			{
2110
+				unset($data['dispositionnotificationto']);
2111
+			}
1871 2112
 			$data['attachmentsBlock'] = $imageHTMLBlock;
1872 2113
 			$data['address'] = ($_folderType?$data["toaddress"]:$data["fromaddress"]);
1873 2114
 			if (in_array("bodypreview", $cols)&&$header['bodypreview'])
@@ -1877,7 +2118,10 @@  discard block
 block discarded – undo
1877 2118
 			$rv[] = $data;
1878 2119
 			//error_log(__METHOD__.__LINE__.array2string($data));
1879 2120
 		}
1880
-		if (Mail::$debugTimes) Mail::logRunTimes($starttime,null,'Folder:'.$_folderName,__METHOD__.__LINE__);
2121
+		if (Mail::$debugTimes)
2122
+		{
2123
+			Mail::logRunTimes($starttime,null,'Folder:'.$_folderName,__METHOD__.__LINE__);
2124
+		}
1881 2125
 
1882 2126
 		// ToDo: call this ONLY if labels change
1883 2127
 		Etemplate\Widget::setElementAttribute('toolbar', 'actions', $this->get_toolbar_actions());
@@ -1892,8 +2136,14 @@  discard block
 block discarded – undo
1892 2136
 	 */
1893 2137
 	function displayHeader()
1894 2138
 	{
1895
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
1896
-		if(isset($_GET['part'])) $partID = $_GET['part'];
2139
+		if(isset($_GET['id']))
2140
+		{
2141
+			$rowID	= $_GET['id'];
2142
+		}
2143
+		if(isset($_GET['part']))
2144
+		{
2145
+			$partID = $_GET['part'];
2146
+		}
1897 2147
 
1898 2148
 		$hA = self::splitRowID($rowID);
1899 2149
 		$uid = $hA['msgUID'];
@@ -1917,7 +2167,8 @@  discard block
 block discarded – undo
1917 2167
 		$rawheaders 	= "";
1918 2168
 		// create it new, with good line breaks
1919 2169
 		reset($newRawHeaders);
1920
-		while(list($key,$value) = @each($newRawHeaders)) {
2170
+		while(list($key,$value) = @each($newRawHeaders))
2171
+		{
1921 2172
 			$rawheaders .= wordwrap($value, 90, "\n     ");
1922 2173
 		}
1923 2174
 
@@ -1940,12 +2191,24 @@  discard block
 block discarded – undo
1940 2191
 	 */
1941 2192
 	function displayMessage($_requesteddata = null)
1942 2193
 	{
1943
-		if (is_null($_requesteddata)) $_requesteddata = $_GET;
2194
+		if (is_null($_requesteddata))
2195
+		{
2196
+			$_requesteddata = $_GET;
2197
+		}
1944 2198
 
1945 2199
 		$preventRedirect=false;
1946
-		if(isset($_requesteddata['id'])) $rowID	= $_requesteddata['id'];
1947
-		if(isset($_requesteddata['part'])) $partID = $_requesteddata['part']!='null'?$_requesteddata['part']:null;
1948
-		if(isset($_requesteddata['mode'])) $preventRedirect   = (($_requesteddata['mode']=='display' || $_requesteddata['mode'] == 'print')?true:false);
2200
+		if(isset($_requesteddata['id']))
2201
+		{
2202
+			$rowID	= $_requesteddata['id'];
2203
+		}
2204
+		if(isset($_requesteddata['part']))
2205
+		{
2206
+			$partID = $_requesteddata['part']!='null'?$_requesteddata['part']:null;
2207
+		}
2208
+		if(isset($_requesteddata['mode']))
2209
+		{
2210
+			$preventRedirect   = (($_requesteddata['mode']=='display' || $_requesteddata['mode'] == 'print')?true:false);
2211
+		}
1949 2212
 
1950 2213
 		$hA = self::splitRowID($rowID);
1951 2214
 		$uid = $hA['msgUID'];
@@ -1958,8 +2221,14 @@  discard block
 block discarded – undo
1958 2221
 			$this->changeProfile($icServerID);
1959 2222
 		}
1960 2223
 		$htmlOptions = $this->mail_bo->htmlOptions;
1961
-		if (!empty($_requesteddata['tryastext'])) $htmlOptions  = "only_if_no_text";
1962
-		if (!empty($_requesteddata['tryashtml'])) $htmlOptions  = "always_display";
2224
+		if (!empty($_requesteddata['tryastext']))
2225
+		{
2226
+			$htmlOptions  = "only_if_no_text";
2227
+		}
2228
+		if (!empty($_requesteddata['tryashtml']))
2229
+		{
2230
+			$htmlOptions  = "always_display";
2231
+		}
1963 2232
 
1964 2233
 		//error_log(__METHOD__.__LINE__.array2string($hA));
1965 2234
 		if (($this->mail_bo->isDraftFolder($mailbox)) && $_requesteddata['mode'] == 'print')
@@ -1983,14 +2252,20 @@  discard block
 block discarded – undo
1983 2252
 			$error_msg[] = lang("In Mailbox: %1, with ID: %2, and PartID: %3",$mailbox,$uid,$partID);
1984 2253
 			Framework::message($e->getMessage(), 'error');
1985 2254
 		}
1986
-		if (!empty($uid)) $this->mail_bo->getFlags($uid);
2255
+		if (!empty($uid))
2256
+		{
2257
+			$this->mail_bo->getFlags($uid);
2258
+		}
1987 2259
 		$envelope	= $this->mail_bo->getMessageEnvelope($uid, $partID,true,$mailbox);
1988 2260
 		//error_log(__METHOD__.__LINE__.array2string($envelope));
1989 2261
 		$this->mail_bo->getMessageRawHeader($uid, $partID,$mailbox);
1990 2262
 		$fetchEmbeddedImages = false;
1991 2263
 		// if we are in HTML so its likely that we should show the embedded images; as a result
1992 2264
 		// we do NOT want to see those, that are embedded in the list of attachments
1993
-		if ($htmlOptions !='always_display') $fetchEmbeddedImages = true;
2265
+		if ($htmlOptions !='always_display')
2266
+		{
2267
+			$fetchEmbeddedImages = true;
2268
+		}
1994 2269
 		$attachments	= $this->mail_bo->getMessageAttachments($uid, $partID, null, $fetchEmbeddedImages,true,true,$mailbox);
1995 2270
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
1996 2271
 		$attachmentHTMLBlock = self::createAttachmentBlock($attachments, $rowID, $uid, $mailbox);
@@ -2006,11 +2281,17 @@  discard block
 block discarded – undo
2006 2281
 		$subject = $this->mail_bo->decode_subject(preg_replace($nonDisplayAbleCharacters,'',$envelope['SUBJECT']),false);
2007 2282
 
2008 2283
 		// Set up data for taglist widget(s)
2009
-		if ($envelope['FROM']==$envelope['SENDER']) unset($envelope['SENDER']);
2284
+		if ($envelope['FROM']==$envelope['SENDER'])
2285
+		{
2286
+			unset($envelope['SENDER']);
2287
+		}
2010 2288
 		$sel_options = array();
2011 2289
 		foreach(array('SENDER','FROM','TO','CC','BCC') as $field)
2012 2290
 		{
2013
-			if (!isset($envelope[$field])) continue;
2291
+			if (!isset($envelope[$field]))
2292
+			{
2293
+				continue;
2294
+			}
2014 2295
 			foreach($envelope[$field] as $field_data)
2015 2296
 			{
2016 2297
 				//error_log(__METHOD__.__LINE__.array2string($field_data));
@@ -2024,7 +2305,10 @@  discard block
 block discarded – undo
2024 2305
 		}
2025 2306
 		$actionsenabled = $this->getDisplayToolbarActions();
2026 2307
 		$content['displayToolbaractions'] = json_encode($actionsenabled);
2027
-		if (empty($subject)) $subject = lang('no subject');
2308
+		if (empty($subject))
2309
+		{
2310
+			$subject = lang('no subject');
2311
+		}
2028 2312
 		$content['msg'] = (is_array($error_msg)?implode("<br>",$error_msg):$error_msg);
2029 2313
 		// Send mail ID so we can use it for actions
2030 2314
 		$content['mail_id'] = $rowID;
@@ -2035,8 +2319,14 @@  discard block
 block discarded – undo
2035 2319
 		$content['mail_displaydate'] = Mail::_strtotime($headers['DATE'],'ts',true);
2036 2320
 		$content['mail_displaysubject'] = $subject;
2037 2321
 		$linkData = array('menuaction'=>"mail.mail_ui.loadEmailBody","_messageID"=>$rowID);
2038
-		if (!empty($partID)) $linkData['_partID']=$partID;
2039
-		if ($htmlOptions != $this->mail_bo->htmlOptions) $linkData['_htmloptions']=$htmlOptions;
2322
+		if (!empty($partID))
2323
+		{
2324
+			$linkData['_partID']=$partID;
2325
+		}
2326
+		if ($htmlOptions != $this->mail_bo->htmlOptions)
2327
+		{
2328
+			$linkData['_htmloptions']=$htmlOptions;
2329
+		}
2040 2330
 		$content['mailDisplayBodySrc'] = Egw::link('/index.php',$linkData);
2041 2331
 		$content['mail_displayattachments'] = $attachmentHTMLBlock;
2042 2332
 		$content['mail_id']=$rowID;
@@ -2104,7 +2394,8 @@  discard block
 block discarded – undo
2104 2394
 	{
2105 2395
 		$attachmentHTMLBlock='';
2106 2396
 		$attachmentHTML = array();
2107
-		if (is_array($attachments) && count($attachments) > 0) {
2397
+		if (is_array($attachments) && count($attachments) > 0)
2398
+		{
2108 2399
 			$url_img_vfs = Api\Html::image('filemanager','navbar', lang('Filemanager'), ' height="16"');
2109 2400
 			$url_img_vfs_save_all = Api\Html::image('mail','save_all', lang('Save all'));
2110 2401
 
@@ -2114,7 +2405,10 @@  discard block
 block discarded – undo
2114 2405
 				$attachmentHTML[$key]['filename'] = Api\Translation::convert_jsonsafe($attachmentHTML[$key]['filename'],'utf-8');
2115 2406
 				//error_log(array2string($value));
2116 2407
 				//error_log(strtoupper($value['mimeType']) .'<->'. Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']));
2117
-				if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']);
2408
+				if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM'))
2409
+				{
2410
+					$value['mimeType'] = Api\MimeMagic::filename2mime($attachmentHTML[$key]['filename']);
2411
+				}
2118 2412
 				$attachmentHTML[$key]['type']=$value['mimeType'];
2119 2413
 				$attachmentHTML[$key]['mimetype'] = Api\MimeMagic::mime2label($value['mimeType']);
2120 2414
 				$hA = self::splitRowID($rowID);
@@ -2157,8 +2451,15 @@  discard block
 block discarded – undo
2157 2451
 						$sfxMimeType = $value['mimeType'];
2158 2452
 						$buff = explode('.',$value['name']);
2159 2453
 						$suffix = '';
2160
-						if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
2161
-						if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2454
+						if (is_array($buff))
2455
+						{
2456
+							$suffix = array_pop($buff);
2457
+						}
2458
+						// take the last extension to check with ext2mime
2459
+						if (!empty($suffix))
2460
+						{
2461
+							$sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2462
+						}
2162 2463
 						if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD')
2163 2464
 						{
2164 2465
 							$attachments[$key]['mimeType'] = $sfxMimeType;
@@ -2327,9 +2628,12 @@  discard block
 block discarded – undo
2327 2628
 	function quotaDisplay($_usage, $_limit)
2328 2629
 	{
2329 2630
 
2330
-		if($_limit == 0) {
2631
+		if($_limit == 0)
2632
+		{
2331 2633
 			$quotaPercent=100;
2332
-		} else {
2634
+		}
2635
+		else
2636
+		{
2333 2637
 			$quotaPercent=round(($_usage*100)/$_limit);
2334 2638
 		}
2335 2639
 
@@ -2337,22 +2641,33 @@  discard block
 block discarded – undo
2337 2641
 		$quotaUsage=Mail::show_readable_size($_usage*1024);
2338 2642
 
2339 2643
 
2340
-		if($quotaPercent > 90 && $_limit>0) {
2644
+		if($quotaPercent > 90 && $_limit>0)
2645
+		{
2341 2646
 			$quotaBG='mail-index_QuotaRed';
2342
-		} elseif($quotaPercent > 80 && $_limit>0) {
2647
+		}
2648
+		elseif($quotaPercent > 80 && $_limit>0)
2649
+		{
2343 2650
 			$quotaBG='mail-index_QuotaYellow';
2344
-		} else {
2651
+		}
2652
+		else
2653
+		{
2345 2654
 			$quotaBG='mail-index_QuotaGreen';
2346 2655
 		}
2347 2656
 
2348
-		if($_limit > 0) {
2657
+		if($_limit > 0)
2658
+		{
2349 2659
 			$quotaText = $quotaUsage .'/'.$quotaLimit;
2350
-		} else {
2660
+		}
2661
+		else
2662
+		{
2351 2663
 			$quotaText = $quotaUsage;
2352 2664
 		}
2353 2665
 
2354
-		if($quotaPercent > 50) {
2355
-		} else {
2666
+		if($quotaPercent > 50)
2667
+		{
2668
+		}
2669
+		else
2670
+		{
2356 2671
 		}
2357 2672
 		$quota['class'] = $quotaBG;
2358 2673
 		$quota['text'] = lang('Quota: %1',$quotaText);
@@ -2370,7 +2685,10 @@  discard block
 block discarded – undo
2370 2685
 		$uid	= $_GET['uid'];
2371 2686
 		$cid	= base64_decode($_GET['cid']);
2372 2687
 		$partID = urldecode($_GET['partID']);
2373
-		if (!empty($_GET['mailbox'])) $mailbox  = base64_decode($_GET['mailbox']);
2688
+		if (!empty($_GET['mailbox']))
2689
+		{
2690
+			$mailbox  = base64_decode($_GET['mailbox']);
2691
+		}
2374 2692
 
2375 2693
 		//error_log(__METHOD__.__LINE__.":$uid, $cid, $partID");
2376 2694
 		$this->mail_bo->reopen($mailbox);
@@ -2402,7 +2720,10 @@  discard block
 block discarded – undo
2402 2720
 
2403 2721
 	function getAttachment()
2404 2722
 	{
2405
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
2723
+		if(isset($_GET['id']))
2724
+		{
2725
+			$rowID	= $_GET['id'];
2726
+		}
2406 2727
 
2407 2728
 		$hA = self::splitRowID($rowID);
2408 2729
 		$uid = $hA['msgUID'];
@@ -2435,10 +2756,20 @@  discard block
 block discarded – undo
2435 2756
 				$sfxMimeType = $attachment['type'];
2436 2757
 				$buff = explode('.',$attachment['filename']);
2437 2758
 				$suffix = '';
2438
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
2439
-				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2759
+				if (is_array($buff))
2760
+				{
2761
+					$suffix = array_pop($buff);
2762
+				}
2763
+				// take the last extension to check with ext2mime
2764
+				if (!empty($suffix))
2765
+				{
2766
+					$sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2767
+				}
2440 2768
 				$attachment['type'] = $sfxMimeType;
2441
-				if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') $attachment['type'] = strtoupper($sfxMimeType);
2769
+				if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD')
2770
+				{
2771
+					$attachment['type'] = strtoupper($sfxMimeType);
2772
+				}
2442 2773
 			}
2443 2774
 			//error_log(__METHOD__.print_r($attachment,true));
2444 2775
 			if (strtoupper($attachment['type']) == 'TEXT/CALENDAR' || strtoupper($attachment['type']) == 'TEXT/X-VCALENDAR')
@@ -2447,7 +2778,10 @@  discard block
 block discarded – undo
2447 2778
 				$calendar_ical = new calendar_ical();
2448 2779
 				$eventid = $calendar_ical->search($attachment['attachment'],-1);
2449 2780
 				//error_log(__METHOD__.array2string($eventid));
2450
-				if (!$eventid) $eventid = -1;
2781
+				if (!$eventid)
2782
+				{
2783
+					$eventid = -1;
2784
+				}
2451 2785
 				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true,0,'',null,$attachment['charset']);
2452 2786
 				//error_log(__METHOD__.$event);
2453 2787
 				if ((int)$event > 0)
@@ -2473,7 +2807,10 @@  discard block
 block discarded – undo
2473 2807
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
2474 2808
 					$contact = $addressbook_vcal->find_contact($vcard,false);
2475 2809
 				}
2476
-				if (!$contact) $contact = null;
2810
+				if (!$contact)
2811
+				{
2812
+					$contact = null;
2813
+				}
2477 2814
 				// if there are not enough fields in the vcard (or the parser was unable to correctly parse the vcard (as of VERSION:3.0 created by MSO))
2478 2815
 				if ($contact || count($vcard)>2)
2479 2816
 				{
@@ -2507,9 +2844,18 @@  discard block
 block discarded – undo
2507 2844
 	function saveMessage()
2508 2845
 	{
2509 2846
 		$display = false;
2510
-		if(isset($_GET['id'])) $rowID	= $_GET['id'];
2511
-		if(isset($_GET['part'])) $partID = $_GET['part'];
2512
-		if (isset($_GET['location'])&& ($_GET['location']=='display'||$_GET['location']=='filemanager')) $display	= $_GET['location'];
2847
+		if(isset($_GET['id']))
2848
+		{
2849
+			$rowID	= $_GET['id'];
2850
+		}
2851
+		if(isset($_GET['part']))
2852
+		{
2853
+			$partID = $_GET['part'];
2854
+		}
2855
+		if (isset($_GET['location'])&& ($_GET['location']=='display'||$_GET['location']=='filemanager'))
2856
+		{
2857
+			$display	= $_GET['location'];
2858
+		}
2513 2859
 
2514 2860
 		$hA = self::splitRowID($rowID);
2515 2861
 		$uid = $hA['msgUID'];
@@ -2598,7 +2944,10 @@  discard block
 block discarded – undo
2598 2944
 			{
2599 2945
 				$succeeded = true;
2600 2946
 			}
2601
-			if ($fp) fclose($fp);
2947
+			if ($fp)
2948
+			{
2949
+				fclose($fp);
2950
+			}
2602 2951
 			if ($succeeded)
2603 2952
 			{
2604 2953
 				unset($headers['SUBJECT']);//already in filename
@@ -2648,7 +2997,8 @@  discard block
 block discarded – undo
2648 2997
 		 *
2649 2998
 		 * @return array an array of parameters
2650 2999
 		 */
2651
-		$getParams = function ($id) {
3000
+		$getParams = function ($id)
3001
+		{
2652 3002
 			list($app,$user,$serverID,$mailbox,$uid,$part,$is_winmail,$name) = explode('::',$id,8);
2653 3003
 			$lId = implode('::',array($app,$user,$serverID,$mailbox,$uid));
2654 3004
 			$hA = mail_ui::splitRowID($lId);
@@ -2684,7 +3034,10 @@  discard block
 block discarded – undo
2684 3034
 		{
2685 3035
 			$params = $getParams($id);
2686 3036
 			// when downloading a single file, name is not set
2687
-			if (!$params['name']&&isset($_GET['name'])&&!$isMultipleDownload) $params['name'] = $_GET['name'];
3037
+			if (!$params['name']&&isset($_GET['name'])&&!$isMultipleDownload)
3038
+			{
3039
+				$params['name'] = $_GET['name'];
3040
+			}
2688 3041
 			if ($params['icServer'] && $params['icServer'] != $this->mail_bo->profileID)
2689 3042
 			{
2690 3043
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@@ -2697,7 +3050,10 @@  discard block
 block discarded – undo
2697 3050
 				// Try to find the right content for file id
2698 3051
 				foreach ($attachments as $key => $val)
2699 3052
 				{
2700
-					if ($key == $params['is_winmail']) $attachment = $val;
3053
+					if ($key == $params['is_winmail'])
3054
+					{
3055
+						$attachment = $val;
3056
+					}
2701 3057
 				}
2702 3058
 			}
2703 3059
 			else
@@ -2744,7 +3100,10 @@  discard block
 block discarded – undo
2744 3100
 	{
2745 3101
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
2746 3102
 		// First, get all attachment IDs
2747
-		if(isset($_GET['id'])) $message_id	= $_GET['id'];
3103
+		if(isset($_GET['id']))
3104
+		{
3105
+			$message_id	= $_GET['id'];
3106
+		}
2748 3107
 		//error_log(__METHOD__.__LINE__.$message_id);
2749 3108
 		$rememberServerID = $this->mail_bo->profileID;
2750 3109
 		if(!is_numeric($message_id))
@@ -2771,7 +3130,10 @@  discard block
 block discarded – undo
2771 3130
 		//get_home_dir may fetch the users startfolder if set; if not writeable, action will fail. TODO: use temp_dir
2772 3131
 		$homedir = '/home/'.$GLOBALS['egw_info']['user']['account_lid'];
2773 3132
 		$temp_path = $homedir/*Vfs::get_home_dir()*/ . "/.mail_$message_id";
2774
-		if(Vfs::is_dir($temp_path)) Vfs::remove ($temp_path);
3133
+		if(Vfs::is_dir($temp_path))
3134
+		{
3135
+			Vfs::remove ($temp_path);
3136
+		}
2775 3137
 
2776 3138
 		// Add subject to path, so it gets used as the file name
2777 3139
 		$path = $temp_path . '/' . ($header['SUBJECT'] ? Vfs::encodePathComponent($header['SUBJECT']) : lang('mail')) .'/';
@@ -2796,7 +3158,10 @@  discard block
 block discarded – undo
2796 3158
 				foreach ($tnefAttachments as $key => $val)
2797 3159
 				{
2798 3160
 					error_log(__METHOD__.' winmail = '.$key);
2799
-					if ($key == $file['is_winmail']) $attachment = $val;
3161
+					if ($key == $file['is_winmail'])
3162
+					{
3163
+						$attachment = $val;
3164
+					}
2800 3165
 				}
2801 3166
 			}
2802 3167
 			else
@@ -2804,7 +3169,10 @@  discard block
 block discarded – undo
2804 3169
 				$attachment = $this->mail_bo->getAttachment($message_id,$file['partID'],$file['is_winmail'],false,true);
2805 3170
 			}
2806 3171
 			$success=true;
2807
-			if (empty($file['filename'])) $file['filename'] = $file['name'];
3172
+			if (empty($file['filename']))
3173
+			{
3174
+				$file['filename'] = $file['name'];
3175
+			}
2808 3176
 			if(in_array($path.$file['filename'], $file_list))
2809 3177
 			{
2810 3178
 				$dupe_count[$path.$file['filename']]++;
@@ -2818,8 +3186,14 @@  discard block
 block discarded – undo
2818 3186
 				$success=false;
2819 3187
 				Framework::message("Unable to zip {$file['filename']}",'error');
2820 3188
 			}
2821
-			if ($success) $file_list[] = $path.$file['filename'];
2822
-			if ($fp) fclose($fp);
3189
+			if ($success)
3190
+			{
3191
+				$file_list[] = $path.$file['filename'];
3192
+			}
3193
+			if ($fp)
3194
+			{
3195
+				fclose($fp);
3196
+			}
2823 3197
 		}
2824 3198
 		$this->mail_bo->closeConnection();
2825 3199
 		if ($rememberServerID != $this->mail_bo->profileID)
@@ -2846,7 +3220,10 @@  discard block
 block discarded – undo
2846 3220
 		$this->uid = $uid;
2847 3221
 		$this->partID = $partID;
2848 3222
 		$bufferHtmlOptions = $this->mail_bo->htmlOptions;
2849
-		if (empty($htmlOptions)) $htmlOptions = $this->mail_bo->htmlOptions;
3223
+		if (empty($htmlOptions))
3224
+		{
3225
+			$htmlOptions = $this->mail_bo->htmlOptions;
3226
+		}
2850 3227
 		// fetching structure now, to supply it to getMessageBody and getMessageAttachment, so it does not get fetched twice
2851 3228
 		$structure = $this->mail_bo->getStructure($uid, $partID, $mailbox, false);
2852 3229
 		$bodyParts	= $this->mail_bo->getMessageBody($uid, ($htmlOptions?$htmlOptions:''), $partID, $structure, false, $mailbox);
@@ -2910,10 +3287,16 @@  discard block
 block discarded – undo
2910 3287
 <table width="100%" style="table-layout:fixed"><tr><td class="td_display">';
2911 3288
 
2912 3289
 		$EndBody = '</td></tr></table></div>';
2913
-		if ($fullPageTags) $EndBody .= "</body></html>";
2914
-		if ($print)	{
3290
+		if ($fullPageTags)
3291
+		{
3292
+			$EndBody .= "</body></html>";
3293
+		}
3294
+		if ($print)
3295
+		{
2915 3296
 			print $BeginBody. $body .$EndBody;
2916
-		} else {
3297
+		}
3298
+		else
3299
+		{
2917 3300
 			return $BeginBody. $body .$EndBody;
2918 3301
 		}
2919 3302
 	}
@@ -2929,9 +3312,14 @@  discard block
 block discarded – undo
2929 3312
 		$body = '';
2930 3313
 
2931 3314
 		//error_log(__METHOD__.array2string($bodyParts)); //exit;
2932
-		if (empty($bodyParts)) return "";
2933
-		foreach((array)$bodyParts as $singleBodyPart) {
2934
-			if (!isset($singleBodyPart['body'])) {
3315
+		if (empty($bodyParts))
3316
+		{
3317
+			return "";
3318
+		}
3319
+		foreach((array)$bodyParts as $singleBodyPart)
3320
+		{
3321
+			if (!isset($singleBodyPart['body']))
3322
+			{
2935 3323
 				$singleBodyPart['body'] = $this->getdisplayableBody($singleBodyPart,$modifyURI,$useTidy);
2936 3324
 				$body .= $singleBodyPart['body'];
2937 3325
 				continue;
@@ -2942,7 +3330,8 @@  discard block
 block discarded – undo
2942 3330
 				$body .= '';
2943 3331
 				continue;
2944 3332
 			}
2945
-			if(!empty($body)) {
3333
+			if(!empty($body))
3334
+			{
2946 3335
 				$body .= '<hr style="border:dotted 1px silver;">';
2947 3336
 			}
2948 3337
 			//error_log($singleBodyPart['body']);
@@ -2980,16 +3369,25 @@  discard block
 block discarded – undo
2980 3369
 				$newBody	= @htmlentities($singleBodyPart['body'],ENT_QUOTES, strtoupper(Mail::$displayCharset));
2981 3370
 				//error_log(__METHOD__.__LINE__.'..'.$newBody);
2982 3371
 				// if empty and charset is utf8 try sanitizing the string in question
2983
-				if (empty($newBody) && strtolower($singleBodyPart['charSet'])=='utf-8') $newBody = @htmlentities(iconv('utf-8', 'utf-8', $singleBodyPart['body']),ENT_QUOTES, strtoupper(Mail::$displayCharset));
3372
+				if (empty($newBody) && strtolower($singleBodyPart['charSet'])=='utf-8')
3373
+				{
3374
+					$newBody = @htmlentities(iconv('utf-8', 'utf-8', $singleBodyPart['body']),ENT_QUOTES, strtoupper(Mail::$displayCharset));
3375
+				}
2984 3376
 				// if the conversion to htmlentities fails somehow, try without specifying the charset, which defaults to iso-
2985
-				if (empty($newBody)) $newBody    = htmlentities($singleBodyPart['body'],ENT_QUOTES);
3377
+				if (empty($newBody))
3378
+				{
3379
+					$newBody    = htmlentities($singleBodyPart['body'],ENT_QUOTES);
3380
+				}
2986 3381
 
2987 3382
 				// search http[s] links and make them as links available again
2988 3383
 				// to understand what's going on here, have a look at
2989 3384
 				// http://www.php.net/manual/en/function.preg-replace.php
2990 3385
 
2991 3386
 				// create links for websites
2992
-				if ($modifyURI) $newBody = Api\Html::activate_links($newBody);
3387
+				if ($modifyURI)
3388
+				{
3389
+					$newBody = Api\Html::activate_links($newBody);
3390
+				}
2993 3391
 				//error_log(__METHOD__.__LINE__.'..'.$newBody);
2994 3392
 				// redirect links for websites if you use no cookies
2995 3393
 				#if (!($GLOBALS['egw_info']['server']['usecookies']))
@@ -3031,10 +3429,13 @@  discard block
 block discarded – undo
3031 3429
 					{
3032 3430
 						$newBody = $cleaned;
3033 3431
 					}
3034
-					if (!$preserveHTML)	// ToDo KL: $preserveHTML is NOT initialised, so always if is dead code
3432
+					if (!$preserveHTML)
3433
+					{
3434
+						// ToDo KL: $preserveHTML is NOT initialised, so always if is dead code
3035 3435
 					{
3036 3436
 						// filter only the 'body', as we only want that part, if we throw away the Api\Html
3037 3437
 						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
3438
+					}
3038 3439
 						if ($matches[2])
3039 3440
 						{
3040 3441
 							$hasOther = true;
@@ -3056,7 +3457,10 @@  discard block
 block discarded – undo
3056 3457
 					// as we switched off HTMLaweds tidy functionality
3057 3458
 					$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
3058 3459
 					$newBody = $htmLawed->run($newBody,Mail::$htmLawed_config);
3059
-					if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
3460
+					if ($hasOther && $preserveHTML)
3461
+					{
3462
+						$newBody = $matches[1]. $newBody. $matches[3];
3463
+					}
3060 3464
 					$alreadyHtmlLawed=true;
3061 3465
 				}
3062 3466
 				// do the cleanup, set for the use of purifier
@@ -3161,7 +3565,10 @@  discard block
 block discarded – undo
3161 3565
 		*/
3162 3566
 		$replace_callback = function ($matches) use ($_mailbox,$_uid, $_partID,  $_type)
3163 3567
 		{
3164
-			if (!$_type)	return false;
3568
+			if (!$_type)
3569
+			{
3570
+				return false;
3571
+			}
3165 3572
 			$CID = '';
3166 3573
 			// Build up matches according to selected type
3167 3574
 			switch ($_type)
@@ -3204,9 +3611,12 @@  discard block
 block discarded – undo
3204 3611
 							$attachment = $bo->getAttachmentByCID($_uid, $CID, $_partID);
3205 3612
 
3206 3613
 							// only use data uri for "smaller" images, as otherwise the first display of the mail takes to long
3207
-							if (($attachment instanceof Horde_Mime_Part) && $attachment->getBytes() < 8192)	// msie=8 allows max 32k data uris
3614
+							if (($attachment instanceof Horde_Mime_Part) && $attachment->getBytes() < 8192)
3615
+							{
3616
+								// msie=8 allows max 32k data uris
3208 3617
 							{
3209 3618
 								$bo->fetchPartContents($_uid, $attachment);
3619
+							}
3210 3620
 								$cache[$imageURL] = 'data:'.$attachment->getType().';base64,'.base64_encode($attachment->getContents());
3211 3621
 							}
3212 3622
 							else
@@ -3278,7 +3688,10 @@  discard block
 block discarded – undo
3278 3688
 			}
3279 3689
 			$destination = $content['FOLDER'][0];
3280 3690
 
3281
-			if (stripos($destination,self::$delimiter)!==false) list($icServerID,$destination) = explode(self::$delimiter,$destination,2);
3691
+			if (stripos($destination,self::$delimiter)!==false)
3692
+			{
3693
+				list($icServerID,$destination) = explode(self::$delimiter,$destination,2);
3694
+			}
3282 3695
 			if ($icServerID && $icServerID != $this->mail_bo->profileID)
3283 3696
 			{
3284 3697
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@@ -3303,14 +3716,26 @@  discard block
 block discarded – undo
3303 3716
 			if (!$importFailed)
3304 3717
 			{
3305 3718
 				list($width, $height) = explode('x', Link::get_registry('mail', 'add_popup'));
3306
-				if ($width > 0 && $height > 0) Api\Json\Response::get()->call('resizeTo', $width, $height);
3719
+				if ($width > 0 && $height > 0)
3720
+				{
3721
+					Api\Json\Response::get()->call('resizeTo', $width, $height);
3722
+				}
3307 3723
 				ExecMethod2('mail.mail_ui.displayMessage',$linkData);
3308 3724
 				return;
3309 3725
 			}
3310 3726
 		}
3311
-		if (!is_array($content)) $content = array();
3312
-		if (empty($content['FOLDER'])) $content['FOLDER']=(array)$this->mail_bo->getDraftFolder();
3313
-		if (!empty($content['FOLDER'])) $sel_options['FOLDER']=mail_compose::ajax_searchFolder(0,true);
3727
+		if (!is_array($content))
3728
+		{
3729
+			$content = array();
3730
+		}
3731
+		if (empty($content['FOLDER']))
3732
+		{
3733
+			$content['FOLDER']=(array)$this->mail_bo->getDraftFolder();
3734
+		}
3735
+		if (!empty($content['FOLDER']))
3736
+		{
3737
+			$sel_options['FOLDER']=mail_compose::ajax_searchFolder(0,true);
3738
+		}
3314 3739
 
3315 3740
 		$etpl = new Etemplate('mail.importMessage');
3316 3741
 		$etpl->setElementAttribute('uploadForImport','onFinish','app.mail.uploadForImport');
@@ -3330,7 +3755,10 @@  discard block
 block discarded – undo
3330 3755
 	{
3331 3756
 		$importfailed = false;
3332 3757
 		//error_log(__METHOD__.__LINE__.array2string($_formData));
3333
-		if (empty($_formData['file'])) $_formData['file'] = $_formData['tmp_name'];
3758
+		if (empty($_formData['file']))
3759
+		{
3760
+			$_formData['file'] = $_formData['tmp_name'];
3761
+		}
3334 3762
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
3335 3763
 		try
3336 3764
 		{
@@ -3361,10 +3789,14 @@  discard block
 block discarded – undo
3361 3789
 				$alert_msg .= lang("Import of message %1 failed. Destination Folder not set.",$_formData['name']);
3362 3790
 			}
3363 3791
 			$delimiter = $this->mail_bo->getHierarchyDelimiter();
3364
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
3792
+			if($_folder=='INBOX'.$delimiter)
3793
+			{
3794
+				$_folder='INBOX';
3795
+			}
3365 3796
 			if ($importfailed === false)
3366 3797
 			{
3367
-				if ($this->mail_bo->folderExists($_folder,true)) {
3798
+				if ($this->mail_bo->folderExists($_folder,true))
3799
+				{
3368 3800
 					try
3369 3801
 					{
3370 3802
 						$messageUid = $this->mail_bo->appendMessage($_folder,
@@ -3425,7 +3857,10 @@  discard block
 block discarded – undo
3425 3857
 	 */
3426 3858
 	function importMessageFromVFS2DraftAndDisplay($formData='',$mode='display')
3427 3859
 	{
3428
-		if (empty($formData)) if (isset($_REQUEST['formData'])) $formData = $_REQUEST['formData'];
3860
+		if (empty($formData))
3861
+		{
3862
+			if (isset($_REQUEST['formData'])) $formData = $_REQUEST['formData'];
3863
+		}
3429 3864
 		//error_log(__METHOD__.__LINE__.':'.array2string($formData).' Mode:'.$mode.'->'.function_backtrace());
3430 3865
 		$draftFolder = $this->mail_bo->getDraftFolder(false);
3431 3866
 		$importID = Mail::getRandomString();
@@ -3439,15 +3874,26 @@  discard block
 block discarded – undo
3439 3874
 		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && empty($formData['name']))
3440 3875
 		{
3441 3876
 			$buff = explode('/',$formData['file']);
3442
-			if (is_array($buff)) $formData['name'] = array_pop($buff); // take the last part as name
3877
+			if (is_array($buff))
3878
+			{
3879
+				$formData['name'] = array_pop($buff);
3880
+			}
3881
+			// take the last part as name
3443 3882
 		}
3444 3883
 		// type should be set to meet the requirements of checkFileBasics
3445 3884
 		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && empty($formData['type']))
3446 3885
 		{
3447 3886
 			$buff = explode('.',$formData['file']);
3448 3887
 			$suffix = '';
3449
-			if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
3450
-			if (!empty($suffix)) $formData['type'] = Api\MimeMagic::ext2mime($suffix);
3888
+			if (is_array($buff))
3889
+			{
3890
+				$suffix = array_pop($buff);
3891
+			}
3892
+			// take the last extension to check with ext2mime
3893
+			if (!empty($suffix))
3894
+			{
3895
+				$formData['type'] = Api\MimeMagic::ext2mime($suffix);
3896
+			}
3451 3897
 		}
3452 3898
 		// size should be set to meet the requirements of checkFileBasics
3453 3899
 		if (parse_url($formData['file'],PHP_URL_SCHEME) == 'vfs' && !isset($formData['size']))
@@ -3490,17 +3936,35 @@  discard block
 block discarded – undo
3490 3936
 	function loadEmailBody($_messageID=null,$_partID=null,$_htmloptions=null)
3491 3937
 	{
3492 3938
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
3493
-		if (!$_messageID && !empty($_GET['_messageID'])) $_messageID = $_GET['_messageID'];
3494
-		if (!$_partID && !empty($_GET['_partID'])) $_partID = $_GET['_partID'];
3495
-		if (!$_htmloptions && !empty($_GET['_htmloptions'])) $_htmloptions = $_GET['_htmloptions'];
3496
-		if(Mail::$debug) error_log(__METHOD__."->".print_r($_messageID,true).",$_partID,$_htmloptions");
3497
-		if (empty($_messageID)) return "";
3939
+		if (!$_messageID && !empty($_GET['_messageID']))
3940
+		{
3941
+			$_messageID = $_GET['_messageID'];
3942
+		}
3943
+		if (!$_partID && !empty($_GET['_partID']))
3944
+		{
3945
+			$_partID = $_GET['_partID'];
3946
+		}
3947
+		if (!$_htmloptions && !empty($_GET['_htmloptions']))
3948
+		{
3949
+			$_htmloptions = $_GET['_htmloptions'];
3950
+		}
3951
+		if(Mail::$debug)
3952
+		{
3953
+			error_log(__METHOD__."->".print_r($_messageID,true).",$_partID,$_htmloptions");
3954
+		}
3955
+		if (empty($_messageID))
3956
+		{
3957
+			return "";
3958
+		}
3498 3959
 		$uidA = self::splitRowID($_messageID);
3499 3960
 		$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
3500 3961
 		$messageID = $uidA['msgUID'];
3501 3962
 		$icServerID = $uidA['profileID'];
3502 3963
 		//something went wrong. there is a $_messageID but no $messageID: means $_messageID is crippeled
3503
-		if (empty($messageID)) return "";
3964
+		if (empty($messageID))
3965
+		{
3966
+			return "";
3967
+		}
3504 3968
 		if ($icServerID && $icServerID != $this->mail_bo->profileID)
3505 3969
 		{
3506 3970
 			//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@@ -3533,7 +3997,11 @@  discard block
 block discarded – undo
3533 3997
 				list($profileID,$folderName) = explode(self::$delimiter,$_folderName,2);
3534 3998
 				if (is_numeric($profileID))
3535 3999
 				{
3536
-					if ($profileID != $this->mail_bo->profileID) continue; // only current connection
4000
+					if ($profileID != $this->mail_bo->profileID)
4001
+					{
4002
+						continue;
4003
+					}
4004
+					// only current connection
3537 4005
 					if ($folderName)
3538 4006
 					{
3539 4007
 						try
@@ -3544,7 +4012,10 @@  discard block
 block discarded – undo
3544 4012
 						{
3545 4013
 							continue;
3546 4014
 						}
3547
-						if (in_array($fS['shortDisplayName'],Mail::$autoFolders)) $fS['shortDisplayName']=lang($fS['shortDisplayName']);
4015
+						if (in_array($fS['shortDisplayName'],Mail::$autoFolders))
4016
+						{
4017
+							$fS['shortDisplayName']=lang($fS['shortDisplayName']);
4018
+						}
3548 4019
 						//error_log(__METHOD__.__LINE__.array2string($fS));
3549 4020
 						if ($fS['unseen'])
3550 4021
 						{
@@ -3585,7 +4056,11 @@  discard block
 block discarded – undo
3585 4056
 			list($profileID,$parentFolderName) = explode(self::$delimiter,$decodedFolderName,2);
3586 4057
 			if (is_numeric($profileID))
3587 4058
 			{
3588
-				if ($profileID != $this->mail_bo->profileID) return; // only current connection
4059
+				if ($profileID != $this->mail_bo->profileID)
4060
+				{
4061
+					return;
4062
+				}
4063
+				// only current connection
3589 4064
 				$del = $this->mail_bo->getHierarchyDelimiter(false);
3590 4065
 				//$del = $prefix = '';
3591 4066
 				//$nameSpace = $this->mail_bo->_getNameSpaces();
@@ -3625,7 +4100,10 @@  discard block
 block discarded – undo
3625 4100
 				$nA = explode($del,$_newName);
3626 4101
 
3627 4102
 				//error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName");
3628
-				if (!!empty($parentFolderName)) $oldFolderInfo = $this->mail_bo->getFolderStatus($parentFolderName,false);
4103
+				if (!!empty($parentFolderName))
4104
+				{
4105
+					$oldFolderInfo = $this->mail_bo->getFolderStatus($parentFolderName,false);
4106
+				}
3629 4107
 				//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
3630 4108
 
3631 4109
 				$this->mail_bo->reopen('INBOX');
@@ -3646,9 +4124,15 @@  discard block
 block discarded – undo
3646 4124
 							$errorMessage .= $error;
3647 4125
 						}
3648 4126
 					}
3649
-					if ($c==count($nA)) $created=true;
4127
+					if ($c==count($nA))
4128
+					{
4129
+						$created=true;
4130
+					}
4131
+				}
4132
+				if (!empty($parentName))
4133
+				{
4134
+					$this->mail_bo->reopen($parentName);
3650 4135
 				}
3651
-				if (!empty($parentName)) $this->mail_bo->reopen($parentName);
3652 4136
 			}
3653 4137
 			//error_log(__METHOD__.__LINE__.array2string($oA));
3654 4138
 			if ($created===true)
@@ -3684,7 +4168,10 @@  discard block
 block discarded – undo
3684 4168
 	 */
3685 4169
 	function ajax_renameFolder($_folderName, $_newName)
3686 4170
 	{
3687
-		if (Mail::$debug) error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName));
4171
+		if (Mail::$debug)
4172
+		{
4173
+			error_log(__METHOD__.__LINE__.' OldFolderName:'.array2string($_folderName).' NewName:'.array2string($_newName));
4174
+		}
3688 4175
 		if ($_folderName)
3689 4176
 		{
3690 4177
 			Api\Translation::add_app('mail');
@@ -3696,7 +4183,11 @@  discard block
 block discarded – undo
3696 4183
 			$hasChildren = false;
3697 4184
 			if (is_numeric($profileID))
3698 4185
 			{
3699
-				if ($profileID != $this->mail_bo->profileID) return; // only current connection
4186
+				if ($profileID != $this->mail_bo->profileID)
4187
+				{
4188
+					return;
4189
+				}
4190
+				// only current connection
3700 4191
 				$pA = explode($del,$folderName);
3701 4192
 				array_pop($pA);
3702 4193
 				$parentFolder = implode($del,$pA);
@@ -3837,8 +4328,15 @@  discard block
 block discarded – undo
3837 4328
 		list($profileID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
3838 4329
 		// if pref and required mode dont match -> reset the folderObject cache to ensure
3839 4330
 		// that we get what we request
3840
-		if ($_subscribedOnly != $oldPrefForSubscribedOnly) $this->mail_bo->resetFolderObjectCache($profileID);
3841
-		if ($profileID != $this->mail_bo->profileID) return; // only current connection
4331
+		if ($_subscribedOnly != $oldPrefForSubscribedOnly)
4332
+		{
4333
+			$this->mail_bo->resetFolderObjectCache($profileID);
4334
+		}
4335
+		if ($profileID != $this->mail_bo->profileID)
4336
+		{
4337
+			return;
4338
+		}
4339
+		// only current connection
3842 4340
 		if (!empty($folderName))
3843 4341
 		{
3844 4342
 			$parentFolder=(!empty($folderName)?$folderName:'INBOX');
@@ -3913,7 +4411,10 @@  discard block
 block discarded – undo
3913 4411
 	 */
3914 4412
 	function ajax_MoveFolder($_folderName, $_target)
3915 4413
 	{
3916
-		if (Mail::$debug) error_log(__METHOD__.__LINE__."Move Folder: $_folderName to Target: $_target");
4414
+		if (Mail::$debug)
4415
+		{
4416
+			error_log(__METHOD__.__LINE__."Move Folder: $_folderName to Target: $_target");
4417
+		}
3917 4418
 		if ($_folderName)
3918 4419
 		{
3919 4420
 			$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
@@ -3924,7 +4425,11 @@  discard block
 block discarded – undo
3924 4425
 			$hasChildren = false;
3925 4426
 			if (is_numeric($profileID))
3926 4427
 			{
3927
-				if ($profileID != $this->mail_bo->profileID || $profileID != $newProfileID) return; // only current connection
4428
+				if ($profileID != $this->mail_bo->profileID || $profileID != $newProfileID)
4429
+				{
4430
+					return;
4431
+				}
4432
+				// only current connection
3928 4433
 				$pA = explode($del,$folderName);
3929 4434
 				$namePart = array_pop($pA);
3930 4435
 				$_newName = $namePart;
@@ -3935,10 +4440,13 @@  discard block
 block discarded – undo
3935 4440
 					(($oldParentFolder === $parentFolder) || //$oldParentFolder == $parentFolder means move on same level
3936 4441
 					(($oldParentFolder != $parentFolder &&
3937 4442
 					strlen($parentFolder)>0 && strlen($folderName)>0 &&
3938
-					strpos($parentFolder,$folderName)===false)))) // indicates that we move the older up the tree within its own branch
4443
+					strpos($parentFolder,$folderName)===false))))
4444
+				{
4445
+					// indicates that we move the older up the tree within its own branch
3939 4446
 				{
3940 4447
 					//error_log(__METHOD__.__LINE__."$folderName, $parentFolder, $_newName");
3941 4448
 					$oldFolderInfo = $this->mail_bo->getFolderStatus($folderName,false,false,false);
4449
+				}
3942 4450
 					//error_log(__METHOD__.__LINE__.array2string($oldFolderInfo));
3943 4451
 					if (!empty($oldFolderInfo['attributes']) && stripos(array2string($oldFolderInfo['attributes']),'\hasnochildren')=== false)
3944 4452
 					{
@@ -4021,8 +4529,14 @@  discard block
 block discarded – undo
4021 4529
 					$profileID.self::$delimiter.$oldParentFolder=>$oldFolderInfo['shortDisplayName'],
4022 4530
 					$profileID.self::$delimiter.$parentFolder=>$folderInfo['shortDisplayName']);
4023 4531
 				// if we move the folder within the same parent-branch of the tree, there is no need no refresh the upper part
4024
-				if (strlen($parentFolder)>strlen($oldParentFolder) && strpos($parentFolder,$oldParentFolder)!==false) unset($refreshData[$profileID.self::$delimiter.$parentFolder]);
4025
-				if (count($refreshData)>1 && strlen($oldParentFolder)>strlen($parentFolder) && strpos($oldParentFolder,$parentFolder)!==false) unset($refreshData[$profileID.self::$delimiter.$oldParentFolder]);
4532
+				if (strlen($parentFolder)>strlen($oldParentFolder) && strpos($parentFolder,$oldParentFolder)!==false)
4533
+				{
4534
+					unset($refreshData[$profileID.self::$delimiter.$parentFolder]);
4535
+				}
4536
+				if (count($refreshData)>1 && strlen($oldParentFolder)>strlen($parentFolder) && strpos($oldParentFolder,$parentFolder)!==false)
4537
+				{
4538
+					unset($refreshData[$profileID.self::$delimiter.$oldParentFolder]);
4539
+				}
4026 4540
 
4027 4541
 				// Send full info back in the response
4028 4542
 				foreach($refreshData as $folder => &$name)
@@ -4058,7 +4572,11 @@  discard block
 block discarded – undo
4058 4572
 			$hasChildren = false;
4059 4573
 			if (is_numeric($profileID))
4060 4574
 			{
4061
-				if ($profileID != $this->mail_bo->profileID) return; // only current connection
4575
+				if ($profileID != $this->mail_bo->profileID)
4576
+				{
4577
+					return;
4578
+				}
4579
+				// only current connection
4062 4580
 				$pA = explode($del,$folderName);
4063 4581
 				array_pop($pA);
4064 4582
 				if (strtoupper($folderName)!= 'INBOX')
@@ -4084,7 +4602,9 @@  discard block
 block discarded – undo
4084 4602
 						}
4085 4603
 						krsort($ftD,SORT_NUMERIC);//sort per level
4086 4604
 						//we iterate per level of depth of the subtree, deepest nesting is to be deleted first, and then up the tree
4087
-						foreach($ftD as $k => $lc)//collection per level
4605
+						foreach($ftD as $k => $lc)
4606
+						{
4607
+							//collection per level
4088 4608
 						{
4089 4609
 							foreach($lc as $f)//folders contained in that level
4090 4610
 							{
@@ -4092,8 +4612,12 @@  discard block
 block discarded – undo
4092 4612
 								{
4093 4613
 									//error_log(__METHOD__.__LINE__.array2string($f).'<->'.$folderName);
4094 4614
 									$this->mail_bo->deleteFolder($f);
4615
+						}
4095 4616
 									$success = true;
4096
-									if ($f==$folderName) $oA[$_folderName] = $oldFolderInfo['shortDisplayName'];
4617
+									if ($f==$folderName)
4618
+									{
4619
+										$oA[$_folderName] = $oldFolderInfo['shortDisplayName'];
4620
+									}
4097 4621
 								}
4098 4622
 								catch (Exception $e)
4099 4623
 								{
@@ -4123,7 +4647,10 @@  discard block
 block discarded – undo
4123 4647
 					$msg = lang("refused to delete folder INBOX");
4124 4648
 				}
4125 4649
 			}
4126
-			if ($_return) return $success;
4650
+			if ($_return)
4651
+			{
4652
+				return $success;
4653
+			}
4127 4654
 			$response = Api\Json\Response::get();
4128 4655
 			if ($success)
4129 4656
 			{
@@ -4210,24 +4737,35 @@  discard block
 block discarded – undo
4210 4737
 				// Create mail app object
4211 4738
 				$mail = new mail_ui();
4212 4739
 
4213
-				if (empty($icServerID)) $icServerID = $mail->Mail->profileID;
4214
-				if ($icServerID != $mail->Mail->profileID) return;
4740
+				if (empty($icServerID))
4741
+				{
4742
+					$icServerID = $mail->Mail->profileID;
4743
+				}
4744
+				if ($icServerID != $mail->Mail->profileID)
4745
+				{
4746
+					return;
4747
+				}
4215 4748
 
4216 4749
 				$vacation = $mail->gatherVacation($cachedVacations);
4217
-			} catch (Exception $e) {
4750
+			}
4751
+			catch (Exception $e) {
4218 4752
 				$vacation=false;
4219 4753
 				error_log(__METHOD__.__LINE__." ".$e->getMessage());
4220 4754
 				unset($e);
4221 4755
 			}
4222 4756
 		}
4223 4757
 
4224
-		if($vacation) {
4758
+		if($vacation)
4759
+		{
4225 4760
 			if (is_array($vacation) && ($vacation['status'] == 'on' || $vacation['status']=='by_date'))
4226 4761
 			{
4227 4762
 				$dtfrmt = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
4228 4763
 				$refreshData['vacationnotice'] = lang('Vacation notice is active');
4229 4764
 				$refreshData['vacationrange'] = ($vacation['status']=='by_date'? Api\DateTime::server2user($vacation['start_date'],$dtfrmt,true).($vacation['end_date']>$vacation['start_date']?'->'.Api\DateTime::server2user($vacation['end_date']+ 24*3600-1,$dtfrmt,true):''):'');
4230
-				if ($vacation['status'] == 'by_date' && $vacation['end_date']+ 24*3600 < time())$refreshData = '';
4765
+				if ($vacation['status'] == 'by_date' && $vacation['end_date']+ 24*3600 < time())
4766
+				{
4767
+					$refreshData = '';
4768
+				}
4231 4769
 			}
4232 4770
 		}
4233 4771
 		if ($vacation==false)
@@ -4249,11 +4787,17 @@  discard block
 block discarded – undo
4249 4787
 	function ajax_refreshFilters($icServerID=null)
4250 4788
 	{
4251 4789
 		//error_log(__METHOD__.__LINE__.array2string($icServerId));
4252
-		if (empty($icServerID)) $icServerID = $this->mail_bo->profileID;
4790
+		if (empty($icServerID))
4791
+		{
4792
+			$icServerID = $this->mail_bo->profileID;
4793
+		}
4253 4794
 		if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4254 4795
 		{
4255 4796
 			Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4256
-			if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4797
+			if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4798
+			{
4799
+				Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
4800
+			}
4257 4801
 		}
4258 4802
 		if (!Mail::$supportsORinQuery[$this->mail_bo->profileID])
4259 4803
 		{
@@ -4275,7 +4819,10 @@  discard block
 block discarded – undo
4275 4819
 			$keywords = array('keyword1','keyword2','keyword3','keyword4','keyword5');
4276 4820
 			foreach($keywords as &$k)
4277 4821
 			{
4278
-				if (array_key_exists($k,$this->statusTypes)) unset($this->statusTypes[$k]);
4822
+				if (array_key_exists($k,$this->statusTypes))
4823
+				{
4824
+					unset($this->statusTypes[$k]);
4825
+				}
4279 4826
 			}
4280 4827
 		}
4281 4828
 
@@ -4295,7 +4842,10 @@  discard block
 block discarded – undo
4295 4842
 	{
4296 4843
 		//error_log(__METHOD__.__LINE__.array2string($icServerID));
4297 4844
 		Api\Translation::add_app('mail');
4298
-		if (is_null($icServerID)) $icServerID = $this->mail_bo->profileID;
4845
+		if (is_null($icServerID))
4846
+		{
4847
+			$icServerID = $this->mail_bo->profileID;
4848
+		}
4299 4849
 		$rememberServerID = $this->mail_bo->profileID;
4300 4850
 		try
4301 4851
 		{
@@ -4305,19 +4855,23 @@  discard block
 block discarded – undo
4305 4855
 				$this->changeProfile($icServerID);
4306 4856
 			}
4307 4857
 			$quota = $this->mail_bo->getQuotaRoot();
4308
-		} catch (Exception $e) {
4858
+		}
4859
+		catch (Exception $e) {
4309 4860
 			$quota['limit'] = 'NOT SET';
4310 4861
 			error_log(__METHOD__.__LINE__." ".$e->getMessage());
4311 4862
 			unset($e);
4312 4863
 		}
4313 4864
 
4314
-		if($quota !== false && $quota['limit'] != 'NOT SET') {
4865
+		if($quota !== false && $quota['limit'] != 'NOT SET')
4866
+		{
4315 4867
 			$quotainfo = $this->quotaDisplay($quota['usage'], $quota['limit']);
4316 4868
 			$content['quota'] = $sel_options[self::$nm_index]['quota'] = $quotainfo['text'];
4317 4869
 			$content['quotainpercent'] = $sel_options[self::$nm_index]['quotainpercent'] =  (string)$quotainfo['percent'];
4318 4870
 			$content['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = $quotainfo['class'];
4319 4871
 			$content['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "";
4320
-		} else {
4872
+		}
4873
+		else
4874
+		{
4321 4875
 			$content['quota'] = $sel_options[self::$nm_index]['quota'] = lang("Quota not provided by server");
4322 4876
 			$content['quotaclass'] = $sel_options[self::$nm_index]['quotaclass'] = "mail_DisplayNone";
4323 4877
 			$content['quotanotsupported'] = $sel_options[self::$nm_index]['quotanotsupported'] = "mail_DisplayNone";
@@ -4328,7 +4882,8 @@  discard block
 block discarded – undo
4328 4882
 			{
4329 4883
 				//error_log(__METHOD__.__LINE__.' change Profile back to where we came from ->'.$rememberServerID);
4330 4884
 				$this->changeProfile($rememberServerID);
4331
-			} catch (Exception $e) {
4885
+			}
4886
+			catch (Exception $e) {
4332 4887
 				//error_log(__METHOD__.__LINE__." ".$e->getMessage());
4333 4888
 				unset($e);
4334 4889
 			}
@@ -4356,7 +4911,8 @@  discard block
 block discarded – undo
4356 4911
 			$this->changeProfile($icServerID);
4357 4912
 		}
4358 4913
 		$junkFolder = $this->mail_bo->getJunkFolder();
4359
-		if(!empty($junkFolder)) {
4914
+		if(!empty($junkFolder))
4915
+		{
4360 4916
 			if ($selectedFolder == $icServerID.self::$delimiter.$junkFolder)
4361 4917
 			{
4362 4918
 				// Lock the tree if the active folder is junk folder
@@ -4406,7 +4962,8 @@  discard block
 block discarded – undo
4406 4962
 			$this->changeProfile($icServerID);
4407 4963
 		}
4408 4964
 		$trashFolder = $this->mail_bo->getTrashFolder();
4409
-		if(!empty($trashFolder)) {
4965
+		if(!empty($trashFolder))
4966
+		{
4410 4967
 			if ($selectedFolder == $icServerID.self::$delimiter.$trashFolder)
4411 4968
 			{
4412 4969
 				// Lock the tree if the active folder is Trash folder
@@ -4452,7 +5009,10 @@  discard block
 block discarded – undo
4452 5009
 		$decodedFolderName = $this->mail_bo->decodeEntityFolderName($_folderName);
4453 5010
 		list($icServerID,$folderName) = explode(self::$delimiter,$decodedFolderName,2);
4454 5011
 
4455
-		if (empty($folderName)) $folderName = $this->mail_bo->sessionData['mailbox'];
5012
+		if (empty($folderName))
5013
+		{
5014
+			$folderName = $this->mail_bo->sessionData['mailbox'];
5015
+		}
4456 5016
 		if ($this->mail_bo->folderExists($folderName))
4457 5017
 		{
4458 5018
 			$rememberServerID = $this->mail_bo->profileID;
@@ -4461,7 +5021,8 @@  discard block
 block discarded – undo
4461 5021
 				//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
4462 5022
 				$this->changeProfile($icServerID);
4463 5023
 			}
4464
-			if(!empty($_folderName)) {
5024
+			if(!empty($_folderName))
5025
+			{
4465 5026
 				$this->mail_bo->compressFolder($folderName);
4466 5027
 			}
4467 5028
 			if ($rememberServerID != $this->mail_bo->profileID)
@@ -4483,7 +5044,10 @@  discard block
 block discarded – undo
4483 5044
 	 */
4484 5045
 	function ajax_sendMDN($_messageList)
4485 5046
 	{
4486
-		if(Mail::$debug) error_log(__METHOD__."->".array2string($_messageList));
5047
+		if(Mail::$debug)
5048
+		{
5049
+			error_log(__METHOD__."->".array2string($_messageList));
5050
+		}
4487 5051
 		$uidA = self::splitRowID($_messageList['msg'][0]);
4488 5052
 		$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
4489 5053
 		$this->mail_bo->sendMDN($uidA['msgUID'],$folder);
@@ -4500,7 +5064,10 @@  discard block
 block discarded – undo
4500 5064
 	 */
4501 5065
 	function ajax_flagMessages($_flag, $_messageList, $_sendJsonResponse=true)
4502 5066
 	{
4503
-		if(Mail::$debug) error_log(__METHOD__."->".$_flag.':'.array2string($_messageList));
5067
+		if(Mail::$debug)
5068
+		{
5069
+			error_log(__METHOD__."->".$_flag.':'.array2string($_messageList));
5070
+		}
4504 5071
 		Api\Translation::add_app('mail');
4505 5072
 		$alreadyFlagged=false;
4506 5073
 		$flag2check='';
@@ -4521,12 +5088,23 @@  discard block
 block discarded – undo
4521 5088
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4522 5089
 						{
4523 5090
 							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4524
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5091
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
5092
+							{
5093
+								Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5094
+							}
4525 5095
 						}
4526 5096
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']);
4527 5097
 						$cutoffdate = $cutoffdate2 = null;
4528
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4529
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
5098
+						if ($query['startdate'])
5099
+						{
5100
+							$cutoffdate = Api\DateTime::to($query['startdate'],'ts');
5101
+						}
5102
+						//SINCE, enddate
5103
+						if ($query['enddate'])
5104
+						{
5105
+							$cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');
5106
+						}
5107
+						//BEFORE, startdate
4530 5108
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4531 5109
 						$filter = array(
4532 5110
 							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
@@ -4535,15 +5113,24 @@  discard block
 block discarded – undo
4535 5113
 							'status' => 'any',//this is a status change. status will be manipulated later on
4536 5114
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4537 5115
 						);
4538
-						if ($query['enddate']||$query['startdate']) {
5116
+						if ($query['enddate']||$query['startdate'])
5117
+						{
4539 5118
 							$filter['range'] = "BETWEEN";
4540
-							if ($cutoffdate) {
5119
+							if ($cutoffdate)
5120
+							{
4541 5121
 								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4542
-								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
5122
+								if (empty($cutoffdate2))
5123
+								{
5124
+									$filter['range'] = "SINCE";
5125
+								}
4543 5126
 							}
4544
-							if ($cutoffdate2) {
5127
+							if ($cutoffdate2)
5128
+							{
4545 5129
 								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4546
-								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
5130
+								if (empty($cutoffdate))
5131
+								{
5132
+									$filter['range'] = "BEFORE";
5133
+								}
4547 5134
 							}
4548 5135
 						}
4549 5136
 						$filter2toggle = $filter;
@@ -4590,13 +5177,19 @@  discard block
 block discarded – undo
4590 5177
 						if (count($messageListForToggle)>0)
4591 5178
 						{
4592 5179
 							$flag2set = (strtolower($_flag));
4593
-							if(Mail::$debug) error_log(__METHOD__.__LINE__." toggle un$_flag -> $flag2set ".array2string($filter2toggle).array2string($messageListForToggle));
5180
+							if(Mail::$debug)
5181
+							{
5182
+								error_log(__METHOD__.__LINE__." toggle un$_flag -> $flag2set ".array2string($filter2toggle).array2string($messageListForToggle));
5183
+							}
4594 5184
 							$this->mail_bo->flagMessages($flag2set, $messageListForToggle,$folder);
4595 5185
 						}
4596 5186
 						if (count($messageList)>0)
4597 5187
 						{
4598 5188
 							$flag2set = 'un'.$_flag;
4599
-							if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag -> $flag2set ".array2string($filter).array2string($messageList));
5189
+							if(Mail::$debug)
5190
+							{
5191
+								error_log(__METHOD__.__LINE__." $_flag -> $flag2set ".array2string($filter).array2string($messageList));
5192
+							}
4600 5193
 							$this->mail_bo->flagMessages($flag2set, $messageList,$folder);
4601 5194
 						}
4602 5195
 						$alreadyFlagged=true;
@@ -4612,7 +5205,10 @@  discard block
 block discarded – undo
4612 5205
 							// since we toggle and we toggle by the filtered flag we must must change _flag
4613 5206
 							$_flag = ($query['filter']=='unseen' && $_flag=='read' ? 'read' : ($query['filter']=='seen'&& $_flag=='read'?'unread':($_flag==$query['filter']?'un'.$_flag:$_flag)));
4614 5207
 						}
4615
-						if(Mail::$debug) error_log(__METHOD__.__LINE__." flag all with $_flag on filter used:".array2string($filter));
5208
+						if(Mail::$debug)
5209
+						{
5210
+							error_log(__METHOD__.__LINE__." flag all with $_flag on filter used:".array2string($filter));
5211
+						}
4616 5212
 						$_sR = $this->mail_bo->getSortedList(
4617 5213
 							$folder,
4618 5214
 							$sort=0,
@@ -4627,7 +5223,10 @@  discard block
 block discarded – undo
4627 5223
 					}
4628 5224
 					else
4629 5225
 					{
4630
-						if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag all ".array2string($filter));
5226
+						if(Mail::$debug)
5227
+						{
5228
+							error_log(__METHOD__.__LINE__." $_flag all ".array2string($filter));
5229
+						}
4631 5230
 						$alreadyFlagged=true;
4632 5231
 						$uidA = self::splitRowID($_messageList['msg'][0]);
4633 5232
 						$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
@@ -4647,13 +5246,19 @@  discard block
 block discarded – undo
4647 5246
 					$hA = self::splitRowID($rowID);
4648 5247
 					$messageList[] = $hA['msgUID'];
4649 5248
 				}
4650
-				if(Mail::$debug) error_log(__METHOD__.__LINE__." $_flag in $folder:".array2string(((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList)));
5249
+				if(Mail::$debug)
5250
+				{
5251
+					error_log(__METHOD__.__LINE__." $_flag in $folder:".array2string(((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList)));
5252
+				}
4651 5253
 				$this->mail_bo->flagMessages($_flag, ((isset($_messageList['all']) && $_messageList['all']) ? 'all':$messageList),$folder);
4652 5254
 			}
4653 5255
 		}
4654 5256
 		else
4655 5257
 		{
4656
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
5258
+			if(Mail::$debug)
5259
+			{
5260
+				error_log(__METHOD__."-> No messages selected.");
5261
+			}
4657 5262
 		}
4658 5263
 
4659 5264
 		if ($_sendJsonResponse)
@@ -4690,7 +5295,10 @@  discard block
 block discarded – undo
4690 5295
 	 */
4691 5296
 	function ajax_deleteMessages($_messageList,$_forceDeleteMethod=null)
4692 5297
 	{
4693
-		if(Mail::$debug) error_log(__METHOD__."->".print_r($_messageList,true).' Method:'.$_forceDeleteMethod);
5298
+		if(Mail::$debug)
5299
+		{
5300
+			error_log(__METHOD__."->".print_r($_messageList,true).' Method:'.$_forceDeleteMethod);
5301
+		}
4694 5302
 		$error = null;
4695 5303
 		$filtered =  false;
4696 5304
 		if ($_messageList=='all' || !empty($_messageList['msg']))
@@ -4709,12 +5317,23 @@  discard block
 block discarded – undo
4709 5317
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4710 5318
 						{
4711 5319
 							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4712
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5320
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
5321
+							{
5322
+								Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5323
+							}
4713 5324
 						}
4714 5325
 						$filtered =  true;
4715 5326
 						$cutoffdate = $cutoffdate2 = null;
4716
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4717
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
5327
+						if ($query['startdate'])
5328
+						{
5329
+							$cutoffdate = Api\DateTime::to($query['startdate'],'ts');
5330
+						}
5331
+						//SINCE, enddate
5332
+						if ($query['enddate'])
5333
+						{
5334
+							$cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');
5335
+						}
5336
+						//BEFORE, startdate
4718 5337
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4719 5338
 						$filter = array(
4720 5339
 							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
@@ -4723,15 +5342,24 @@  discard block
 block discarded – undo
4723 5342
 							'status' => (!empty($query['filter'])?$query['filter']:'any'),
4724 5343
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4725 5344
 						);
4726
-						if ($query['enddate']||$query['startdate']) {
5345
+						if ($query['enddate']||$query['startdate'])
5346
+						{
4727 5347
 							$filter['range'] = "BETWEEN";
4728
-							if ($cutoffdate) {
5348
+							if ($cutoffdate)
5349
+							{
4729 5350
 								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4730
-								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
5351
+								if (empty($cutoffdate2))
5352
+								{
5353
+									$filter['range'] = "SINCE";
5354
+								}
4731 5355
 							}
4732
-							if ($cutoffdate2) {
5356
+							if ($cutoffdate2)
5357
+							{
4733 5358
 								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4734
-								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
5359
+								if (empty($cutoffdate))
5360
+								{
5361
+									$filter['range'] = "BEFORE";
5362
+								}
4735 5363
 							}
4736 5364
 						}
4737 5365
 					}
@@ -4798,7 +5426,10 @@  discard block
 block discarded – undo
4798 5426
 		}
4799 5427
 		else
4800 5428
 		{
4801
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
5429
+			if(Mail::$debug)
5430
+			{
5431
+				error_log(__METHOD__."-> No messages selected.");
5432
+			}
4802 5433
 		}
4803 5434
 	}
4804 5435
 
@@ -4814,11 +5445,17 @@  discard block
 block discarded – undo
4814 5445
 	 */
4815 5446
 	function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_')
4816 5447
 	{
4817
-		if(Mail::$debug) error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList,true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
5448
+		if(Mail::$debug)
5449
+		{
5450
+			error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList,true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
5451
+		}
4818 5452
 		Api\Translation::add_app('mail');
4819 5453
 		$folderName = $this->mail_bo->decodeEntityFolderName($_folderName);
4820 5454
 		// only copy or move are supported as method
4821
-		if (!($_copyOrMove=='copy' || $_copyOrMove=='move')) $_copyOrMove='copy';
5455
+		if (!($_copyOrMove=='copy' || $_copyOrMove=='move'))
5456
+		{
5457
+			$_copyOrMove='copy';
5458
+		}
4822 5459
 		list($targetProfileID,$targetFolder) = explode(self::$delimiter,$folderName,2);
4823 5460
 		// check if move2archive was called with the correct archiveFolder
4824 5461
 		$archiveFolder = $this->mail_bo->getArchiveFolder();
@@ -4841,8 +5478,13 @@  discard block
 block discarded – undo
4841 5478
 				$keys = array_keys($lastFoldersUsedForMoveCont[$targetProfileID]);
4842 5479
 				foreach( $keys as &$f)
4843 5480
 				{
4844
-					if (count($lastFoldersUsedForMoveCont[$targetProfileID])>9) unset($lastFoldersUsedForMoveCont[$targetProfileID][$f]);
4845
-					else break;
5481
+					if (count($lastFoldersUsedForMoveCont[$targetProfileID])>9)
5482
+					{
5483
+						unset($lastFoldersUsedForMoveCont[$targetProfileID][$f]);
5484
+					}
5485
+					else {
5486
+						break;
5487
+					}
4846 5488
 				}
4847 5489
 				//error_log(__METHOD__.__LINE__.array2string($lastFoldersUsedForMoveCont[$targetProfileID]));
4848 5490
 			}
@@ -4869,12 +5511,23 @@  discard block
 block discarded – undo
4869 5511
 						if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
4870 5512
 						{
4871 5513
 							Mail::$supportsORinQuery = Api\Cache::getCache(Api\Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60*60*10);
4872
-							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID])) Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5514
+							if (!isset(Mail::$supportsORinQuery[$this->mail_bo->profileID]))
5515
+							{
5516
+								Mail::$supportsORinQuery[$this->mail_bo->profileID]=true;
5517
+							}
4873 5518
 						}
4874 5519
 						$filtered = true;
4875 5520
 						$cutoffdate = $cutoffdate2 = null;
4876
-						if ($query['startdate']) $cutoffdate = Api\DateTime::to($query['startdate'],'ts');//SINCE, enddate
4877
-						if ($query['enddate']) $cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');//BEFORE, startdate
5521
+						if ($query['startdate'])
5522
+						{
5523
+							$cutoffdate = Api\DateTime::to($query['startdate'],'ts');
5524
+						}
5525
+						//SINCE, enddate
5526
+						if ($query['enddate'])
5527
+						{
5528
+							$cutoffdate2 = Api\DateTime::to($query['enddate'],'ts');
5529
+						}
5530
+						//BEFORE, startdate
4878 5531
 						//error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate);
4879 5532
 						$filter = array(
4880 5533
 							'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')),
@@ -4883,15 +5536,24 @@  discard block
 block discarded – undo
4883 5536
 							'status' => (!empty($query['filter'])?$query['filter']:'any'),
4884 5537
 							//'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2)
4885 5538
 						);
4886
-						if ($query['enddate']||$query['startdate']) {
5539
+						if ($query['enddate']||$query['startdate'])
5540
+						{
4887 5541
 							$filter['range'] = "BETWEEN";
4888
-							if ($cutoffdate) {
5542
+							if ($cutoffdate)
5543
+							{
4889 5544
 								$filter[(empty($cutoffdate2)?'date':'since')] =  date("d-M-Y", $cutoffdate);
4890
-								if (empty($cutoffdate2)) $filter['range'] = "SINCE";
5545
+								if (empty($cutoffdate2))
5546
+								{
5547
+									$filter['range'] = "SINCE";
5548
+								}
4891 5549
 							}
4892
-							if ($cutoffdate2) {
5550
+							if ($cutoffdate2)
5551
+							{
4893 5552
 								$filter[(empty($cutoffdate)?'date':'before')] =  date("d-M-Y", $cutoffdate2);
4894
-								if (empty($cutoffdate)) $filter['range'] = "BEFORE";
5553
+								if (empty($cutoffdate))
5554
+								{
5555
+									$filter['range'] = "BEFORE";
5556
+								}
4895 5557
 							}
4896 5558
 						}
4897 5559
 					}
@@ -4947,7 +5609,10 @@  discard block
 block discarded – undo
4947 5609
 						$hA = self::splitRowID($rowID);
4948 5610
 
4949 5611
 						// If folder changes, stop and move what we've got
4950
-						if($hA['folder'] != $folder) break;
5612
+						if($hA['folder'] != $folder)
5613
+						{
5614
+							break;
5615
+						}
4951 5616
 
4952 5617
 						array_shift($_messageList['msg']);
4953 5618
 						$messageList[] = $hA['msgUID'];
@@ -5002,7 +5667,10 @@  discard block
 block discarded – undo
5002 5667
 		}
5003 5668
 		else
5004 5669
 		{
5005
-			if(Mail::$debug) error_log(__METHOD__."-> No messages selected.");
5670
+			if(Mail::$debug)
5671
+			{
5672
+				error_log(__METHOD__."-> No messages selected.");
5673
+			}
5006 5674
 		}
5007 5675
 	}
5008 5676
 
Please login to merge, or discard this patch.