Completed
Push — master ( fb037c...c173de )
by Klaus
57:17 queued 36:58
created
api/src/Mail.php 2 patches
Spacing   +1144 added lines, -1145 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 with error:".$e->getMessage().($e->details?', '.$e->details:''));
286
+					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_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,34 +1281,34 @@  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
-					$_reverse=1;
1311
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse, array('status'=>array('UNSEEN','UNDELETED')),$byUid,false);
1309
+					$byUid = true;
1310
+					$_reverse = 1;
1311
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid, false);
1312 1312
 					$retValue['unseen'] = $sortResult['count'];
1313 1313
 				}
1314 1314
 				catch (\Exception $ee)
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
 		}
1320 1320
 		catch (\Exception $e)
1321 1321
 		{
1322
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1322
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1323 1323
 		}
1324 1324
 
1325 1325
 		return $retValue;
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 	 * @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))
1342 1342
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1343 1343
 	 */
1344
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1344
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true, $_fetchPreviews = false)
1345 1345
 	{
1346 1346
 		//self::$debug=true;
1347 1347
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 		$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
1355 1355
 		#print "<pre>";
1356 1356
 		#$this->icServer->setDebug(true);
1357
-		$total=0;
1357
+		$total = 0;
1358 1358
 		if ($_thisUIDOnly === null)
1359 1359
 		{
1360 1360
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1367,24 +1367,24 @@  discard block
 block discarded – undo
1367 1367
 				//$_filter['range'] ="$_startMessage:*";
1368 1368
 			}
1369 1369
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1370
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1370
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1371 1371
 			//see this example below for a 12 week datefilter (since)
1372 1372
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1373 1373
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1374 1374
 			$sortResult = $_sortResult['match']->ids;
1375 1375
 			//$modseq = $_sortResult['modseq'];
1376 1376
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1377
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1377
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1378 1378
 
1379 1379
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1380 1380
 			#$this->icServer->setDebug(false);
1381 1381
 			#print "</pre>";
1382 1382
 			// nothing found
1383
-			if(!is_array($sortResult) || empty($sortResult)) {
1383
+			if (!is_array($sortResult) || empty($sortResult)) {
1384 1384
 				$retValue = array();
1385 1385
 				$retValue['info']['total']	= 0;
1386 1386
 				$retValue['info']['first']	= 0;
1387
-				$retValue['info']['last']	= 0;
1387
+				$retValue['info']['last'] = 0;
1388 1388
 				return $retValue;
1389 1389
 			}
1390 1390
 
@@ -1392,54 +1392,54 @@  discard block
 block discarded – undo
1392 1392
 			#_debug_array($sortResult);
1393 1393
 			#_debug_array(array_slice($sortResult, -5, -2));
1394 1394
 			//error_log("REVERSE: $reverse");
1395
-			if($reverse === true) {
1396
-				if  ($_startMessage<=$total)
1395
+			if ($reverse === true) {
1396
+				if ($_startMessage <= $total)
1397 1397
 				{
1398
-					$startMessage = $_startMessage-1;
1398
+					$startMessage = $_startMessage - 1;
1399 1399
 				}
1400 1400
 				else
1401 1401
 				{
1402 1402
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1403
-					if ($_startMessage+$_numberOfMessages>$total)
1403
+					if ($_startMessage + $_numberOfMessages > $total)
1404 1404
 					{
1405
-						$numberOfMessages = $total%$_numberOfMessages;
1405
+						$numberOfMessages = $total % $_numberOfMessages;
1406 1406
 						//$numberOfMessages = abs($_startMessage-$total-1);
1407
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1407
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1408 1408
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1409 1409
 					}
1410
-					$startMessage=($total-$_numberOfMessages)-1;
1410
+					$startMessage = ($total - $_numberOfMessages) - 1;
1411 1411
 					//$retValue['info']['first'] = $startMessage;
1412 1412
 					//$retValue['info']['last'] = $total;
1413 1413
 
1414 1414
 				}
1415
-				if ($startMessage+$_numberOfMessages>$total)
1415
+				if ($startMessage + $_numberOfMessages > $total)
1416 1416
 				{
1417
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1417
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1418 1418
 					//$retValue['info']['first'] = $startMessage;
1419 1419
 					//$retValue['info']['last'] = $total;
1420 1420
 				}
1421
-				if($startMessage > 0) {
1422
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1423
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1421
+				if ($startMessage > 0) {
1422
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1423
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1424 1424
 				} else {
1425
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1426
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1425
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1426
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1427 1427
 				}
1428 1428
 				$sortResult = array_reverse($sortResult);
1429 1429
 			} else {
1430
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1431
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1430
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1431
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1432 1432
 			}
1433 1433
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1434 1434
 		}
1435 1435
 		else
1436 1436
 		{
1437
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1437
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1438 1438
 		}
1439 1439
 
1440 1440
 
1441 1441
 		// fetch the data for the selected messages
1442
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1442
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1443 1443
 		try
1444 1444
 		{
1445 1445
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1448,22 +1448,22 @@  discard block
 block discarded – undo
1448 1448
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1449 1449
 
1450 1450
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1451
-			$fquery->headers('fetchHeaders',array(
1452
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1453
-				'DATE','SUBJECT','FROM','TO','CC',
1451
+			$fquery->headers('fetchHeaders', array(
1452
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1453
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC',
1454 1454
 				'X-PRIORITY'
1455
-			),array(
1455
+			), array(
1456 1456
 				// Cache headers, we'll look at them below
1457
-				'cache' => true,//$_cacheResult,
1457
+				'cache' => true, //$_cacheResult,
1458 1458
 				// Set peek so messages are not flagged as read
1459 1459
 				'peek' => true
1460 1460
 			));
1461 1461
 			$fquery->size();
1462 1462
 			$fquery->structure();
1463 1463
 			$fquery->flags();
1464
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1464
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1465 1465
 			// if $_fetchPreviews is activated fetch part of the messages too
1466
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1466
+			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true, 'length'=>((int)$_fetchPreviews < 5000 ? 5000 : $_fetchPreviews), 'start'=>0));
1467 1467
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1468 1468
 				'ids' => $uidsToFetch,
1469 1469
 			));
@@ -1474,9 +1474,9 @@  discard block
 block discarded – undo
1474 1474
 			$headersNew = array();
1475 1475
 			$sortResult = array();
1476 1476
 		}
1477
-		if (self::$debug||self::$debugTimes)
1477
+		if (self::$debug || self::$debugTimes)
1478 1478
 		{
1479
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1479
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1480 1480
 			if (self::$debug)
1481 1481
 			{
1482 1482
 				$queryString = implode(',', $sortResult);
@@ -1486,27 +1486,27 @@  discard block
 block discarded – undo
1486 1486
 
1487 1487
 		$cnt = 0;
1488 1488
 
1489
-		foreach((array)$sortResult as $uid) {
1489
+		foreach ((array)$sortResult as $uid) {
1490 1490
 			$sortOrder[$uid] = $cnt++;
1491 1491
 		}
1492 1492
 
1493 1493
 		$count = 0;
1494 1494
 		if (is_object($headersNew)) {
1495
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1496
-			foreach($headersNew->ids() as $id) {
1495
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1496
+			foreach ($headersNew->ids() as $id) {
1497 1497
 				$_headerObject = $headersNew->get($id);
1498 1498
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1499 1499
 				$headerObject = array();
1500 1500
 				$bodyPreview = null;
1501
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1501
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1502 1502
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1503 1503
 				$headerObject['SIZE'] = $_headerObject->getSize();
1504 1504
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1505 1505
 
1506 1506
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1507
-				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1507
+				$headerForPrio = $_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1508 1508
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1509
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1509
+				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1510 1510
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1511 1511
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1512 1512
 				if ($_fetchPreviews)
@@ -1514,16 +1514,16 @@  discard block
 block discarded – undo
1514 1514
 					// on enabled preview $bodyPreview is needed lateron. fetched here, for fallback-reasons
1515 1515
 					// in case of failed Header-Retrieval
1516 1516
 					$bodyPreview = $_headerObject->getFullMsg();
1517
-					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1517
+					if (empty($headerForPrio) || (is_array($headerForPrio) && count($headerForPrio) === 1 && $headerForPrio['']))
1518 1518
 					{
1519 1519
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1520
-						if ($length===false) $length = strlen($bodyPreview);
1521
-						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1520
+						if ($length === false) $length = strlen($bodyPreview);
1521
+						$headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0, $length))->toArray();
1522 1522
 					}
1523 1523
 				}
1524 1524
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1525 1525
 				if (self::$debug) {
1526
-					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
+					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'));
1527 1527
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1528 1528
 				}
1529 1529
 				// message deleted from server but cache still reporting its existence ; may happen on QRESYNC with No permanent modsequences
@@ -1532,21 +1532,21 @@  discard block
 block discarded – undo
1532 1532
 					$total--;
1533 1533
 					continue;
1534 1534
 				}
1535
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1535
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1536 1536
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1537
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1537
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1538 1538
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1539
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1539
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1540 1540
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1541 1541
 				} /*else $sent_not = "";*/
1542 1542
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1543 1543
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1544
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1545
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1544
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1545
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1546 1546
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1547
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1548
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1549
-				foreach (array('FROM','TO','CC') as $key)
1547
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1548
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1549
+				foreach (array('FROM', 'TO', 'CC') as $key)
1550 1550
 				{
1551 1551
 					$address = array();
1552 1552
 					foreach ($headerObject[$key] as $k => $ad)
@@ -1568,13 +1568,13 @@  discard block
 block discarded – undo
1568 1568
 						foreach ($rfcAddr as $_rfcAddr)
1569 1569
 						{
1570 1570
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1571
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1571
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1572 1572
 						}
1573 1573
 					}
1574 1574
 					$headerObject[$key] = $address;
1575 1575
 				}
1576 1576
 				$headerObject['FLAGS'] = $_headerObject->getFlags();
1577
-				$headerObject['BODYPREVIEW']=null;
1577
+				$headerObject['BODYPREVIEW'] = null;
1578 1578
 				// this section fetches part of the message-body (if enabled) for some kind of preview
1579 1579
 				// if we fail to succeed, we fall back to the retrieval of the message-body with
1580 1580
 				// fetchPartContents (see below, when we iterate over the structure to determine the
@@ -1586,17 +1586,17 @@  discard block
 block discarded – undo
1586 1586
 					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1587 1587
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1588 1588
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1589
-					foreach($base->partIterator() as $part)
1589
+					foreach ($base->partIterator() as $part)
1590 1590
 					{
1591 1591
 						//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
1592
-						if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
1592
+						if (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'text')
1593 1593
 						{
1594 1594
 							$charset = $part->getContentTypeParameter('charset');
1595 1595
 							$buffer = Mail\Html::convertHTMLToText($part->toString(array(
1596
-												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1596
+												'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
1597 1597
 											)), $charset, 'utf-8');
1598
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1599
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1598
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Translation::convert_jsonsafe($buffer), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1599
+						} elseif (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'multipart')
1600 1600
 						{
1601 1601
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1602 1602
 						}
@@ -1607,12 +1607,12 @@  discard block
 block discarded – undo
1607 1607
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1608 1608
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1609 1609
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1610
-				$headerObject['ATTACHMENTS']=null;
1611
-				$skipParts=array();
1612
-				$messageMimeType='';
1610
+				$headerObject['ATTACHMENTS'] = null;
1611
+				$skipParts = array();
1612
+				$messageMimeType = '';
1613 1613
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1614 1614
 				{
1615
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1615
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1616 1616
 					$part = $mailStructureObject->getPart($mime_id);
1617 1617
 					$partdisposition = $part->getDisposition();
1618 1618
 					$partPrimaryType = $part->getPrimaryType();
@@ -1620,16 +1620,16 @@  discard block
 block discarded – undo
1620 1620
 					// drawback here it is talking to the mailserver for each mail thus consuming
1621 1621
 					// more time than expected; so we call this section only when there is no
1622 1622
 					// bodypreview could be found (multipart/....)
1623
-					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1623
+					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW']) && ($partPrimaryType == 'text') &&
1624 1624
 						((intval($mime_id) === 1) || !$mime_id) &&
1625 1625
 						($partdisposition !== 'attachment')) {
1626
-							$_structure=$part;
1627
-							$this->fetchPartContents($uid, $_structure, false,true);
1628
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1629
-							$charSet=Translation::detect_encoding($headerObject['BODYPREVIEW']);
1626
+							$_structure = $part;
1627
+							$this->fetchPartContents($uid, $_structure, false, true);
1628
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1629
+							$charSet = Translation::detect_encoding($headerObject['BODYPREVIEW']);
1630 1630
 							// add line breaks to $bodyParts
1631 1631
 							//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
1632
-							$headerObject['BODYPREVIEW']  = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1632
+							$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1633 1633
 							//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
1634 1634
 					}
1635 1635
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
@@ -1639,28 +1639,28 @@  discard block
 block discarded – undo
1639 1639
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1640 1640
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1641 1641
 						// as attachment in order to not loose/miss information on our data
1642
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1642
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1643 1643
 					}
1644
-					if ($mime_type=='message/rfc822')
1644
+					if ($mime_type == 'message/rfc822')
1645 1645
 					{
1646 1646
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1647
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1647
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1648 1648
 					}
1649 1649
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1650
-					if (array_key_exists($mime_id,$skipParts)) continue;
1651
-					if ($partdisposition=='attachment' ||
1652
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1653
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1654
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1650
+					if (array_key_exists($mime_id, $skipParts)) continue;
1651
+					if ($partdisposition == 'attachment' ||
1652
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1653
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1654
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1655 1655
 					{
1656
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1657
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1658
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1656
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1657
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1658
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1659 1659
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1660
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1661
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1662
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1663
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1660
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1661
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1662
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1663
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1664 1664
 						{
1665 1665
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1666 1666
 						}
@@ -1675,54 +1675,54 @@  discard block
 block discarded – undo
1675 1675
 				if (empty($headerObject['UID'])) continue;
1676 1676
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1677 1677
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1678
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1678
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1679 1679
 					$headerObject['DATE'] .= 'C';
1680 1680
 				}
1681
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1681
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1682 1682
 					$headerObject['INTERNALDATE'] .= 'C';
1683 1683
 				}
1684 1684
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1685 1685
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1686
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1687
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1688
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1689
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1690
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1691
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1692
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1693
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1694
-				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1695
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1686
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1687
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1688
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1689
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1690
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1691
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1692
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1693
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1694
+				$retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW'];
1695
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1696 1696
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1697 1697
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1698 1698
 				if (is_array($headerObject['FLAGS'])) {
1699
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1699
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1700 1700
 				}
1701 1701
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1702
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1703
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1702
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1703
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1704 1704
 				}
1705
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1706
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1707
-					if (count($headerObject['TO'])>1)
1705
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1706
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1707
+					if (count($headerObject['TO']) > 1)
1708 1708
 					{
1709
-						$ki=0;
1710
-						foreach($headerObject['TO'] as $k => $add)
1709
+						$ki = 0;
1710
+						foreach ($headerObject['TO'] as $k => $add)
1711 1711
 						{
1712
-							if ($k==0) continue;
1712
+							if ($k == 0) continue;
1713 1713
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1714
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1714
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1715 1715
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1716 1716
 							$ki++;
1717 1717
 						}
1718 1718
 					}
1719 1719
 				}
1720
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1721
-					$ki=0;
1722
-					foreach($headerObject['CC'] as $k => $add)
1720
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1721
+					$ki = 0;
1722
+					foreach ($headerObject['CC'] as $k => $add)
1723 1723
 					{
1724 1724
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1725
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1725
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1726 1726
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1727 1727
 						$ki++;
1728 1728
 					}
@@ -1731,27 +1731,27 @@  discard block
 block discarded – undo
1731 1731
 
1732 1732
 				$count++;
1733 1733
 			}
1734
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1734
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1735 1735
 			//self::$debug=false;
1736 1736
 			// sort the messages to the requested displayorder
1737
-			if(is_array($retValue['header'])) {
1737
+			if (is_array($retValue['header'])) {
1738 1738
 				$countMessages = $total;
1739 1739
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1740 1740
 				ksort($retValue['header']);
1741 1741
 				$retValue['info']['total']	= $total;
1742 1742
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1743 1743
 				$retValue['info']['first']	= $_startMessage;
1744
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1744
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1745 1745
 				return $retValue;
1746 1746
 			} else {
1747 1747
 				$retValue = array();
1748 1748
 				$retValue['info']['total']	= 0;
1749 1749
 				$retValue['info']['first']	= 0;
1750
-				$retValue['info']['last']	= 0;
1750
+				$retValue['info']['last'] = 0;
1751 1751
 				return $retValue;
1752 1752
 			}
1753 1753
 		} else {
1754
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1754
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1755 1755
 			$retValue = array();
1756 1756
 			$retValue['info']['total']  = 0;
1757 1757
 			$retValue['info']['first']  = 0;
@@ -1768,17 +1768,17 @@  discard block
 block discarded – undo
1768 1768
 	 */
1769 1769
 	static function prepareFlagsArray($headerObject)
1770 1770
 	{
1771
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1771
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1772 1772
 		$retValue = array();
1773 1773
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1774 1774
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1775
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1776
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1775
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1776
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1777 1777
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1778
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1779
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1780
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1781
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1778
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1779
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1780
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1781
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1782 1782
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1783 1783
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1784 1784
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1802,12 +1802,12 @@  discard block
 block discarded – undo
1802 1802
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1803 1803
 	 * @return mixed bool/array false or array of ids
1804 1804
 	 */
1805
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1805
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1806 1806
 	{
1807 1807
 		static $cachedFolderStatus = null;
1808 1808
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1809 1809
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1810
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1810
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1811 1811
 		{
1812 1812
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1813 1813
 		}
@@ -1819,29 +1819,29 @@  discard block
 block discarded – undo
1819 1819
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1820 1820
 		$try2useCache = true;
1821 1821
 		static $eMailListContainsDeletedMessages = null;
1822
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1822
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1823 1823
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1824
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1824
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1825 1825
 		{
1826 1826
 			if (self::$debugTimes) $starttime = microtime(true);
1827
-			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);
1828
-			$five=true;
1829
-			$dReverse=1;
1830
-			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false);
1827
+			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);
1828
+			$five = true;
1829
+			$dReverse = 1;
1830
+			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')), $five, false);
1831 1831
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1832
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1833
-			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1834
-			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']);
1832
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1833
+			Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1834
+			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']);
1835 1835
 		}
1836 1836
 		$try2useCache = false;
1837 1837
 		//self::$supportsORinQuery[$this->profileID]=true;
1838 1838
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1839 1839
 		{
1840
-			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1841
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1840
+			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1841
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1842 1842
 		}
1843 1843
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1844
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1844
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1845 1845
 		if (self::$debug)
1846 1846
 		{
1847 1847
 			$query_str = $filter->build();
@@ -1849,14 +1849,14 @@  discard block
 block discarded – undo
1849 1849
 		}
1850 1850
 		//_debug_array($filter);
1851 1851
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1852
-		if($this->icServer->hasCapability('SORT')) {
1852
+		if ($this->icServer->hasCapability('SORT')) {
1853 1853
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1854 1854
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1855 1855
 			// there is no messing with the dates)
1856 1856
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1857 1857
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1858 1858
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1859
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1859
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1860 1860
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1861 1861
 			try
1862 1862
 			{
@@ -1864,24 +1864,24 @@  discard block
 block discarded – undo
1864 1864
 					'sort' => $sortOrder,));
1865 1865
 			// if there is an Error, we assume that the server is not capable of sorting
1866 1866
 			}
1867
-			catch(\Exception $e)
1867
+			catch (\Exception $e)
1868 1868
 			{
1869 1869
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1870 1870
 				$resultByUid = false;
1871 1871
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1872
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1872
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1873 1873
 				try
1874 1874
 				{
1875 1875
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1876 1876
 						'sort' => $sortOrder));
1877 1877
 				}
1878
-				catch(\Exception $e)
1878
+				catch (\Exception $e)
1879 1879
 				{
1880 1880
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1881 1881
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1882 1882
 				}
1883 1883
 			}
1884
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1884
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1885 1885
 		} else {
1886 1886
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1887 1887
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1891,12 +1891,12 @@  discard block
 block discarded – undo
1891 1891
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1892 1892
 					'sort' => $sortOrder)*/);
1893 1893
 			}
1894
-			catch(\Exception $e)
1894
+			catch (\Exception $e)
1895 1895
 			{
1896 1896
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1897 1897
 				// possible error OR Query. But Horde gives no detailed Info :-(
1898
-				self::$supportsORinQuery[$this->profileID]=false;
1899
-				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1898
+				self::$supportsORinQuery[$this->profileID] = false;
1899
+				Cache::setCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1900 1900
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1901 1901
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1902 1902
 				try
@@ -1904,25 +1904,25 @@  discard block
 block discarded – undo
1904 1904
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1905 1905
 						'sort' => $sortOrder)*/);
1906 1906
 				}
1907
-				catch(\Exception $e)
1907
+				catch (\Exception $e)
1908 1908
 				{
1909 1909
 				}
1910 1910
 			}
1911
-			if(is_array($sortResult['match'])) {
1911
+			if (is_array($sortResult['match'])) {
1912 1912
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1913 1913
 					sort($sortResult['match'], SORT_NUMERIC);
1914 1914
 			}
1915
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1915
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1916 1916
 		}
1917 1917
 		if ($setSession)
1918 1918
 		{
1919 1919
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1920
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1920
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1921 1921
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1922 1922
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1923
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1923
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1924 1924
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1925
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1925
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1926 1926
 		}
1927 1927
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1928 1928
 		//_debug_array($sortResult['match']->ids);
@@ -1936,12 +1936,12 @@  discard block
 block discarded – undo
1936 1936
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1937 1937
 	 * @return the sort sequence for horde search
1938 1938
 	 */
1939
-	function _getSortString($_sort, $_reverse=false)
1939
+	function _getSortString($_sort, $_reverse = false)
1940 1940
 	{
1941
-		$_reverse=false;
1941
+		$_reverse = false;
1942 1942
 		if (is_numeric($_sort))
1943 1943
 		{
1944
-			switch($_sort) {
1944
+			switch ($_sort) {
1945 1945
 				case 2:
1946 1946
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1947 1947
 					break;
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
 		}
1964 1964
 		else
1965 1965
 		{
1966
-			switch(strtoupper($_sort)) {
1966
+			switch (strtoupper($_sort)) {
1967 1967
 				case 'FROMADDRESS':
1968 1968
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1969 1969
 					break;
@@ -1989,7 +1989,7 @@  discard block
 block discarded – undo
1989 1989
 					break;
1990 1990
 			}
1991 1991
 		}
1992
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
1992
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
1993 1993
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1994 1994
 		return $retValue;
1995 1995
 	}
@@ -2002,28 +2002,28 @@  discard block
 block discarded – undo
2002 2002
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
2003 2003
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
2004 2004
 	 */
2005
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
2005
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
2006 2006
 	{
2007 2007
 		$imapFilter = new Horde_Imap_Client_Search_Query();
2008 2008
 		$imapFilter->charset('UTF-8');
2009 2009
 
2010 2010
 		//_debug_array($_criterias);
2011
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2012
-		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2011
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
2012
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') &&
2013 2013
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2014
-			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
2015
-			( !empty($_criterias['range'])&& ($_criterias['range']!='BETWEEN' && empty($_criterias['date'])||
2016
-			($_criterias['range']=='BETWEEN' && empty($_criterias['since'])&& empty($_criterias['before']))))))
2014
+			(!isset($_criterias['range']) || empty($_criterias['range']) ||
2015
+			(!empty($_criterias['range']) && ($_criterias['range'] != 'BETWEEN' && empty($_criterias['date']) ||
2016
+			($_criterias['range'] == 'BETWEEN' && empty($_criterias['since']) && empty($_criterias['before']))))))
2017 2017
 		{
2018 2018
 			//error_log(__METHOD__.' ('.__LINE__.') returning early Criterias:'.print_r($_criterias, true));
2019
-			$imapFilter->flag('DELETED', $set=false);
2019
+			$imapFilter->flag('DELETED', $set = false);
2020 2020
 			return $imapFilter;
2021 2021
 		}
2022 2022
 		$queryValid = false;
2023 2023
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2024 2024
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2025 2025
 		$statusQueryValid = false;
2026
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2026
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
2027 2027
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2028 2028
 			$imapStatusFilter->charset('UTF-8');
2029 2029
 			$criteria = strtoupper($criteria);
@@ -2033,12 +2033,12 @@  discard block
 block discarded – undo
2033 2033
 				case 'FLAGGED':
2034 2034
 				case 'RECENT':
2035 2035
 				case 'SEEN':
2036
-					$imapStatusFilter->flag($criteria, $set=true);
2037
-					$queryValid = $statusQueryValid =true;
2036
+					$imapStatusFilter->flag($criteria, $set = true);
2037
+					$queryValid = $statusQueryValid = true;
2038 2038
 					break;
2039 2039
 				case 'READ':
2040
-					$imapStatusFilter->flag('SEEN', $set=true);
2041
-					$queryValid = $statusQueryValid =true;
2040
+					$imapStatusFilter->flag('SEEN', $set = true);
2041
+					$queryValid = $statusQueryValid = true;
2042 2042
 					break;
2043 2043
 				case 'LABEL1':
2044 2044
 				case 'KEYWORD1':
@@ -2050,38 +2050,38 @@  discard block
 block discarded – undo
2050 2050
 				case 'KEYWORD4':
2051 2051
 				case 'LABEL5':
2052 2052
 				case 'KEYWORD5':
2053
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
2054
-					$queryValid = $statusQueryValid =true;
2053
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
2054
+					$queryValid = $statusQueryValid = true;
2055 2055
 					break;
2056 2056
 				case 'NEW':
2057
-					$imapStatusFilter->flag('RECENT', $set=true);
2058
-					$imapStatusFilter->flag('SEEN', $set=false);
2059
-					$queryValid = $statusQueryValid =true;
2057
+					$imapStatusFilter->flag('RECENT', $set = true);
2058
+					$imapStatusFilter->flag('SEEN', $set = false);
2059
+					$queryValid = $statusQueryValid = true;
2060 2060
 					break;
2061 2061
 				case 'OLD':
2062
-					$imapStatusFilter->flag('RECENT', $set=false);
2063
-					$queryValid = $statusQueryValid =true;
2062
+					$imapStatusFilter->flag('RECENT', $set = false);
2063
+					$queryValid = $statusQueryValid = true;
2064 2064
 					break;
2065 2065
 // operate only on system flags
2066 2066
 //        $systemflags = array(
2067 2067
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
2068 2068
 //        );
2069 2069
 				case 'UNANSWERED':
2070
-					$imapStatusFilter->flag('ANSWERED', $set=false);
2071
-					$queryValid = $statusQueryValid =true;
2070
+					$imapStatusFilter->flag('ANSWERED', $set = false);
2071
+					$queryValid = $statusQueryValid = true;
2072 2072
 					break;
2073 2073
 				case 'UNDELETED':
2074
-					$imapFilter->flag('DELETED', $set=false);
2074
+					$imapFilter->flag('DELETED', $set = false);
2075 2075
 					$queryValid = true;
2076 2076
 					break;
2077 2077
 				case 'UNFLAGGED':
2078
-					$imapStatusFilter->flag('FLAGGED', $set=false);
2079
-					$queryValid = $statusQueryValid =true;
2078
+					$imapStatusFilter->flag('FLAGGED', $set = false);
2079
+					$queryValid = $statusQueryValid = true;
2080 2080
 					break;
2081 2081
 				case 'UNREAD':
2082 2082
 				case 'UNSEEN':
2083
-					$imapStatusFilter->flag('SEEN', $set=false);
2084
-					$queryValid = $statusQueryValid =true;
2083
+					$imapStatusFilter->flag('SEEN', $set = false);
2084
+					$queryValid = $statusQueryValid = true;
2085 2085
 					break;
2086 2086
 				case 'UNLABEL1':
2087 2087
 				case 'UNKEYWORD1':
@@ -2093,8 +2093,8 @@  discard block
 block discarded – undo
2093 2093
 				case 'UNKEYWORD4':
2094 2094
 				case 'UNLABEL5':
2095 2095
 				case 'UNKEYWORD5':
2096
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
2097
-					$queryValid = $statusQueryValid =true;
2096
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
2097
+					$queryValid = $statusQueryValid = true;
2098 2098
 					break;
2099 2099
 				default:
2100 2100
 					$statusQueryValid = false;
@@ -2110,20 +2110,20 @@  discard block
 block discarded – undo
2110 2110
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2111 2111
 		$imapSearchFilter->charset('UTF-8');
2112 2112
 
2113
-		if(!empty($_criterias['string'])) {
2113
+		if (!empty($_criterias['string'])) {
2114 2114
 			$criteria = strtoupper($_criterias['type']);
2115 2115
 			switch ($criteria) {
2116 2116
 				case 'BYDATE':
2117 2117
 				case 'QUICK':
2118 2118
 				case 'QUICKWITHCC':
2119
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
2119
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
2120 2120
 					//$imapSearchFilter->charset('UTF-8');
2121 2121
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2122 2122
 					$imapFilter2->charset('UTF-8');
2123
-					if($this->isSentFolder($_folder)) {
2124
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2123
+					if ($this->isSentFolder($_folder)) {
2124
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
2125 2125
 					} else {
2126
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2126
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
2127 2127
 					}
2128 2128
 					if ($_supportsOrInQuery)
2129 2129
 					{
@@ -2133,31 +2133,31 @@  discard block
 block discarded – undo
2133 2133
 					{
2134 2134
 						$imapSearchFilter->andSearch($imapFilter2);
2135 2135
 					}
2136
-					if ($_supportsOrInQuery && $criteria=='QUICKWITHCC')
2136
+					if ($_supportsOrInQuery && $criteria == 'QUICKWITHCC')
2137 2137
 					{
2138 2138
 						$imapFilter3 = new Horde_Imap_Client_Search_Query();
2139 2139
 						$imapFilter3->charset('UTF-8');
2140
-						$imapFilter3->headerText('CC', $_criterias['string'], $not=false);
2140
+						$imapFilter3->headerText('CC', $_criterias['string'], $not = false);
2141 2141
 						$imapSearchFilter->orSearch($imapFilter3);
2142 2142
 					}
2143 2143
 					$queryValid = true;
2144 2144
 					break;
2145 2145
 				case 'LARGER':
2146 2146
 				case 'SMALLER':
2147
-					if (strlen(trim($_criterias['string'])) != strlen((float) trim($_criterias['string'])))
2147
+					if (strlen(trim($_criterias['string'])) != strlen((float)trim($_criterias['string'])))
2148 2148
 					{
2149 2149
 						//examine string to evaluate size
2150
-						$unit = strtoupper(trim(substr(trim($_criterias['string']),strlen((float) trim($_criterias['string'])))));
2151
-						$multipleBy = array('KB'=>1024,'K'=>1024,
2152
-											'MB'=>1024*1000,'M'=>1024*1000,
2153
-											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2154
-											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2155
-						$numberinBytes=(float)$_criterias['string'];
2156
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2150
+						$unit = strtoupper(trim(substr(trim($_criterias['string']), strlen((float)trim($_criterias['string'])))));
2151
+						$multipleBy = array('KB'=>1024, 'K'=>1024,
2152
+											'MB'=>1024 * 1000, 'M'=>1024 * 1000,
2153
+											'GB'=>1024 * 1000 * 1000, 'G'=>1024 * 1000 * 1000,
2154
+											'TB'=>1024 * 1000 * 1000 * 1000, 'T'=>1024 * 1000 * 1000 * 1000);
2155
+						$numberinBytes = (float)$_criterias['string'];
2156
+						if (isset($multipleBy[$unit])) $numberinBytes = (float)$_criterias['string'] * $multipleBy[$unit];
2157 2157
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2158
-						$_criterias['string']=$numberinBytes;
2158
+						$_criterias['string'] = $numberinBytes;
2159 2159
 					}
2160
-					$imapSearchFilter->size( $_criterias['string'], ($criteria=='LARGER'?true:false), $not=false);
2160
+					$imapSearchFilter->size($_criterias['string'], ($criteria == 'LARGER' ? true : false), $not = false);
2161 2161
 					//$imapSearchFilter->charset('UTF-8');
2162 2162
 					$queryValid = true;
2163 2163
 					break;
@@ -2166,31 +2166,31 @@  discard block
 block discarded – undo
2166 2166
 				case 'CC':
2167 2167
 				case 'BCC':
2168 2168
 				case 'SUBJECT':
2169
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
2169
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
2170 2170
 					//$imapSearchFilter->charset('UTF-8');
2171 2171
 					$queryValid = true;
2172 2172
 					break;
2173 2173
 				case 'BODY':
2174 2174
 				case 'TEXT':
2175
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2175
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ? true : false), $not = false);
2176 2176
 					//$imapSearchFilter->charset('UTF-8');
2177 2177
 					$queryValid = true;
2178 2178
 					break;
2179 2179
 				case 'SINCE':
2180
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2180
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2181 2181
 					$queryValid = true;
2182 2182
 					break;
2183 2183
 				case 'BEFORE':
2184
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2184
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2185 2185
 					$queryValid = true;
2186 2186
 					break;
2187 2187
 				case 'ON':
2188
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2188
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2189 2189
 					$queryValid = true;
2190 2190
 					break;
2191 2191
 			}
2192 2192
 		}
2193
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2193
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2194 2194
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2195 2195
 
2196 2196
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2199,12 +2199,12 @@  discard block
 block discarded – undo
2199 2199
 			$imapRangeFilter = new Horde_Imap_Client_Search_Query();
2200 2200
 			$imapRangeFilter->charset('UTF-8');
2201 2201
 			$criteria = strtoupper($_criterias['range']);
2202
-			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since']==$_criterias['before'])
2202
+			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since'] == $_criterias['before'])
2203 2203
 			{
2204
-				$_criterias['date']=$_criterias['since'];
2204
+				$_criterias['date'] = $_criterias['since'];
2205 2205
 				unset($_criterias['since']);
2206 2206
 				unset($_criterias['before']);
2207
-				$criteria=$_criterias['range']='ON';
2207
+				$criteria = $_criterias['range'] = 'ON';
2208 2208
 			}
2209 2209
 			switch ($criteria) {
2210 2210
 				case 'BETWEEN':
@@ -2212,7 +2212,7 @@  discard block
 block discarded – undo
2212 2212
 					//enddate
2213 2213
 					if ($_criterias['since'])
2214 2214
 					{
2215
-						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2215
+						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2216 2216
 						$rangeValid = true;
2217 2217
 					}
2218 2218
 					//startdate
@@ -2221,28 +2221,28 @@  discard block
 block discarded – undo
2221 2221
 						$imapRangeFilter2 = new Horde_Imap_Client_Search_Query();
2222 2222
 						$imapRangeFilter2->charset('UTF-8');
2223 2223
 						//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2224
-						$_criterias['before'] = date("d-M-Y",DateTime::to($_criterias['before'],'ts')+(3600*24));
2225
-						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2224
+						$_criterias['before'] = date("d-M-Y", DateTime::to($_criterias['before'], 'ts') + (3600 * 24));
2225
+						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2226 2226
 						$imapRangeFilter->andSearch($imapRangeFilter2);
2227 2227
 						$rangeValid = true;
2228 2228
 					}
2229 2229
 					break;
2230 2230
 				case 'SINCE'://enddate
2231
-					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since']?$_criterias['since']:$_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2231
+					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since'] ? $_criterias['since'] : $_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2232 2232
 					$rangeValid = true;
2233 2233
 					break;
2234 2234
 				case 'BEFORE'://startdate
2235 2235
 					//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2236
-					$_criterias['before'] = date("d-M-Y",DateTime::to(($_criterias['before']?$_criterias['before']:$_criterias['date']),'ts')+(3600*24));
2237
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2236
+					$_criterias['before'] = date("d-M-Y", DateTime::to(($_criterias['before'] ? $_criterias['before'] : $_criterias['date']), 'ts') + (3600 * 24));
2237
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2238 2238
 					$rangeValid = true;
2239 2239
 					break;
2240 2240
 				case 'ON':
2241
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2241
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2242 2242
 					$rangeValid = true;
2243 2243
 					break;
2244 2244
 			}
2245
-			if ($rangeValid && !$queryValid) $queryValid=true;
2245
+			if ($rangeValid && !$queryValid) $queryValid = true;
2246 2246
 			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2247 2247
 		}
2248 2248
 		if (self::$debug)
@@ -2251,8 +2251,8 @@  discard block
 block discarded – undo
2251 2251
 			$query_str = $imapFilter->build();
2252 2252
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2253 2253
 		}
2254
-		if($queryValid==false) {
2255
-			$imapFilter->flag('DELETED', $set=false);
2254
+		if ($queryValid == false) {
2255
+			$imapFilter->flag('DELETED', $set = false);
2256 2256
 			return $imapFilter;
2257 2257
 		} else {
2258 2258
 			return $imapFilter;
@@ -2266,11 +2266,11 @@  discard block
 block discarded – undo
2266 2266
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2267 2267
 	 * @return mixed - based on the input type
2268 2268
 	 */
2269
-	static function decode_header($_string, $_tryIDNConversion=false)
2269
+	static function decode_header($_string, $_tryIDNConversion = false)
2270 2270
 	{
2271 2271
 		if (is_array($_string))
2272 2272
 		{
2273
-			foreach($_string as $k=>$v)
2273
+			foreach ($_string as $k=>$v)
2274 2274
 			{
2275 2275
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2276 2276
 			}
@@ -2278,18 +2278,18 @@  discard block
 block discarded – undo
2278 2278
 		}
2279 2279
 		else
2280 2280
 		{
2281
-			$_string = Mail\Html::decodeMailHeader($_string,self::$displayCharset);
2281
+			$_string = Mail\Html::decodeMailHeader($_string, self::$displayCharset);
2282 2282
 			$test = @json_encode($_string);
2283 2283
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2284
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2284
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2285 2285
 			{
2286 2286
 				// try to fix broken utf8
2287 2287
 				$x = utf8_encode($_string);
2288 2288
 				$test = @json_encode($x);
2289
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2289
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2290 2290
 				{
2291 2291
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2292
-					$_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));
2292
+					$_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));
2293 2293
 				}
2294 2294
 				else
2295 2295
 				{
@@ -2297,7 +2297,7 @@  discard block
 block discarded – undo
2297 2297
 				}
2298 2298
 			}
2299 2299
 
2300
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2300
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2301 2301
 			{
2302 2302
 				$rfcAddr = self::parseAddressList($_string);
2303 2303
 				$stringA = array();
@@ -2309,11 +2309,11 @@  discard block
 block discarded – undo
2309 2309
 						$stringA = array();
2310 2310
 						break; // skip idna conversion if we encounter an error here
2311 2311
 					}
2312
-					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2312
+					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, Horde_Idna::decode($_rfcAddr->host), $_rfcAddr->personal);
2313 2313
 				}
2314
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2314
+				if (!empty($stringA)) $_string = implode(',', $stringA);
2315 2315
 			}
2316
-			if ($_tryIDNConversion==='FORCE')
2316
+			if ($_tryIDNConversion === 'FORCE')
2317 2317
 			{
2318 2318
 				//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.Horde_Idna::decode($_string));
2319 2319
 				$_string = Horde_Idna::decode($_string);
@@ -2329,17 +2329,17 @@  discard block
 block discarded – undo
2329 2329
 	 * @param  boolean $decode try decoding
2330 2330
 	 * @return mixed - based on the input type
2331 2331
 	 */
2332
-	function decode_subject($_string,$decode=true)
2332
+	function decode_subject($_string, $decode = true)
2333 2333
 	{
2334 2334
 		#$string = $_string;
2335
-		if($_string=='NIL')
2335
+		if ($_string == 'NIL')
2336 2336
 		{
2337 2337
 			return 'No Subject';
2338 2338
 		}
2339 2339
 		if ($decode) $_string = self::decode_header($_string);
2340 2340
 		// make sure its utf-8
2341 2341
 		$test = @json_encode($_string);
2342
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2342
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2343 2343
 		{
2344 2344
 			$_string = utf8_encode($_string);
2345 2345
 		}
@@ -2391,18 +2391,18 @@  discard block
 block discarded – undo
2391 2391
 	function createFolder($_parent, $_folderName, &$_error)
2392 2392
 	{
2393 2393
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2394
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2395
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2394
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2395
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2396 2396
 
2397
-		if(empty($parent)) {
2397
+		if (empty($parent)) {
2398 2398
 			$newFolderName = $folderName;
2399 2399
 		} else {
2400 2400
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2401
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2401
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2402 2402
 		}
2403 2403
 		if (empty($newFolderName)) return false;
2404 2404
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2405
-		if ($this->folderExists($newFolderName,true))
2405
+		if ($this->folderExists($newFolderName, true))
2406 2406
 		{
2407 2407
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2408 2408
 			return $newFolderName;
@@ -2419,7 +2419,7 @@  discard block
 block discarded – undo
2419 2419
 		}
2420 2420
 		catch (\Exception $e)
2421 2421
 		{
2422
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2422
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2423 2423
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2424 2424
 			return false;
2425 2425
 		}
@@ -2448,15 +2448,15 @@  discard block
 block discarded – undo
2448 2448
 	 */
2449 2449
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2450 2450
 	{
2451
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2452
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2453
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2451
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2452
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2453
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2454 2454
 
2455
-		if(empty($parent)) {
2455
+		if (empty($parent)) {
2456 2456
 			$newFolderName = $folderName;
2457 2457
 		} else {
2458 2458
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2459
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2459
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2460 2460
 		}
2461 2461
 		if (self::$debug) error_log("create folder: $newFolderName");
2462 2462
 		try
@@ -2465,10 +2465,10 @@  discard block
 block discarded – undo
2465 2465
 		}
2466 2466
 		catch (\Exception $e)
2467 2467
 		{
2468
-			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2468
+			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2469 2469
 		}
2470 2470
 		// clear FolderExistsInfoCache
2471
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2471
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2472 2472
 
2473 2473
 		return $newFolderName;
2474 2474
 
@@ -2487,15 +2487,15 @@  discard block
 block discarded – undo
2487 2487
 		//$folderName = $this->_encodeFolderName($_folderName);
2488 2488
 		try
2489 2489
 		{
2490
-			$this->icServer->subscribeMailbox($_folderName,false);
2490
+			$this->icServer->subscribeMailbox($_folderName, false);
2491 2491
 			$this->icServer->deleteMailbox($_folderName);
2492 2492
 		}
2493 2493
 		catch (\Exception $e)
2494 2494
 		{
2495
-			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2495
+			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2496 2496
 		}
2497 2497
 		// clear FolderExistsInfoCache
2498
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2498
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2499 2499
 
2500 2500
 		return true;
2501 2501
 	}
@@ -2530,10 +2530,10 @@  discard block
 block discarded – undo
2530 2530
 	 *
2531 2531
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2532 2532
 	 */
2533
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2533
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2534 2534
 	{
2535 2535
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2536
-		if (self::$debugTimes) $starttime = microtime (true);
2536
+		if (self::$debugTimes) $starttime = microtime(true);
2537 2537
 		static $folders2return;
2538 2538
 		//$_subscribedOnly=false;
2539 2539
 		// always use static on single request if info is available;
@@ -2541,42 +2541,42 @@  discard block
 block discarded – undo
2541 2541
 		// set $_useCacheIfPossible to false !
2542 2542
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2543 2543
 		{
2544
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2544
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2545 2545
 			return $folders2return[$this->icServer->ImapServerId];
2546 2546
 		}
2547 2547
 
2548
-		if ($_subscribedOnly && $_getCounters===false)
2548
+		if ($_subscribedOnly && $_getCounters === false)
2549 2549
 		{
2550
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2550
+			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2551 2551
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2552 2552
 			{
2553 2553
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2554
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2554
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2555 2555
 				return $folders2return[$this->icServer->ImapServerId];
2556 2556
 			}
2557 2557
 		}
2558 2558
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2559 2559
 		static $folderBasicInfo;
2560
-		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);
2560
+		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);
2561 2561
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2562 2562
 
2563 2563
 		$delimiter = $this->getHierarchyDelimiter();
2564 2564
 
2565 2565
 		$inboxData = new \stdClass;
2566
-		$inboxData->name 		= 'INBOX';
2566
+		$inboxData->name = 'INBOX';
2567 2567
 		$inboxData->folderName		= 'INBOX';
2568
-		$inboxData->displayName		= lang('INBOX');
2568
+		$inboxData->displayName = lang('INBOX');
2569 2569
 		$inboxData->delimiter 		= $delimiter;
2570
-		$inboxData->shortFolderName	= 'INBOX';
2571
-		$inboxData->shortDisplayName	= lang('INBOX');
2570
+		$inboxData->shortFolderName = 'INBOX';
2571
+		$inboxData->shortDisplayName = lang('INBOX');
2572 2572
 		$inboxData->subscribed = true;
2573
-		if($_getCounters == true) {
2573
+		if ($_getCounters == true) {
2574 2574
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2575 2575
 		}
2576 2576
 		// force unsubscribed by preference showAllFoldersInFolderPane
2577 2577
 		if ($_subscribedOnly == true &&
2578 2578
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2579
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2579
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2580 2580
 		{
2581 2581
 			$_subscribedOnly = false;
2582 2582
 		}
@@ -2589,12 +2589,12 @@  discard block
 block discarded – undo
2589 2589
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2590 2590
 		if (is_array($nameSpace))
2591 2591
 		{
2592
-			foreach($nameSpace as $k => $singleNameSpace) {
2592
+			foreach ($nameSpace as $k => $singleNameSpace) {
2593 2593
 				$type = $singleNameSpace['type'];
2594 2594
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2595
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2595
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2596 2596
 
2597
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2597
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2598 2598
 					// fetch and sort the subscribed folders
2599 2599
 					// we alway fetch the subscribed, as this provides the only way to tell
2600 2600
 					// if a folder is subscribed or not
@@ -2602,22 +2602,22 @@  discard block
 block discarded – undo
2602 2602
 					{
2603 2603
 						try
2604 2604
 						{
2605
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2605
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2606 2606
 							if (!empty($subscribedMailboxes))
2607 2607
 							{
2608 2608
 								$fetchedAllInOneGo = true;
2609 2609
 							}
2610 2610
 							else
2611 2611
 							{
2612
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2612
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2613 2613
 							}
2614 2614
 						}
2615
-						catch(Exception $e)
2615
+						catch (Exception $e)
2616 2616
 						{
2617 2617
 							continue;
2618 2618
 						}
2619 2619
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2620
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2620
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ? array_keys($subscribedMailboxes) : array());
2621 2621
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2622 2622
 						//_debug_array($foldersNameSpace);
2623 2623
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2627,18 +2627,18 @@  discard block
 block discarded – undo
2627 2627
 							foreach ($subscribedMailboxes as $k => $finfo)
2628 2628
 							{
2629 2629
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2630
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2631
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2630
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2631
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2632 2632
 									'MAILBOX'=>$finfo['MAILBOX'],
2633 2633
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2634
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2635
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2634
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2635
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2636 2636
 								);
2637
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2637
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2638 2638
 								{
2639 2639
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2640 2640
 								}
2641
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2641
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2642 2642
 								{
2643 2643
 									$foldersNameSpace[$type]['all'][] = $k;
2644 2644
 								}
@@ -2661,7 +2661,7 @@  discard block
 block discarded – undo
2661 2661
 						// that may produce problems, when encountering recursions probably
2662 2662
 						// horde is handling that, so we do not; keep that in mind!
2663 2663
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2664
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2664
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2665 2665
 					}
2666 2666
 					catch (\Exception $e)
2667 2667
 					{
@@ -2679,26 +2679,26 @@  discard block
 block discarded – undo
2679 2679
 					foreach ($allMailboxesExt as $mbx) {
2680 2680
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2681 2681
 						{
2682
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2682
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2683 2683
 								'MAILBOX'=>$mbx['MAILBOX'],
2684 2684
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2685
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2686
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2685
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2686
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2687 2687
 							);
2688 2688
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2689 2689
 							{
2690 2690
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2691 2691
 							}
2692 2692
 						}
2693
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2693
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2694 2694
 						{
2695 2695
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2696 2696
 						}
2697 2697
 						//echo __METHOD__;_debug_array($mbx);
2698 2698
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2699
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2700
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2701
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2699
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2700
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2701
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2702 2702
 						) continue;
2703 2703
 
2704 2704
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2708,7 +2708,7 @@  discard block
 block discarded – undo
2708 2708
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2709 2709
 					$allMailboxes = array();
2710 2710
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2711
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2711
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2712 2712
 						//echo "Result:";_debug_array($allMailboxes);
2713 2713
 					}
2714 2714
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2717,57 +2717,57 @@  discard block
 block discarded – undo
2717 2717
 			}
2718 2718
 		}
2719 2719
 		//subscribed folders may be used in getFolderStatus
2720
-		Cache::setCache(Cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2720
+		Cache::setCache(Cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2721 2721
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2722 2722
 		$autoFolderObjects = $folders = array();
2723 2723
 		$autofolder_exists = array();
2724
-		foreach( array('personal', 'others', 'shared') as $type) {
2725
-			if(isset($foldersNameSpace[$type])) {
2726
-				if($_subscribedOnly) {
2727
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2724
+		foreach (array('personal', 'others', 'shared') as $type) {
2725
+			if (isset($foldersNameSpace[$type])) {
2726
+				if ($_subscribedOnly) {
2727
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2728 2728
 				} else {
2729
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2729
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2730 2730
 				}
2731
-				foreach((array)$listOfFolders as $folderName) {
2731
+				foreach ((array)$listOfFolders as $folderName) {
2732 2732
 					//echo "<br>FolderToCheck:$folderName<br>";
2733 2733
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2734
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2735
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2734
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2735
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2736 2736
 						#echo "$folderName failed to be here <br>";
2737 2737
 						continue;
2738 2738
 					}
2739 2739
 					if (isset($folders[$folderName])) continue;
2740 2740
 					if (isset($autoFolderObjects[$folderName])) continue;
2741
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2741
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2742 2742
 					$folderParts = explode($delimiter, $folderName);
2743 2743
 					$shortName = array_pop($folderParts);
2744 2744
 
2745 2745
 					$folderObject = new \stdClass;
2746
-					$folderObject->delimiter	= $delimiter;
2747
-					$folderObject->folderName	= $folderName;
2748
-					$folderObject->shortFolderName	= $shortName;
2749
-					if(!$_subscribedOnly) {
2746
+					$folderObject->delimiter = $delimiter;
2747
+					$folderObject->folderName = $folderName;
2748
+					$folderObject->shortFolderName = $shortName;
2749
+					if (!$_subscribedOnly) {
2750 2750
 						#echo $folderName."->".$type."<br>";
2751 2751
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2752 2752
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2753 2753
 					}
2754 2754
 
2755
-					if($_getCounters == true) {
2755
+					if ($_getCounters == true) {
2756 2756
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2757 2757
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2758 2758
 					}
2759
-					if(strtoupper($folderName) == 'INBOX') {
2759
+					if (strtoupper($folderName) == 'INBOX') {
2760 2760
 						$folderName = 'INBOX';
2761
-						$folderObject->folderName	= 'INBOX';
2762
-						$folderObject->shortFolderName	= 'INBOX';
2763
-						$folderObject->displayName	= lang('INBOX');
2761
+						$folderObject->folderName = 'INBOX';
2762
+						$folderObject->shortFolderName = 'INBOX';
2763
+						$folderObject->displayName = lang('INBOX');
2764 2764
 						$folderObject->shortDisplayName = lang('INBOX');
2765
-						$folderObject->subscribed	= true;
2765
+						$folderObject->subscribed = true;
2766 2766
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2767
-					} elseif (in_array($shortName,self::$autoFolders)) {
2768
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2767
+					} elseif (in_array($shortName, self::$autoFolders)) {
2768
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2769 2769
 						array_pop($tmpfolderparts);
2770
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2770
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2771 2771
 						$folderObject->shortDisplayName = lang($shortName);
2772 2772
 						unset($tmpfolderparts);
2773 2773
 					} else {
@@ -2775,13 +2775,13 @@  discard block
 block discarded – undo
2775 2775
 						$folderObject->shortDisplayName = $shortName;
2776 2776
 					}
2777 2777
 					//$folderName = $folderName;
2778
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2778
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2779 2779
 						$autoFolderObjects[$folderName] = $folderObject;
2780 2780
 					} else {
2781 2781
 						$folders[$folderName] = $folderObject;
2782 2782
 					}
2783 2783
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2784
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2784
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2785 2785
 					if (isset(self::$specialUseFolders[$folderName]))
2786 2786
 					{
2787 2787
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2790,27 +2790,27 @@  discard block
 block discarded – undo
2790 2790
 			}
2791 2791
 		}
2792 2792
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2793
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2793
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2794 2794
 		}
2795 2795
 		// check if some standard folders are missing and need to be created
2796 2796
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2797 2797
 		{
2798 2798
 			// if new folders have been created, re-read folders ignoring the cache
2799
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2799
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2800 2800
 		}
2801
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2801
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2802 2802
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2803 2803
 		//_debug_array($folders2return); #exit;
2804
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2805
-		if (($_subscribedOnly && $_getCounters===false) ||
2806
-			($_subscribedOnly == false && $_getCounters===false &&
2804
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2805
+		if (($_subscribedOnly && $_getCounters === false) ||
2806
+			($_subscribedOnly == false && $_getCounters === false &&
2807 2807
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2808
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2808
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2809 2809
 		{
2810
-			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2810
+			Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2811 2811
 		}
2812
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2813
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2812
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2813
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2814 2814
 		return $folders2return[$this->icServer->ImapServerId];
2815 2815
 	}
2816 2816
 
@@ -2831,21 +2831,21 @@  discard block
 block discarded – undo
2831 2831
 	 *
2832 2832
 	 * @return array arrays of folders
2833 2833
 	 */
2834
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2834
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2835 2835
 	{
2836 2836
 		// delimiter
2837 2837
 		$delimiter = $this->getHierarchyDelimiter();
2838 2838
 
2839
-		$folders = $nameSpace =  array();
2839
+		$folders = $nameSpace = array();
2840 2840
 		$nameSpaceTmp = $this->_getNameSpaces();
2841
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2842
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2841
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2842
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2843 2843
 		}
2844 2844
 		unset($nameSpaceTmp);
2845 2845
 
2846 2846
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2847 2847
 		// Get special use folders
2848
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2848
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2849 2849
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2850 2850
 		if ($_onlyTopLevel) // top level leaves
2851 2851
 		{
@@ -2856,20 +2856,20 @@  discard block
 block discarded – undo
2856 2856
 			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
2857 2857
 			if (self::$mailConfig['examineNamespace'])
2858 2858
 			{
2859
-				$prefixes=array();
2859
+				$prefixes = array();
2860 2860
 				if (is_array($nameSpace))
2861 2861
 				{
2862
-					foreach($nameSpace as $k => $singleNameSpace) {
2862
+					foreach ($nameSpace as $k => $singleNameSpace) {
2863 2863
 						$type = $singleNameSpace['type'];
2864 2864
 
2865
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2865
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2866 2866
 							$prefixes[$type] = $singleNameSpace['prefix'];
2867 2867
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2868
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2868
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2869 2869
 							if (is_array($result))
2870 2870
 							{
2871 2871
 								ksort($result);
2872
-								$topFolders = array_merge($topFolders,$result);
2872
+								$topFolders = array_merge($topFolders, $result);
2873 2873
 							}
2874 2874
 						}
2875 2875
 					}
@@ -2878,7 +2878,7 @@  discard block
 block discarded – undo
2878 2878
 
2879 2879
 			$autofolders = array();
2880 2880
 
2881
-			foreach(self::$specialUseFolders as $path => $folder)
2881
+			foreach (self::$specialUseFolders as $path => $folder)
2882 2882
 			{
2883 2883
 				if ($this->folderExists($path))
2884 2884
 				{
@@ -2886,9 +2886,9 @@  discard block
 block discarded – undo
2886 2886
 				}
2887 2887
 			}
2888 2888
 			// Check if the special use folders are there, otherwise try to create them
2889
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2889
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2890 2890
 			{
2891
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2891
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2892 2892
 			}
2893 2893
 
2894 2894
 			// now process topFolders for next level
@@ -2896,13 +2896,13 @@  discard block
 block discarded – undo
2896 2896
 			{
2897 2897
 				$pattern = "/\\".$delimiter."/";
2898 2898
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2899
-				if(!empty($prefixes))
2899
+				if (!empty($prefixes))
2900 2900
 				{
2901 2901
 					$reference = '';
2902
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2903
-					foreach($tmpArray as $p)
2902
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2903
+					foreach ($tmpArray as $p)
2904 2904
 					{
2905
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2905
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2906 2906
 					}
2907 2907
 				}
2908 2908
 				$mainFolder = $subFolders = array();
@@ -2938,19 +2938,19 @@  discard block
 block discarded – undo
2938 2938
 							$nFolders [$path] = $folder;
2939 2939
 						}
2940 2940
 					}
2941
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2941
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2942 2942
 					//ksort($aFolders);
2943 2943
 
2944 2944
 					// Sort none auto folders base on mailbox name
2945
-					uasort($nFolders,array($this,'sortByMailbox'));
2945
+					uasort($nFolders, array($this, 'sortByMailbox'));
2946 2946
 
2947
-					$subFolders = array_merge($aFolders,$nFolders);
2947
+					$subFolders = array_merge($aFolders, $nFolders);
2948 2948
 				}
2949 2949
 				else
2950 2950
 				{
2951 2951
 					if (is_array($subFolders)) ksort($subFolders);
2952 2952
 				}
2953
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2953
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2954 2954
 			}
2955 2955
 		}
2956 2956
 		elseif ($_nodePath) // single node
@@ -2977,9 +2977,9 @@  discard block
 block discarded – undo
2977 2977
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
2978 2978
 			}
2979 2979
 
2980
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2980
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2981 2981
 		}
2982
-		elseif(!$_nodePath) // all
2982
+		elseif (!$_nodePath) // all
2983 2983
 		{
2984 2984
 			if ($_subscribedOnly)
2985 2985
 			{
@@ -2995,101 +2995,101 @@  discard block
 block discarded – undo
2995 2995
 		{
2996 2996
 			// SORTING FOLDERS
2997 2997
 			//self::$debugTimes=true;
2998
-			if (self::$debugTimes) $starttime = microtime (true);
2998
+			if (self::$debugTimes) $starttime = microtime(true);
2999 2999
 			// Merge of all auto folders and specialusefolders
3000 3000
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
3001
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
3001
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
3002 3002
 			$tmpFolders = $folders;
3003
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
3004
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
3005
-			$isGoogleMail=false;
3006
-			foreach($autoFoldersTmp as $afk=>$aF)
3003
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
3004
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
3005
+			$isGoogleMail = false;
3006
+			foreach ($autoFoldersTmp as $afk=>$aF)
3007 3007
 			{
3008
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3008
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
3009 3009
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3010 3010
 			}
3011 3011
 			//error_log(array2string($mySpecialUseFolders));
3012 3012
 			foreach ($tmpFolders as $k => $f) {
3013
-				$sorted=false;
3014
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3015
-					if (strtoupper($k)=='INBOX') {
3013
+				$sorted = false;
3014
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
3015
+					if (strtoupper($k) == 'INBOX') {
3016 3016
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3017
-						$inboxFolderObject[$k]=$f;
3017
+						$inboxFolderObject[$k] = $f;
3018 3018
 						unset($folders[$k]);
3019
-						$sorted=true;
3019
+						$sorted = true;
3020 3020
 					} else {
3021
-						$isAutoFolder=false;
3022
-						foreach($autoFoldersTmp as $afk=>$aF)
3021
+						$isAutoFolder = false;
3022
+						foreach ($autoFoldersTmp as $afk=>$aF)
3023 3023
 						{
3024 3024
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3025
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3026
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3027
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3025
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3026
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3027
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3028 3028
 							{
3029 3029
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3030
-								$isAutoFolder=true;
3031
-								$autoFolderObjects[$k]=$f;
3030
+								$isAutoFolder = true;
3031
+								$autoFolderObjects[$k] = $f;
3032 3032
 								break;
3033 3033
 							}
3034 3034
 						}
3035
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3035
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
3036 3036
 						unset($folders[$k]);
3037
-						$sorted=true;
3037
+						$sorted = true;
3038 3038
 					}
3039
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3040
-					$isGoogleMail=true;
3041
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3042
-						$googleMailFolderObject[$k]=$f;
3039
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
3040
+					$isGoogleMail = true;
3041
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
3042
+						$googleMailFolderObject[$k] = $f;
3043 3043
 						unset($folders[$k]);
3044
-						$sorted=true;
3044
+						$sorted = true;
3045 3045
 					} else {
3046
-						$isAutoFolder=false;
3047
-						foreach($autoFoldersTmp as $afk=>$aF)
3046
+						$isAutoFolder = false;
3047
+						foreach ($autoFoldersTmp as $afk=>$aF)
3048 3048
 						{
3049 3049
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3050
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3051
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3052
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3050
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3051
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3052
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3053 3053
 							{
3054 3054
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3055
-								$isAutoFolder=true;
3056
-								$googleAutoFolderObjects[$k]=$f;
3055
+								$isAutoFolder = true;
3056
+								$googleAutoFolderObjects[$k] = $f;
3057 3057
 								break;
3058 3058
 							}
3059 3059
 						}
3060
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3060
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
3061 3061
 						unset($folders[$k]);
3062
-						$sorted=true;
3062
+						$sorted = true;
3063 3063
 					}
3064 3064
 				} else {
3065
-					$isAutoFolder=false;
3066
-					foreach($autoFoldersTmp as $afk=>$aF)
3065
+					$isAutoFolder = false;
3066
+					foreach ($autoFoldersTmp as $afk=>$aF)
3067 3067
 					{
3068 3068
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3069
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3070
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3071
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3069
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3070
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3071
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3072 3072
 						{
3073 3073
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3074
-							$isAutoFolder=true;
3075
-							$autoFolderObjects[$k]=$f;
3074
+							$isAutoFolder = true;
3075
+							$autoFolderObjects[$k] = $f;
3076 3076
 							unset($folders[$k]);
3077
-							$sorted=true;
3077
+							$sorted = true;
3078 3078
 							break;
3079 3079
 						}
3080 3080
 					}
3081 3081
 				}
3082 3082
 
3083
-				if ($sorted==false)
3083
+				if ($sorted == false)
3084 3084
 				{
3085
-					foreach(array('others','shared') as $type)
3085
+					foreach (array('others', 'shared') as $type)
3086 3086
 					{
3087
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3087
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
3088 3088
 						{
3089
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3090
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3089
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
3090
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
3091 3091
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3092
-								$typeFolderObject[$type][$k]=$f;
3092
+								$typeFolderObject[$type][$k] = $f;
3093 3093
 								unset($folders[$k]);
3094 3094
 							}
3095 3095
 						}
@@ -3100,40 +3100,40 @@  discard block
 block discarded – undo
3100 3100
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
3101 3101
 			$autoFolderObjectsTmp = $autoFolderObjects;
3102 3102
 			unset($autoFolderObjects);
3103
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
3104
-			foreach($autoFoldersTmp as $afk=>$aF)
3103
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
3104
+			foreach ($autoFoldersTmp as $afk=>$aF)
3105 3105
 			{
3106
-				foreach($autoFolderObjectsTmp as $k => $f)
3106
+				foreach ($autoFolderObjectsTmp as $k => $f)
3107 3107
 				{
3108
-					if($aF && ($mySpecialUseFolders[$aF]==$k ||
3109
-						substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter ||
3110
-						stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3108
+					if ($aF && ($mySpecialUseFolders[$aF] == $k ||
3109
+						substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter ||
3110
+						stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false))
3111 3111
 					{
3112
-						$autoFolderObjects[$k]=$f;
3112
+						$autoFolderObjects[$k] = $f;
3113 3113
 					}
3114 3114
 				}
3115 3115
 			}
3116 3116
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3117 3117
 			if (!$isGoogleMail) {
3118
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3118
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3119 3119
 			} else {
3120 3120
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3121 3121
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3122 3122
 				unset($googleAutoFolderObjects);
3123
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
3124
-				foreach($autoFoldersTmp as $afk=>$aF)
3123
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
3124
+				foreach ($autoFoldersTmp as $afk=>$aF)
3125 3125
 				{
3126
-					foreach($gAutoFolderObjectsTmp as $k => $f)
3126
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
3127 3127
 					{
3128
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
3128
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
3129 3129
 						{
3130
-							$googleAutoFolderObjects[$k]=$f;
3130
+							$googleAutoFolderObjects[$k] = $f;
3131 3131
 						}
3132 3132
 					}
3133 3133
 				}
3134
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3134
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3135 3135
 			}
3136
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3136
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
3137 3137
 			//self::$debugTimes=false;
3138 3138
 		}
3139 3139
 		// Get counter information and add them to each fetched folders array
@@ -3155,10 +3155,10 @@  discard block
 block discarded – undo
3155 3155
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
3156 3156
 	 * @return int number of new folders created
3157 3157
 	 */
3158
-	function check_create_autofolders(array $autofolders_exists=array())
3158
+	function check_create_autofolders(array $autofolders_exists = array())
3159 3159
 	{
3160 3160
 		$num_created = 0;
3161
-		foreach(self::$autoFolders as $folder)
3161
+		foreach (self::$autoFolders as $folder)
3162 3162
 		{
3163 3163
 			$created = false;
3164 3164
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -3183,7 +3183,7 @@  discard block
 block discarded – undo
3183 3183
 		$rv = false;
3184 3184
 		foreach ($haystack as $k => $v)
3185 3185
 		{
3186
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3186
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
3187 3187
 		}
3188 3188
 		return $rv;
3189 3189
 	}
@@ -3196,9 +3196,9 @@  discard block
 block discarded – undo
3196 3196
 	 * @param array $b array of folders
3197 3197
 	 * @return int expect values (0, 1 or -1)
3198 3198
 	 */
3199
-	function sortByMailbox($a,$b)
3199
+	function sortByMailbox($a, $b)
3200 3200
 	{
3201
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
3201
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
3202 3202
 	}
3203 3203
 
3204 3204
 	/**
@@ -3208,13 +3208,13 @@  discard block
 block discarded – undo
3208 3208
 	 * @param string $_hDelimiter hierarchy delimiter
3209 3209
 	 * @return array returns an array of data extracted from given node path
3210 3210
 	 */
3211
-	static function pathToFolderData ($_path, $_hDelimiter)
3211
+	static function pathToFolderData($_path, $_hDelimiter)
3212 3212
 	{
3213 3213
 		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3214 3214
 		list(,$path) = explode(self::DELIMITER, $_path);
3215 3215
 		$path_chain = $parts = explode($_hDelimiter, $path);
3216 3216
 		$name = array_pop($parts);
3217
-		return array (
3217
+		return array(
3218 3218
 			'name' => $name,
3219 3219
 			'mailbox' => $path,
3220 3220
 			'parent' => implode($_hDelimiter, $parts),
@@ -3237,8 +3237,8 @@  discard block
 block discarded – undo
3237 3237
 		// 0, 1 und -1
3238 3238
 		$a = self::pathToFolderData($_a['MAILBOX'], $_a['delimiter']);
3239 3239
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3240
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3241
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3240
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
3241
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3242 3242
 		if ($pos1 == $pos2) return 0;
3243 3243
 		return ($pos1 < $pos2) ? -1 : 1;
3244 3244
 	}
@@ -3251,10 +3251,10 @@  discard block
 block discarded – undo
3251 3251
 	 * @param object $b array of folderobjects
3252 3252
 	 * @return int expect values (0, 1 or -1)
3253 3253
 	 */
3254
-	function sortByDisplayName($a,$b)
3254
+	function sortByDisplayName($a, $b)
3255 3255
 	{
3256 3256
 		// 0, 1 und -1
3257
-		return strcasecmp($a->displayName,$b->displayName);
3257
+		return strcasecmp($a->displayName, $b->displayName);
3258 3258
 	}
3259 3259
 
3260 3260
 	/**
@@ -3265,11 +3265,11 @@  discard block
 block discarded – undo
3265 3265
 	 * @param object $b array of folderobjects
3266 3266
 	 * @return int expect values (0, 1 or -1)
3267 3267
 	 */
3268
-	function sortByAutoFolderPos($a,$b)
3268
+	function sortByAutoFolderPos($a, $b)
3269 3269
 	{
3270 3270
 		// 0, 1 und -1
3271
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3272
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3271
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3272
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3273 3273
 		if ($pos1 == $pos2) return 0;
3274 3274
 		return ($pos1 < $pos2) ? -1 : 1;
3275 3275
 	}
@@ -3282,7 +3282,7 @@  discard block
 block discarded – undo
3282 3282
 	 * @param boolean $_returnObject return the counters as object rather than an array
3283 3283
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3284 3284
 	 */
3285
-	function getMailBoxCounters($folderName,$_returnObject=true)
3285
+	function getMailBoxCounters($folderName, $_returnObject = true)
3286 3286
 	{
3287 3287
 		try
3288 3288
 		{
@@ -3294,9 +3294,9 @@  discard block
 block discarded – undo
3294 3294
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3295 3295
 			return false;
3296 3296
 		}
3297
-		if(is_array($folderStatus)) {
3298
-			if ($_returnObject===false) return $folderStatus;
3299
-			$status =  new \stdClass;
3297
+		if (is_array($folderStatus)) {
3298
+			if ($_returnObject === false) return $folderStatus;
3299
+			$status = new \stdClass;
3300 3300
 			$status->messages   = $folderStatus['MESSAGES'];
3301 3301
 			$status->unseen     = $folderStatus['UNSEEN'];
3302 3302
 			$status->recent     = $folderStatus['RECENT'];
@@ -3318,42 +3318,42 @@  discard block
 block discarded – undo
3318 3318
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3319 3319
 	 * @return array of mailboxes
3320 3320
 	 */
3321
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3321
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3322 3322
 	{
3323 3323
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3324
-		$maxreclevel=25;
3324
+		$maxreclevel = 25;
3325 3325
 		if ($reclevel > $maxreclevel) {
3326
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3326
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3327 3327
 			return array();
3328 3328
 		}
3329 3329
 		$reclevel++;
3330 3330
 		// clean up double delimiters
3331
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3331
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3332 3332
 		//get that mailbox in question
3333
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3333
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3334 3334
 		$mbxkeys = array_keys($mbx);
3335 3335
 		#_debug_array($mbx);
3336 3336
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3337 3337
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3338 3338
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3339
-		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"]))) {
3339
+		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"]))) {
3340 3340
 			// if there are children fetch them
3341 3341
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3342 3342
 
3343
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3343
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3344 3344
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3345 3345
 			//_debug_array($buff);
3346 3346
 			$allMailboxes = array();
3347 3347
 			foreach ($buff as $mbxname) {
3348 3348
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3349
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3349
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3350 3350
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3351
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3351
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3352 3352
 				{
3353 3353
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3354 3354
 				}
3355 3355
 			}
3356
-			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'];
3356
+			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'];
3357 3357
 			return $allMailboxes;
3358 3358
 		} else {
3359 3359
 			return array($_mailbox);
@@ -3368,18 +3368,18 @@  discard block
 block discarded – undo
3368 3368
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3369 3369
 	 * @return mixed string or false
3370 3370
 	 */
3371
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3371
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3372 3372
 	{
3373 3373
 		static $types = array(
3374
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3375
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3376
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3377
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3378
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3379
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3380
-			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3374
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3375
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3376
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3377
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3378
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3379
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3380
+			'Archive'   => array('profileKey'=>'acc_folder_archive', 'autoFolderName'=>'Archive'),
3381 3381
 		);
3382
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3382
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3383 3383
 		$created = false;
3384 3384
 		if (!isset($types[$_type]))
3385 3385
 		{
@@ -3401,7 +3401,7 @@  discard block
 block discarded – undo
3401 3401
 		}
3402 3402
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3403 3403
 		if ($_type == 'Archive') {
3404
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3404
+			if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3405 3405
 				return false;
3406 3406
 			} else {
3407 3407
 				return $_folderName;
@@ -3409,38 +3409,38 @@  discard block
 block discarded – undo
3409 3409
 
3410 3410
 		}
3411 3411
 		// does the folder exist??? (is configured/preset, but non-existent)
3412
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3412
+		if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3413 3413
 			try
3414 3414
 			{
3415 3415
 				$error = null;
3416 3416
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3417 3417
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3418 3418
 			}
3419
-			catch(Exception $e)
3419
+			catch (Exception $e)
3420 3420
 			{
3421 3421
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3422 3422
 				$_folderName = false;
3423 3423
 			}
3424 3424
 		}
3425 3425
 		// not sure yet if false is the correct behavior on none
3426
-		if ($_folderName =='none') return 'none' ; //false;
3426
+		if ($_folderName == 'none') return 'none'; //false;
3427 3427
 		//no (valid) folder found yet; try specialUseFolders
3428
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3428
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3429 3429
 		//no specialUseFolder; try some Defaults
3430 3430
 		if (empty($_folderName) && isset($types[$_type]))
3431 3431
 		{
3432 3432
 			$nameSpace = $this->_getNameSpaces();
3433
-			$prefix='';
3433
+			$prefix = '';
3434 3434
 			foreach ($nameSpace as $nSp)
3435 3435
 			{
3436
-				if ($nSp['type']=='personal')
3436
+				if ($nSp['type'] == 'personal')
3437 3437
 				{
3438 3438
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3439 3439
 					$prefix = $nSp['prefix'];
3440 3440
 					break;
3441 3441
 				}
3442 3442
 			}
3443
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3443
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3444 3444
 			{
3445 3445
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3446 3446
 			}
@@ -3449,11 +3449,11 @@  discard block
 block discarded – undo
3449 3449
 				try
3450 3450
 				{
3451 3451
 					$error = null;
3452
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3452
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3453 3453
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3454 3454
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3455 3455
 				}
3456
-				catch(Exception $e)
3456
+				catch (Exception $e)
3457 3457
 				{
3458 3458
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3459 3459
 					$_folderName = false;
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
 	 * @param boolean $_checkexistance trigger check for existance
3470 3470
 	 * @return mixed string or false
3471 3471
 	 */
3472
-	function getFolderByType($type, $_checkexistance=false)
3472
+	function getFolderByType($type, $_checkexistance = false)
3473 3473
 	{
3474 3474
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3475 3475
 	}
@@ -3479,7 +3479,7 @@  discard block
 block discarded – undo
3479 3479
 	 * @param boolean $_checkexistance trigger check for existance
3480 3480
 	 * @return mixed string or false
3481 3481
 	 */
3482
-	function getJunkFolder($_checkexistance=TRUE)
3482
+	function getJunkFolder($_checkexistance = TRUE)
3483 3483
 	{
3484 3484
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3485 3485
 	}
@@ -3489,7 +3489,7 @@  discard block
 block discarded – undo
3489 3489
 	 * @param boolean $_checkexistance trigger check for existance
3490 3490
 	 * @return mixed string or false
3491 3491
 	 */
3492
-	function getDraftFolder($_checkexistance=TRUE)
3492
+	function getDraftFolder($_checkexistance = TRUE)
3493 3493
 	{
3494 3494
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3495 3495
 	}
@@ -3499,7 +3499,7 @@  discard block
 block discarded – undo
3499 3499
 	 * @param boolean $_checkexistance trigger check for existance
3500 3500
 	 * @return mixed string or false
3501 3501
 	 */
3502
-	function getTemplateFolder($_checkexistance=TRUE)
3502
+	function getTemplateFolder($_checkexistance = TRUE)
3503 3503
 	{
3504 3504
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3505 3505
 	}
@@ -3509,7 +3509,7 @@  discard block
 block discarded – undo
3509 3509
 	 * @param boolean $_checkexistance trigger check for existance
3510 3510
 	 * @return mixed string or false
3511 3511
 	 */
3512
-	function getTrashFolder($_checkexistance=TRUE)
3512
+	function getTrashFolder($_checkexistance = TRUE)
3513 3513
 	{
3514 3514
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3515 3515
 	}
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
 	 * @param boolean $_checkexistance trigger check for existance
3520 3520
 	 * @return mixed string or false
3521 3521
 	 */
3522
-	function getSentFolder($_checkexistance=TRUE)
3522
+	function getSentFolder($_checkexistance = TRUE)
3523 3523
 	{
3524 3524
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3525 3525
 	}
@@ -3529,7 +3529,7 @@  discard block
 block discarded – undo
3529 3529
 	 * @param boolean $_checkexistance trigger check for existance
3530 3530
 	 * @return mixed string or false
3531 3531
 	 */
3532
-	function getOutboxFolder($_checkexistance=TRUE)
3532
+	function getOutboxFolder($_checkexistance = TRUE)
3533 3533
 	{
3534 3534
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3535 3535
 	}
@@ -3539,7 +3539,7 @@  discard block
 block discarded – undo
3539 3539
 	 * @param boolean $_checkexistance trigger check for existance . We do no autocreation for configured Archive folder
3540 3540
 	 * @return mixed string or false
3541 3541
 	 */
3542
-	function getArchiveFolder($_checkexistance=TRUE)
3542
+	function getArchiveFolder($_checkexistance = TRUE)
3543 3543
 	{
3544 3544
 		return $this->_getSpecialUseFolder('Archive', $_checkexistance);
3545 3545
 	}
@@ -3551,10 +3551,10 @@  discard block
 block discarded – undo
3551 3551
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3552 3552
 	 * @return boolean
3553 3553
 	 */
3554
-	function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3554
+	function isSentFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3555 3555
 	{
3556 3556
 		$sentFolder = $this->getSentFolder($_checkexistance);
3557
-		if(empty($sentFolder)) {
3557
+		if (empty($sentFolder)) {
3558 3558
 			return false;
3559 3559
 		}
3560 3560
 		// does the folder exist???
@@ -3564,13 +3564,13 @@  discard block
 block discarded – undo
3564 3564
 
3565 3565
 		if ($_exactMatch)
3566 3566
 		{
3567
-			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) {
3567
+			if (false !== stripos($_folderName, $sentFolder) && strlen($_folderName) == strlen($sentFolder)) {
3568 3568
 				return true;
3569 3569
 			} else {
3570 3570
 				return false;
3571 3571
 			}
3572 3572
 		} else {
3573
-			if(false !== stripos($_folderName, $sentFolder)) {
3573
+			if (false !== stripos($_folderName, $sentFolder)) {
3574 3574
 				return true;
3575 3575
 			} else {
3576 3576
 				return false;
@@ -3585,9 +3585,9 @@  discard block
 block discarded – undo
3585 3585
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3586 3586
 	 * @return boolean
3587 3587
 	 */
3588
-	function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3588
+	function isOutbox($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3589 3589
 	{
3590
-		if (stripos($_folderName, 'Outbox')===false) {
3590
+		if (stripos($_folderName, 'Outbox') === false) {
3591 3591
 			return false;
3592 3592
 		}
3593 3593
 		// does the folder exist???
@@ -3595,13 +3595,13 @@  discard block
 block discarded – undo
3595 3595
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3596 3596
 			if ($_exactMatch)
3597 3597
 			{
3598
-				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) {
3598
+				if (false !== stripos($_folderName, $outboxFolder) && strlen($_folderName) == strlen($outboxFolder)) {
3599 3599
 					return true;
3600 3600
 				} else {
3601 3601
 					return false;
3602 3602
 				}
3603 3603
 			} else {
3604
-				if(false !== stripos($_folderName, $outboxFolder)) {
3604
+				if (false !== stripos($_folderName, $outboxFolder)) {
3605 3605
 					return true;
3606 3606
 				} else {
3607 3607
 					return false;
@@ -3618,26 +3618,26 @@  discard block
 block discarded – undo
3618 3618
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3619 3619
 	 * @return boolean
3620 3620
 	 */
3621
-	function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3621
+	function isDraftFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3622 3622
 	{
3623 3623
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3624
-		if(empty($draftFolder)) {
3624
+		if (empty($draftFolder)) {
3625 3625
 			return false;
3626 3626
 		}
3627 3627
 		// does the folder exist???
3628 3628
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3629 3629
 			return false;
3630 3630
 		}
3631
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3631
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3632 3632
 		if ($_exactMatch)
3633 3633
 		{
3634
-			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) {
3634
+			if (false !== stripos($_folderName, $draftFolder) && strlen($_folderName) == strlen($draftFolder)) {
3635 3635
 				return true;
3636 3636
 			} else {
3637 3637
 				return false;
3638 3638
 			}
3639 3639
 		} else {
3640
-			if(false !== stripos($_folderName, $draftFolder)) {
3640
+			if (false !== stripos($_folderName, $draftFolder)) {
3641 3641
 				return true;
3642 3642
 			} else {
3643 3643
 				return false;
@@ -3652,10 +3652,10 @@  discard block
 block discarded – undo
3652 3652
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3653 3653
 	 * @return boolean
3654 3654
 	 */
3655
-	function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3655
+	function isTrashFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3656 3656
 	{
3657 3657
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3658
-		if(empty($trashFolder)) {
3658
+		if (empty($trashFolder)) {
3659 3659
 			return false;
3660 3660
 		}
3661 3661
 		// does the folder exist???
@@ -3665,13 +3665,13 @@  discard block
 block discarded – undo
3665 3665
 
3666 3666
 		if ($_exactMatch)
3667 3667
 		{
3668
-			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) {
3668
+			if (false !== stripos($_folderName, $trashFolder) && strlen($_folderName) == strlen($trashFolder)) {
3669 3669
 				return true;
3670 3670
 			} else {
3671 3671
 				return false;
3672 3672
 			}
3673 3673
 		} else {
3674
-			if(false !== stripos($_folderName, $trashFolder)) {
3674
+			if (false !== stripos($_folderName, $trashFolder)) {
3675 3675
 				return true;
3676 3676
 			} else {
3677 3677
 				return false;
@@ -3686,10 +3686,10 @@  discard block
 block discarded – undo
3686 3686
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3687 3687
 	 * @return boolean
3688 3688
 	 */
3689
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3689
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3690 3690
 	{
3691 3691
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3692
-		if(empty($templateFolder)) {
3692
+		if (empty($templateFolder)) {
3693 3693
 			return false;
3694 3694
 		}
3695 3695
 		// does the folder exist???
@@ -3698,13 +3698,13 @@  discard block
 block discarded – undo
3698 3698
 		}
3699 3699
 		if ($_exactMatch)
3700 3700
 		{
3701
-			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) {
3701
+			if (false !== stripos($_folderName, $templateFolder) && strlen($_folderName) == strlen($templateFolder)) {
3702 3702
 				return true;
3703 3703
 			} else {
3704 3704
 				return false;
3705 3705
 			}
3706 3706
 		} else {
3707
-			if(false !== stripos($_folderName, $templateFolder)) {
3707
+			if (false !== stripos($_folderName, $templateFolder)) {
3708 3708
 				return true;
3709 3709
 			} else {
3710 3710
 				return false;
@@ -3718,24 +3718,24 @@  discard block
 block discarded – undo
3718 3718
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3719 3719
 	 * @return mixed string or false
3720 3720
 	 */
3721
-	function folderExists($_folder, $_forceCheck=false)
3721
+	function folderExists($_folder, $_forceCheck = false)
3722 3722
 	{
3723 3723
 		static $folderInfo;
3724 3724
 		$forceCheck = $_forceCheck;
3725 3725
 		if (empty($_folder))
3726 3726
 		{
3727 3727
 			// this error is more or less without significance, unless we force the check
3728
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3728
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3729 3729
 			return false;
3730 3730
 		}
3731 3731
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3732
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3733
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3732
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3733
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3734 3734
 		// reduce traffic within the Instance per User; Expire every 5 hours
3735 3735
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3736
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3736
+		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3737 3737
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3738
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3738
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3739 3739
 		{
3740 3740
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3741 3741
 			return $folderInfo[$this->profileID][$_folder];
@@ -3751,7 +3751,7 @@  discard block
 block discarded – undo
3751 3751
 
3752 3752
 		// does the folder exist???
3753 3753
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3754
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3754
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3755 3755
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3756 3756
 			//return false;
3757 3757
 			//try to connect
@@ -3762,18 +3762,18 @@  discard block
 block discarded – undo
3762 3762
 		}
3763 3763
 		catch (\Exception $e)
3764 3764
 		{
3765
-			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:''));
3766
-			self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
3765
+			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details ? ', '.$e->details : ''));
3766
+			self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
3767 3767
 			$folderInfo[$this->profileID][$_folder] = false;
3768 3768
 		}
3769 3769
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3770 3770
 
3771
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3771
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3772 3772
 			$folderInfo[$this->profileID][$_folder] !== true)
3773 3773
 		{
3774 3774
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3775 3775
 		}
3776
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3776
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3777 3777
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3778 3778
 	}
3779 3779
 
@@ -3786,14 +3786,14 @@  discard block
 block discarded – undo
3786 3786
 	 */
3787 3787
 	function compressFolder($_folderName = false)
3788 3788
 	{
3789
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3790
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3791
-		$trashFolder	= $this->getTrashFolder();
3789
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3790
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3791
+		$trashFolder = $this->getTrashFolder();
3792 3792
 
3793 3793
 		$this->icServer->openMailbox($folderName);
3794 3794
 
3795
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3796
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3795
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3796
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3797 3797
 		} else {
3798 3798
 			$this->icServer->expunge($folderName);
3799 3799
 		}
@@ -3809,19 +3809,19 @@  discard block
 block discarded – undo
3809 3809
 	 * @return bool true, as we do not handle return values yet
3810 3810
 	 * @throws Exception
3811 3811
 	 */
3812
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3812
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3813 3813
 	{
3814 3814
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3815 3815
 		$oldMailbox = '';
3816 3816
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3817 3817
 		if (empty($_messageUID))
3818 3818
 		{
3819
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3819
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3820 3820
 			return false;
3821 3821
 		}
3822
-		elseif ($_messageUID==='all')
3822
+		elseif ($_messageUID === 'all')
3823 3823
 		{
3824
-			$_messageUID= null;
3824
+			$_messageUID = null;
3825 3825
 		}
3826 3826
 		else
3827 3827
 		{
@@ -3830,32 +3830,32 @@  discard block
 block discarded – undo
3830 3830
 			$uidsToDelete->add($_messageUID);
3831 3831
 		}
3832 3832
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3833
-		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");
3833
+		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");
3834 3834
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3835 3835
 		$trashFolder    = $this->getTrashFolder();
3836
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3836
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3837 3837
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3838
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3838
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3839 3839
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3840 3840
 			$deleteOptions = "remove_immediately";
3841 3841
 		}
3842
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3842
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3843 3843
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3844 3844
 			$this->icServer->openMailbox($_folder);
3845 3845
 		}
3846 3846
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3847 3847
 		$updateCache = false;
3848
-		switch($deleteOptions) {
3848
+		switch ($deleteOptions) {
3849 3849
 			case "move_to_trash":
3850 3850
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3851 3851
 				$updateCache = true;
3852
-				if(!empty($trashFolder)) {
3852
+				if (!empty($trashFolder)) {
3853 3853
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3854
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3854
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3855 3855
 					// copy messages
3856 3856
 					try
3857 3857
 					{
3858
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3858
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3859 3859
 					}
3860 3860
 					catch (\Exception $e)
3861 3861
 					{
@@ -3867,18 +3867,18 @@  discard block
 block discarded – undo
3867 3867
 			case "mark_as_deleted":
3868 3868
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3869 3869
 				// mark messages as deleted
3870
-				if (is_null($_messageUID)) $_messageUID='all';
3871
-				foreach((array)$_messageUID as $key =>$uid)
3870
+				if (is_null($_messageUID)) $_messageUID = 'all';
3871
+				foreach ((array)$_messageUID as $key =>$uid)
3872 3872
 				{
3873 3873
 					//flag messages, that are flagged for deletion as seen too
3874 3874
 					$this->flagMessages('read', $uid, $_folder);
3875 3875
 					$flags = $this->getFlags($uid);
3876 3876
 					$this->flagMessages('delete', $uid, $_folder);
3877 3877
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3878
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3878
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3879 3879
 					unset($flags);
3880 3880
 				}
3881
-				foreach((array)$undelete as $key =>$uid)
3881
+				foreach ((array)$undelete as $key =>$uid)
3882 3882
 				{
3883 3883
 					$this->flagMessages('undelete', $uid, $_folder);
3884 3884
 				}
@@ -3887,14 +3887,14 @@  discard block
 block discarded – undo
3887 3887
 			case "remove_immediately":
3888 3888
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3889 3889
 				$updateCache = true;
3890
-				if (is_null($_messageUID)) $_messageUID='all';
3890
+				if (is_null($_messageUID)) $_messageUID = 'all';
3891 3891
 				if (is_object($_messageUID))
3892 3892
 				{
3893 3893
 					$this->flagMessages('delete', $_messageUID, $_folder);
3894 3894
 				}
3895 3895
 				else
3896 3896
 				{
3897
-					foreach((array)$_messageUID as $key =>$uid)
3897
+					foreach ((array)$_messageUID as $key =>$uid)
3898 3898
 					{
3899 3899
 						//flag messages, that are flagged for deletion as seen too
3900 3900
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3904,7 +3904,7 @@  discard block
 block discarded – undo
3904 3904
 				$this->icServer->expunge($_folder);
3905 3905
 				break;
3906 3906
 		}
3907
-		if($oldMailbox != '') {
3907
+		if ($oldMailbox != '') {
3908 3908
 			$this->icServer->openMailbox($oldMailbox);
3909 3909
 		}
3910 3910
 
@@ -3918,7 +3918,7 @@  discard block
 block discarded – undo
3918 3918
 	 *
3919 3919
 	 * @return null/array flags
3920 3920
 	 */
3921
-	function getFlags ($_messageUID) {
3921
+	function getFlags($_messageUID) {
3922 3922
 		try
3923 3923
 		{
3924 3924
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3931,7 +3931,7 @@  discard block
 block discarded – undo
3931 3931
 				'ids' => $uidsToFetch,
3932 3932
 			));
3933 3933
 			if (is_object($headersNew)) {
3934
-				foreach($headersNew->ids() as $id) {
3934
+				foreach ($headersNew->ids() as $id) {
3935 3935
 					$_headerObject = $headersNew->get($id);
3936 3936
 					$flags = $_headerObject->getFlags();
3937 3937
 				}
@@ -3954,22 +3954,22 @@  discard block
 block discarded – undo
3954 3954
 	 *
3955 3955
 	 * @return null/boolean
3956 3956
 	 */
3957
-	function getNotifyFlags ($_messageUID, $flags=null)
3957
+	function getNotifyFlags($_messageUID, $flags = null)
3958 3958
 	{
3959 3959
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3960 3960
 		try
3961 3961
 		{
3962
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3962
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3963 3963
 		}
3964 3964
 		catch (\Exception $e)
3965 3965
 		{
3966 3966
 			return null;
3967 3967
 		}
3968 3968
 
3969
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3969
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3970 3970
 			return true;
3971 3971
 
3972
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3972
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
3973 3973
 			return false;
3974 3974
 
3975 3975
 		return null;
@@ -3986,45 +3986,45 @@  discard block
 block discarded – undo
3986 3986
 	 *
3987 3987
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
3988 3988
 	 */
3989
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
3989
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
3990 3990
 	{
3991 3991
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3992 3992
 		if (empty($_messageUID))
3993 3993
 		{
3994
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3994
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3995 3995
 			return false;
3996 3996
 		}
3997
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
3997
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
3998 3998
 		$folder = $this->icServer->getCurrentMailbox();
3999
-		if (is_array($_messageUID)&& count($_messageUID)>50)
3999
+		if (is_array($_messageUID) && count($_messageUID) > 50)
4000 4000
 		{
4001
-			$count = $this->getMailBoxCounters($folder,true);
4002
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4001
+			$count = $this->getMailBoxCounters($folder, true);
4002
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
4003 4003
 		}
4004 4004
 
4005
-		if ($_messageUID==='all')
4005
+		if ($_messageUID === 'all')
4006 4006
 		{
4007 4007
 			$messageUIDs = array('all');
4008 4008
 		}
4009 4009
 		else
4010 4010
 		{
4011 4011
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4012
-			$messageUIDs = array_chunk($_messageUID,50,true);
4012
+			$messageUIDs = array_chunk($_messageUID, 50, true);
4013 4013
 		}
4014 4014
 		try
4015 4015
 		{
4016
-			foreach($messageUIDs as &$uids)
4016
+			foreach ($messageUIDs as &$uids)
4017 4017
 			{
4018
-				if ($uids==='all')
4018
+				if ($uids === 'all')
4019 4019
 				{
4020
-					$uidsToModify=null;
4020
+					$uidsToModify = null;
4021 4021
 				}
4022 4022
 				else
4023 4023
 				{
4024 4024
 					$uidsToModify = new Horde_Imap_Client_Ids();
4025 4025
 					$uidsToModify->add($uids);
4026 4026
 				}
4027
-				switch($_flag) {
4027
+				switch ($_flag) {
4028 4028
 					case "delete":
4029 4029
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
4030 4030
 						break;
@@ -4048,7 +4048,7 @@  discard block
 block discarded – undo
4048 4048
 						break;
4049 4049
 					case "unread":
4050 4050
 					case "unseen":
4051
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
4051
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
4052 4052
 						break;
4053 4053
 					case "mdnsent":
4054 4054
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -4106,13 +4106,13 @@  discard block
 block discarded – undo
4106 4106
 				}
4107 4107
 			}
4108 4108
 		}
4109
-		catch(Exception $e)
4109
+		catch (Exception $e)
4110 4110
 		{
4111 4111
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4112 4112
 		}
4113 4113
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4114 4114
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4115
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4115
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
4116 4116
 
4117 4117
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
4118 4118
 		return true; // as we do not catch/examine setFlags returnValue
@@ -4133,19 +4133,19 @@  discard block
 block discarded – undo
4133 4133
 	 * @return mixed/bool true,false or new uid
4134 4134
 	 * @throws Exception
4135 4135
 	 */
4136
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4136
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4137 4137
 	{
4138
-		$source = Mail\Account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
4138
+		$source = Mail\Account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
4139 4139
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4140 4140
 		if (empty($_messageUID))
4141 4141
 		{
4142
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4142
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
4143 4143
 			return false;
4144 4144
 		}
4145
-		elseif ($_messageUID==='all')
4145
+		elseif ($_messageUID === 'all')
4146 4146
 		{
4147 4147
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
4148
-			$uidsToMove= null;
4148
+			$uidsToMove = null;
4149 4149
 		}
4150 4150
 		else
4151 4151
 		{
@@ -4154,7 +4154,7 @@  discard block
 block discarded – undo
4154 4154
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4155 4155
 			$uidsToMove->add($_messageUID);
4156 4156
 		}
4157
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
4157
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
4158 4158
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
4159 4159
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
4160 4160
 		{
@@ -4174,19 +4174,19 @@  discard block
 block discarded – undo
4174 4174
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4175 4175
 
4176 4176
 			if (is_object($headersNew)) {
4177
-				$c=0;
4177
+				$c = 0;
4178 4178
 				$retUid = new Horde_Imap_Client_Ids();
4179 4179
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4180 4180
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4181
-				foreach($headersNew as &$_headerObject) {
4181
+				foreach ($headersNew as &$_headerObject) {
4182 4182
 					$c++;
4183 4183
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4184 4184
 					$date = $_headerObject->getImapDate();
4185
-					$currentDate =  new Horde_Imap_Client_DateTime();
4185
+					$currentDate = new Horde_Imap_Client_DateTime();
4186 4186
 					// if the internal Date of the message equals the current date; try using the header date
4187
-					if ($date==$currentDate)
4187
+					if ($date == $currentDate)
4188 4188
 					{
4189
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4189
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4190 4190
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
4191 4191
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
4192 4192
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -4195,20 +4195,20 @@  discard block
 block discarded – undo
4195 4195
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
4196 4196
 					$body = $_headerObject->getFullMsg();
4197 4197
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
4198
-					if ($c==1)
4198
+					if ($c == 1)
4199 4199
 					{
4200 4200
 						$target = Mail\Account::read($_targetProfileID)->imapServer();
4201 4201
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
4202 4202
 						$foldername = $target->getMailbox($_foldername);
4203 4203
 						// make sure the target folder is open and ready
4204 4204
 						$target->openMailbox($foldername);
4205
-						$ret = $target->append($foldername,$dataNflags);
4205
+						$ret = $target->append($foldername, $dataNflags);
4206 4206
 						$retUid->add($ret);
4207 4207
 						unset($dataNflags);
4208 4208
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
4209 4209
 						// inflicting in them. they "reply" with an unspecific IMAP Error
4210
-						time_nanosleep(0,500000);
4211
-						$c=0;
4210
+						time_nanosleep(0, 500000);
4211
+						$c = 0;
4212 4212
 					}
4213 4213
 				}
4214 4214
 				if (isset($dataNflags))
@@ -4218,7 +4218,7 @@  discard block
 block discarded – undo
4218 4218
 					$foldername = $target->getMailbox($_foldername);
4219 4219
 					// make sure the target folder is open and ready
4220 4220
 					$target->openMailbox($foldername);
4221
-					$ret = $target->append($foldername,$dataNflags);
4221
+					$ret = $target->append($foldername, $dataNflags);
4222 4222
 					$retUid->add($ret);
4223 4223
 					unset($dataNflags);
4224 4224
 				}
@@ -4229,7 +4229,7 @@  discard block
 block discarded – undo
4229 4229
 				{
4230 4230
 					$remember = $this->icServer;
4231 4231
 					$this->icServer = $source;
4232
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
4232
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
4233 4233
 					$this->icServer = $remember;
4234 4234
 				}
4235 4235
 			}
@@ -4238,7 +4238,7 @@  discard block
 block discarded – undo
4238 4238
 		{
4239 4239
 			try
4240 4240
 			{
4241
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
4241
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
4242 4242
 			}
4243 4243
 			catch (exception $e)
4244 4244
 			{
@@ -4258,19 +4258,19 @@  discard block
 block discarded – undo
4258 4258
 	 * @param string $format ='' if none is passed, use user prefs
4259 4259
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
4260 4260
 	 */
4261
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
4261
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
4262 4262
 	{
4263 4263
 		try {
4264
-			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4265
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4264
+			$date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable)
4265
+			if ($convert2usertime) $date->setUser(); // convert to user-time
4266 4266
 			$date2return = $date->format($format);
4267 4267
 		}
4268
-		catch(\Exception $e)
4268
+		catch (\Exception $e)
4269 4269
 		{
4270
-			unset($e);	// not used
4270
+			unset($e); // not used
4271 4271
 
4272 4272
 			// remove last space-separated part and retry
4273
-			$parts = explode(' ',$_date);
4273
+			$parts = explode(' ', $_date);
4274 4274
 			if (count($parts) > 1)
4275 4275
 			{
4276 4276
 				array_pop($parts);
@@ -4291,12 +4291,12 @@  discard block
 block discarded – undo
4291 4291
 	 * @param mixed $_charset false or string -> Target charset, if false Mail displayCharset will be used
4292 4292
 	 * @return string
4293 4293
 	 */
4294
-	static function htmlentities($_string, $_charset=false)
4294
+	static function htmlentities($_string, $_charset = false)
4295 4295
 	{
4296 4296
 		//setting the charset (if not given)
4297
-		if ($_charset===false) $_charset = self::$displayCharset;
4297
+		if ($_charset === false) $_charset = self::$displayCharset;
4298 4298
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4299
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4299
+		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string, Translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
4300 4300
 		return $string;
4301 4301
 	}
4302 4302
 
@@ -4313,21 +4313,21 @@  discard block
 block discarded – undo
4313 4313
 		//$_html = str_replace("\t",' ',$_html);
4314 4314
 		//error_log(__METHOD__.__LINE__.':'.$_html);
4315 4315
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4316
-		$_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>'),
4317
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4316
+		$_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>'),
4317
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4318 4318
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4319
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4320
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4319
+		if (stripos($_html, 'style') !== false) Mail\Html::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4320
+		if (stripos($_html, 'head') !== false) Mail\Html::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4321 4321
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4322 4322
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4323 4323
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4324 4324
 
4325 4325
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4326 4326
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4327
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4328
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4329
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4330
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4327
+		if (stripos($_html, '!doctype') !== false) Mail\Html::replaceTagsCompletley($_html, '!doctype');
4328
+		if (stripos($_html, '?xml:namespace') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4329
+		if (stripos($_html, '?xml version') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4330
+		if (strpos($_html, '!CURSOR') !== false) Mail\Html::replaceTagsCompletley($_html, '!CURSOR');
4331 4331
 		// htmLawed filter only the 'body'
4332 4332
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4333 4333
 		//if ($matches[2])
@@ -4338,16 +4338,16 @@  discard block
 block discarded – undo
4338 4338
 		// purify got switched to htmLawed
4339 4339
 		// some testcode to test purifying / htmlawed
4340 4340
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4341
-		$_html = Html\HtmLawed::purify($_html,self::$htmLawed_config,array(),true);
4341
+		$_html = Html\HtmLawed::purify($_html, self::$htmLawed_config, array(), true);
4342 4342
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4343 4343
 		// clean out comments , should not be needed as purify should do the job.
4344 4344
 		$search = array(
4345
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4346
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4345
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4346
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4347 4347
 		);
4348
-		$_html = preg_replace($search,"",$_html);
4348
+		$_html = preg_replace($search, "", $_html);
4349 4349
 		// remove non printable chars
4350
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4350
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4351 4351
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4352 4352
 	}
4353 4353
 
@@ -4364,12 +4364,12 @@  discard block
 block discarded – undo
4364 4364
 	function getMimePartCharset($_mimePartObject)
4365 4365
 	{
4366 4366
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4367
-		$CharsetFound=false;
4367
+		$CharsetFound = false;
4368 4368
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4369
-		if(is_array($_mimePartObject->parameters)) {
4370
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4369
+		if (is_array($_mimePartObject->parameters)) {
4370
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4371 4371
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4372
-				$CharsetFound=true;
4372
+				$CharsetFound = true;
4373 4373
 			}
4374 4374
 		}
4375 4375
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4388,7 +4388,7 @@  discard block
 block discarded – undo
4388 4388
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4389 4389
 	{
4390 4390
 		// decode the part
4391
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4391
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4392 4392
 		switch (strtoupper($_encoding))
4393 4393
 		{
4394 4394
 			case 'BASE64':
@@ -4428,10 +4428,10 @@  discard block
 block discarded – undo
4428 4428
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4429 4429
 		// as attachment AND as abstracted ical information (we use our notification style here).
4430 4430
 		$partText = $partCalendar = $partHTML = null;
4431
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4431
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4432 4432
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4433 4433
 		$ignore_first_part = true;
4434
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4434
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4435 4435
 		{
4436 4436
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4437 4437
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4439,15 +4439,15 @@  discard block
 block discarded – undo
4439 4439
 			if ($ignore_first_part)
4440 4440
 			{
4441 4441
 				$ignore_first_part = false;
4442
-				continue;	// ignore multipart/alternative itself
4442
+				continue; // ignore multipart/alternative itself
4443 4443
 			}
4444 4444
 
4445 4445
 			$mimePart = $_structure->getPart($mime_id);
4446 4446
 
4447
-			switch($mimePart->getPrimaryType())
4447
+			switch ($mimePart->getPrimaryType())
4448 4448
 			{
4449 4449
 				case 'text':
4450
-					switch($mimePart->getSubType())
4450
+					switch ($mimePart->getSubType())
4451 4451
 					{
4452 4452
 						case 'plain':
4453 4453
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4460,7 +4460,7 @@  discard block
 block discarded – undo
4460 4460
 					break;
4461 4461
 
4462 4462
 				case 'multipart':
4463
-					switch($mimePart->getSubType())
4463
+					switch ($mimePart->getSubType())
4464 4464
 					{
4465 4465
 						case 'related':
4466 4466
 						case 'mixed':
@@ -4482,13 +4482,13 @@  discard block
 block discarded – undo
4482 4482
 			}
4483 4483
 		}
4484 4484
 
4485
-		switch($_htmlMode)
4485
+		switch ($_htmlMode)
4486 4486
 		{
4487 4487
 			case 'html_only':
4488 4488
 			case 'always_display':
4489 4489
 				if ($partHTML)
4490 4490
 				{
4491
-					switch($partHTML->getSubType())
4491
+					switch ($partHTML->getSubType())
4492 4492
 					{
4493 4493
 						case 'related':
4494 4494
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4500,7 +4500,7 @@  discard block
 block discarded – undo
4500 4500
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4501 4501
 					}
4502 4502
 				}
4503
-				elseif ($partText && $_htmlMode=='always_display')
4503
+				elseif ($partText && $_htmlMode == 'always_display')
4504 4504
 				{
4505 4505
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4506 4506
 				}
@@ -4546,7 +4546,7 @@  discard block
 block discarded – undo
4546 4546
 	 * @param array	&$skipParts - passed by reference to have control/knowledge which parts are already fetched
4547 4547
 	 * @return array containing the desired part
4548 4548
 	 */
4549
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4549
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array())
4550 4550
 	{
4551 4551
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4552 4552
 		$bodyPart = array();
@@ -4555,7 +4555,7 @@  discard block
 block discarded – undo
4555 4555
 		$ignore_first_part = true;
4556 4556
 		//$skipParts = array();
4557 4557
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4558
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4558
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4559 4559
 		{
4560 4560
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4561 4561
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4563,9 +4563,9 @@  discard block
 block discarded – undo
4563 4563
 			{
4564 4564
 				$ignore_first_part = false;
4565 4565
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4566
-				continue;	// ignore multipart/mixed itself
4566
+				continue; // ignore multipart/mixed itself
4567 4567
 			}
4568
-			if (array_key_exists($mime_id,$skipParts))
4568
+			if (array_key_exists($mime_id, $skipParts))
4569 4569
 			{
4570 4570
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4571 4571
 				continue;
@@ -4573,11 +4573,11 @@  discard block
 block discarded – undo
4573 4573
 
4574 4574
 			$part = $_structure->getPart($mime_id);
4575 4575
 
4576
-			switch($part->getPrimaryType())
4576
+			switch ($part->getPrimaryType())
4577 4577
 			{
4578 4578
 				case 'multipart':
4579 4579
 					if ($part->getDisposition() == 'attachment') continue;
4580
-					switch($part->getSubType())
4580
+					switch ($part->getSubType())
4581 4581
 					{
4582 4582
 						case 'alternative':
4583 4583
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen));
@@ -4593,15 +4593,15 @@  discard block
 block discarded – undo
4593 4593
 					}
4594 4594
 					break;
4595 4595
 				case 'application':
4596
-					switch($part->getSubType())
4596
+					switch ($part->getSubType())
4597 4597
 					{
4598 4598
 						case 'pgp-encrypted':
4599
-							if (($part = $_structure->getPart($mime_id+1)) &&
4599
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4600 4600
 								$part->getType() == 'application/octet-stream')
4601 4601
 							{
4602 4602
 								$this->fetchPartContents($_uid, $part);
4603
-								$skipParts[$mime_id]=$mime_type;
4604
-								$skipParts[$mime_id+1]=$part->getType();
4603
+								$skipParts[$mime_id] = $mime_type;
4604
+								$skipParts[$mime_id + 1] = $part->getType();
4605 4605
 								$bodyPart[] = array(
4606 4606
 									'body'		=> $part->getContents(array(
4607 4607
 										'stream' => false,
@@ -4615,15 +4615,15 @@  discard block
 block discarded – undo
4615 4615
 					break;
4616 4616
 
4617 4617
 				case 'text':
4618
-					switch($part->getSubType())
4618
+					switch ($part->getSubType())
4619 4619
 					{
4620 4620
 						case 'plain':
4621 4621
 						case 'html':
4622 4622
 						case 'calendar': // inline ics/ical files
4623
-							if($part->getDisposition() != 'attachment')
4623
+							if ($part->getDisposition() != 'attachment')
4624 4624
 							{
4625 4625
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4626
-								$skipParts[$mime_id]=$mime_type;
4626
+								$skipParts[$mime_id] = $mime_type;
4627 4627
 							}
4628 4628
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4629 4629
 							break;
@@ -4632,16 +4632,16 @@  discard block
 block discarded – undo
4632 4632
 
4633 4633
 				case 'message':
4634 4634
 					//skip attachments
4635
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4635
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4636 4636
 					{
4637 4637
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4638
-						$skipParts[$mime_id]=$mime_type;
4638
+						$skipParts[$mime_id] = $mime_type;
4639 4639
 					}
4640 4640
 					// do not descend into attached Messages
4641
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4641
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4642 4642
 					{
4643 4643
 						$skipParts[$mime_id.'.0'] = $mime_type;
4644
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4644
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4645 4645
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4646 4646
 						//break 2;
4647 4647
 					}
@@ -4682,13 +4682,13 @@  discard block
 block discarded – undo
4682 4682
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4683 4683
 	 * @return string|resource
4684 4684
 	 */
4685
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4685
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4686 4686
 	{
4687
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4687
+		if (self::$debug) error_log(__METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4688 4688
 
4689 4689
 		if (empty($_folder))
4690 4690
 		{
4691
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4691
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4692 4692
 		}
4693 4693
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4694 4694
 		// querying contents of body part
@@ -4699,11 +4699,11 @@  discard block
 block discarded – undo
4699 4699
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4700 4700
 		$fetchParams = array(
4701 4701
 			'peek' => $_preserveSeen,
4702
-			'decode' => true,	// try decode on server, does NOT neccessary work
4702
+			'decode' => true, // try decode on server, does NOT neccessary work
4703 4703
 		);
4704
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4704
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4705 4705
 		{
4706
-			$_tryDecodingServerside=false;
4706
+			$_tryDecodingServerside = false;
4707 4707
 			$fetchParams = array(
4708 4708
 				'peek' => $_preserveSeen,
4709 4709
 			);
@@ -4723,12 +4723,12 @@  discard block
 block discarded – undo
4723 4723
 		}
4724 4724
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4725 4725
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4726
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4726
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4727 4727
 		{
4728 4728
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4729 4729
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4730 4730
 		}
4731
-		return ($partToReturn?$partToReturn:null);
4731
+		return ($partToReturn ? $partToReturn : null);
4732 4732
 	}
4733 4733
 
4734 4734
 	/**
@@ -4741,13 +4741,13 @@  discard block
 block discarded – undo
4741 4741
 	 * @param boolean $_stream = false true return a stream, false return string
4742 4742
 	 * @return array containing the desired text part, mimeType and charset
4743 4743
 	 */
4744
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4744
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4745 4745
 	{
4746 4746
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4747 4747
 		$bodyPart = array();
4748
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4748
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4749 4749
 
4750
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4750
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4751 4751
 		{
4752 4752
 			$bodyPart = array(
4753 4753
 				'error'		=> 1,
@@ -4793,10 +4793,10 @@  discard block
 block discarded – undo
4793 4793
 	 * @param string $_folder folder to work on
4794 4794
 	 * @return array containing the message body, mimeType and charset
4795 4795
 	 */
4796
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4796
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '')
4797 4797
 	{
4798 4798
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4799
-		if($_htmlOptions != '') {
4799
+		if ($_htmlOptions != '') {
4800 4800
 			$this->htmlOptions = $_htmlOptions;
4801 4801
 		}
4802 4802
 		if (empty($_folder))
@@ -4817,7 +4817,7 @@  discard block
 block discarded – undo
4817 4817
 			return array(
4818 4818
 				array(
4819 4819
 					'error'		=> 1,
4820
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4820
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4821 4821
 					'mimeType'	=> 'text/plain',
4822 4822
 					'charSet'	=> self::$displayCharset,
4823 4823
 				)
@@ -4830,7 +4830,7 @@  discard block
 block discarded – undo
4830 4830
 			//_debug_array($_structure->getMimeId()); exit;
4831 4831
 		}
4832 4832
 
4833
-		switch($_structure->getPrimaryType())
4833
+		switch ($_structure->getPrimaryType())
4834 4834
 		{
4835 4835
 			case 'application':
4836 4836
 				return array(
@@ -4842,7 +4842,7 @@  discard block
 block discarded – undo
4842 4842
 				);
4843 4843
 
4844 4844
 			case 'multipart':
4845
-				switch($_structure->getSubType())
4845
+				switch ($_structure->getSubType())
4846 4846
 				{
4847 4847
 					case 'alternative':
4848 4848
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
@@ -4876,7 +4876,7 @@  discard block
 block discarded – undo
4876 4876
 				$bodyPart = array();
4877 4877
 				if ($_structure->getDisposition() != 'attachment')
4878 4878
 				{
4879
-					switch($_structure->getSubType())
4879
+					switch ($_structure->getSubType())
4880 4880
 					{
4881 4881
 						case 'calendar':
4882 4882
 							// this is handeled in getTextPart
@@ -4892,11 +4892,11 @@  discard block
 block discarded – undo
4892 4892
 
4893 4893
 			case 'attachment':
4894 4894
 			case 'message':
4895
-				switch($_structure->getSubType())
4895
+				switch ($_structure->getSubType())
4896 4896
 				{
4897 4897
 					case 'rfc822':
4898 4898
 						$newStructure = $_structure->getParts();
4899
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4899
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4900 4900
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4901 4901
 				}
4902 4902
 				break;
@@ -4924,11 +4924,11 @@  discard block
 block discarded – undo
4924 4924
 	{
4925 4925
 		if (is_array($_bodyParts))
4926 4926
 		{
4927
-			foreach($_bodyParts as $singleBodyPart)
4927
+			foreach ($_bodyParts as $singleBodyPart)
4928 4928
 			{
4929 4929
 				if (!isset($singleBodyPart['body'])) {
4930 4930
 					$buff = self::normalizeBodyParts($singleBodyPart);
4931
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4931
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4932 4932
 					continue;
4933 4933
 				}
4934 4934
 				$body2return[] = $singleBodyPart;
@@ -4949,14 +4949,14 @@  discard block
 block discarded – undo
4949 4949
 	 * @param boolean $useTidy  switch to use tidy
4950 4950
 	 * @return string a preformatted string with the mails converted to text
4951 4951
 	 */
4952
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4952
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4953 4953
 	{
4954
-		$message='';
4955
-		for($i=0; $i<count($bodyParts); $i++)
4954
+		$message = '';
4955
+		for ($i = 0; $i < count($bodyParts); $i++)
4956 4956
 		{
4957 4957
 			if (!isset($bodyParts[$i]['body'])) {
4958 4958
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4959
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4959
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
4960 4960
 				continue;
4961 4961
 			}
4962 4962
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -4981,32 +4981,32 @@  discard block
 block discarded – undo
4981 4981
 				'(R)',
4982 4982
 			);
4983 4983
 
4984
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4984
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4985 4985
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
4986 4986
 			{
4987
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4987
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
4988 4988
 			}
4989 4989
 
4990
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4990
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4991 4991
 			// add line breaks to $bodyParts
4992 4992
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4993
-			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4993
+			$newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4994 4994
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4995 4995
 			$mailClass->activeMimeType = 'text/plain';
4996 4996
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
4997 4997
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4998 4998
 				if (!$preserveHTML)
4999 4999
 				{
5000
-					$alreadyHtmlLawed=false;
5000
+					$alreadyHtmlLawed = false;
5001 5001
 					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
5002
-					$newBody = str_replace("\n"," ",$newBody);
5002
+					$newBody = str_replace("\n", " ", $newBody);
5003 5003
 					// convert HTML to text, as we dont want HTML in infologs
5004 5004
 					if ($useTidy && extension_loaded('tidy'))
5005 5005
 					{
5006 5006
 						$tidy = new tidy();
5007
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
5007
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
5008 5008
 						// Found errors. Strip it all so there's some output
5009
-						if($tidy->getStatus() == 2)
5009
+						if ($tidy->getStatus() == 2)
5010 5010
 						{
5011 5011
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
5012 5012
 						}
@@ -5017,7 +5017,7 @@  discard block
 block discarded – undo
5017 5017
 						if (!$preserveHTML)
5018 5018
 						{
5019 5019
 							// filter only the 'body', as we only want that part, if we throw away the html
5020
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5020
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
5021 5021
 							if ($matches[2])
5022 5022
 							{
5023 5023
 								$hasOther = true;
@@ -5028,7 +5028,7 @@  discard block
 block discarded – undo
5028 5028
 					else
5029 5029
 					{
5030 5030
 						// htmLawed filter only the 'body'
5031
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5031
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
5032 5032
 						if ($matches[2])
5033 5033
 						{
5034 5034
 							$hasOther = true;
@@ -5037,17 +5037,17 @@  discard block
 block discarded – undo
5037 5037
 						$htmLawed = new Html\HtmLawed();
5038 5038
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
5039 5039
 						// as we switched off HTMLaweds tidy functionality
5040
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
5041
-						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
5042
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5043
-						$alreadyHtmlLawed=true;
5040
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
5041
+						$newBody = $htmLawed->run($newBody, self::$htmLawed_config);
5042
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
5043
+						$alreadyHtmlLawed = true;
5044 5044
 					}
5045 5045
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
5046
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5046
+					if ($preserveHTML == false) $newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, true, true);
5047 5047
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
5048
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5048
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5049 5049
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
5050
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5050
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
5051 5051
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5052 5052
 				}
5053 5053
 				$message .= $newBody;
@@ -5056,9 +5056,9 @@  discard block
 block discarded – undo
5056 5056
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
5057 5057
 			//use Mail\Html::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
5058 5058
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
5059
-			$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,false,false);
5059
+			$newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, false, false);
5060 5060
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
5061
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
5061
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
5062 5062
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
5063 5063
 			$message .= $newBody;
5064 5064
 			//continue;
@@ -5066,27 +5066,27 @@  discard block
 block discarded – undo
5066 5066
 		return $message;
5067 5067
 	}
5068 5068
 
5069
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
5069
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
5070 5070
 	{
5071 5071
 		$lines = explode("\n", $str);
5072 5072
 		$newStr = '';
5073
-		foreach($lines as $line)
5073
+		foreach ($lines as $line)
5074 5074
 		{
5075 5075
 			// replace tabs by 8 space chars, or any tab only counts one char
5076 5076
 			//$line = str_replace("\t","        ",$line);
5077 5077
 			//$newStr .= wordwrap($line, $cols, $cut);
5078
-			$allowedLength = $cols-strlen($cut);
5078
+			$allowedLength = $cols - strlen($cut);
5079 5079
 			//dont try to break lines with links, chance is we mess up the text is way too big
5080
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
5081
-				($dontbreaklinesstartingwith==false ||
5080
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
5081
+				($dontbreaklinesstartingwith == false ||
5082 5082
 				 ($dontbreaklinesstartingwith &&
5083
-				  strlen($dontbreaklinesstartingwith)>=1 &&
5084
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5083
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
5084
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5085 5085
 				 )
5086 5086
 				)
5087 5087
 			   )
5088 5088
 			{
5089
-				$s=explode(" ", $line);
5089
+				$s = explode(" ", $line);
5090 5090
 				$line = "";
5091 5091
 				$linecnt = 0;
5092 5092
 				foreach ($s as &$v) {
@@ -5094,22 +5094,22 @@  discard block
 block discarded – undo
5094 5094
 					// only break long words within the wordboundaries,
5095 5095
 					// but it may destroy links, so we check for href and dont do it if we find one
5096 5096
 					// we check for any html within the word, because we do not want to break html by accident
5097
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
5097
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
5098 5098
 					{
5099
-						$v=wordwrap($v, $allowedLength, $cut, true);
5099
+						$v = wordwrap($v, $allowedLength, $cut, true);
5100 5100
 					}
5101 5101
 					// the rest should be broken at the start of the new word that exceeds the limit
5102
-					if ($linecnt+$cnt > $allowedLength) {
5103
-						$v=$cut.$v;
5102
+					if ($linecnt + $cnt > $allowedLength) {
5103
+						$v = $cut.$v;
5104 5104
 						#$linecnt = 0;
5105
-						$linecnt =strlen($v)-strlen($cut);
5105
+						$linecnt = strlen($v) - strlen($cut);
5106 5106
 					} else {
5107 5107
 						$linecnt += $cnt;
5108 5108
 					}
5109 5109
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5110 5110
 				}
5111 5111
 			}
5112
-			$newStr .= $line . "\n";
5112
+			$newStr .= $line."\n";
5113 5113
 		}
5114 5114
 		return $newStr;
5115 5115
 	}
@@ -5124,12 +5124,12 @@  discard block
 block discarded – undo
5124 5124
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
5125 5125
 	 * @return array the message header
5126 5126
 	 */
5127
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5127
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
5128 5128
 	{
5129 5129
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5130
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5130
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5131 5131
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5132
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5132
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
5133 5133
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5134 5134
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5135 5135
 			$uidsToFetch->add($_uid);
@@ -5142,7 +5142,7 @@  discard block
 block discarded – undo
5142 5142
 				'ids' => $uidsToFetch,
5143 5143
 			));
5144 5144
 			if (is_object($headersNew)) {
5145
-				foreach($headersNew as &$_headerObject) {
5145
+				foreach ($headersNew as &$_headerObject) {
5146 5146
 					$env = $_headerObject->getEnvelope();
5147 5147
 					//_debug_array($envFields->singleFields());
5148 5148
 					$singleFields = $envFields->singleFields();
@@ -5157,34 +5157,34 @@  discard block
 block discarded – undo
5157 5157
 							case 'bcc':
5158 5158
 							case 'sender':
5159 5159
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5160
-								$envelope[$v]=$env->$v->addresses;
5160
+								$envelope[$v] = $env->$v->addresses;
5161 5161
 								$address = array();
5162 5162
 								if (!is_array($envelope[$v])) break;
5163 5163
 								foreach ($envelope[$v] as $k => $ad)
5164 5164
 								{
5165
-									if (stripos($ad,'@')===false)
5165
+									if (stripos($ad, '@') === false)
5166 5166
 									{
5167
-										$remember=$k;
5167
+										$remember = $k;
5168 5168
 									}
5169 5169
 									else
5170 5170
 									{
5171
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
5172
-										$remember=null;
5171
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
5172
+										$remember = null;
5173 5173
 									}
5174 5174
 								}
5175 5175
 								$envelope[$v] = $address;
5176 5176
 								break;
5177 5177
 							case 'date':
5178
-								$envelope[$v]=DateTime::to($env->$v);
5178
+								$envelope[$v] = DateTime::to($env->$v);
5179 5179
 								break;
5180 5180
 							default:
5181
-								$envelope[$v]=$env->$v;
5181
+								$envelope[$v] = $env->$v;
5182 5182
 						}
5183 5183
 					}
5184
-					$envelope['size']=$_headerObject->getSize();
5184
+					$envelope['size'] = $_headerObject->getSize();
5185 5185
 				}
5186 5186
 			}
5187
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
5187
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
5188 5188
 			//if ($decode) _debug_array($envelope);
5189 5189
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
5190 5190
 			if ($decode)
@@ -5192,19 +5192,19 @@  discard block
 block discarded – undo
5192 5192
 				foreach ($envelope as $key => $rvV)
5193 5193
 				{
5194 5194
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5195
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5195
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5196 5196
 				}
5197 5197
 			}
5198 5198
 			return $envelope;
5199 5199
 		} else {
5200 5200
 
5201
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5201
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
5202 5202
 
5203 5203
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
5204 5204
 			//_debug_array($headers);
5205 5205
 			$newData = array(
5206 5206
 				'DATE'		=> $headers['DATE'],
5207
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5207
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
5208 5208
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5209 5209
 			);
5210 5210
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -5215,11 +5215,11 @@  discard block
 block discarded – undo
5215 5215
 			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5216 5216
 			//_debug_array($newData);
5217 5217
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5218
-			foreach($recepientList as $recepientType) {
5219
-				if(isset($headers[$recepientType])) {
5220
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5218
+			foreach ($recepientList as $recepientType) {
5219
+				if (isset($headers[$recepientType])) {
5220
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
5221 5221
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5222
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5222
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5223 5223
 						$addressData = array(
5224 5224
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5225 5225
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5227,15 +5227,15 @@  discard block
 block discarded – undo
5227 5227
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5228 5228
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5229 5229
 						);
5230
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5230
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
5231 5231
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5232 5232
 						} else {
5233 5233
 							$addressData['RFC822_EMAIL'] = 'NIL';
5234 5234
 						}
5235
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5235
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
5236 5236
 					}
5237 5237
 				} else {
5238
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5238
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5239 5239
 						$newData[$recepientType] = $newData['FROM'];
5240 5240
 					} else {
5241 5241
 						$newData[$recepientType] = array();
@@ -5257,10 +5257,10 @@  discard block
 block discarded – undo
5257 5257
 	 * @param string $_folder folder to work on
5258 5258
 	 * @return array|Horde_Mime_Headers message header as array or object
5259 5259
 	 */
5260
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5260
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
5261 5261
 	{
5262 5262
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5263
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5263
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5264 5264
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5265 5265
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5266 5266
 		$uidsToFetch->add($_uid);
@@ -5268,7 +5268,7 @@  discard block
 block discarded – undo
5268 5268
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5269 5269
 		if ($_partID != '')
5270 5270
 		{
5271
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
5271
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
5272 5272
 			$fquery->structure();
5273 5273
 		}
5274 5274
 		else
@@ -5281,18 +5281,18 @@  discard block
 block discarded – undo
5281 5281
 			'ids' => $uidsToFetch,
5282 5282
 		));
5283 5283
 		if (is_object($headersNew)) {
5284
-			foreach($headersNew as $_fetchObject)
5284
+			foreach ($headersNew as $_fetchObject)
5285 5285
 			{
5286
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5286
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5287 5287
 				if ($_partID != '')
5288 5288
 				{
5289 5289
 					$mailStructureObject = $_fetchObject->getStructure();
5290 5290
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5291 5291
 					{
5292
-						if ($mime_id==$_partID)
5292
+						if ($mime_id == $_partID)
5293 5293
 						{
5294 5294
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
5295
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5295
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5296 5296
 							break;
5297 5297
 						}
5298 5298
 					}
@@ -5305,15 +5305,15 @@  discard block
 block discarded – undo
5305 5305
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5306 5306
 				return $headers;
5307 5307
 			}
5308
-			$retValue = is_object($headers) ? $headers->toArray():array();
5308
+			$retValue = is_object($headers) ? $headers->toArray() : array();
5309 5309
 			if ($size) $retValue['size'] = $size;
5310 5310
 		}
5311
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
5311
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
5312 5312
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
5313 5313
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
5314 5314
 		if (is_array($retValue['SUBJECT']))
5315 5315
 		{
5316
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
5316
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
5317 5317
 		}
5318 5318
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
5319 5319
 		if ($decode)
@@ -5321,7 +5321,7 @@  discard block
 block discarded – undo
5321 5321
 			foreach ($retValue as $key => $rvV)
5322 5322
 			{
5323 5323
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5324
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5324
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5325 5325
 			}
5326 5326
 		}
5327 5327
 		return $retValue;
@@ -5338,14 +5338,14 @@  discard block
 block discarded – undo
5338 5338
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5339 5339
 	{
5340 5340
 		static $rawHeaders;
5341
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5341
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5342 5342
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5343 5343
 
5344
-		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);
5345
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5344
+		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);
5345
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5346 5346
 		{
5347 5347
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5348
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5348
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5349 5349
 		}
5350 5350
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5351 5351
 		$uid = $_uid;
@@ -5355,7 +5355,7 @@  discard block
 block discarded – undo
5355 5355
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5356 5356
 		if ($_partID != '')
5357 5357
 		{
5358
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5358
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5359 5359
 			$fquery->structure();
5360 5360
 		}
5361 5361
 		else
@@ -5366,14 +5366,14 @@  discard block
 block discarded – undo
5366 5366
 			'ids' => $uidsToFetch,
5367 5367
 		));
5368 5368
 		if (is_object($headersNew)) {
5369
-			foreach($headersNew as &$_headerObject) {
5369
+			foreach ($headersNew as &$_headerObject) {
5370 5370
 				$retValue = $_headerObject->getHeaderText();
5371 5371
 				if ($_partID != '')
5372 5372
 				{
5373 5373
 					$mailStructureObject = $_headerObject->getStructure();
5374 5374
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5375 5375
 					{
5376
-						if ($mime_id==$_partID)
5376
+						if ($mime_id == $_partID)
5377 5377
 						{
5378 5378
 							$retValue = $_headerObject->getHeaderText($mime_id);
5379 5379
 						}
@@ -5381,8 +5381,8 @@  discard block
 block discarded – undo
5381 5381
 				}
5382 5382
 			}
5383 5383
 		}
5384
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5385
-		Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5384
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5385
+		Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5386 5386
 		return $retValue;
5387 5387
 	}
5388 5388
 
@@ -5395,25 +5395,25 @@  discard block
 block discarded – undo
5395 5395
 	{
5396 5396
 		$style = '';
5397 5397
 		if (empty($_bodyParts)) return "";
5398
-		foreach((array)$_bodyParts as $singleBodyPart) {
5398
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5399 5399
 			if (!isset($singleBodyPart['body'])) {
5400 5400
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5401 5401
 				$style .= $singleBodyPart['body'];
5402 5402
 				continue;
5403 5403
 			}
5404 5404
 
5405
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5405
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5406 5406
 			$singleBodyPart['body'] = Translation::convert(
5407 5407
 				$singleBodyPart['body'],
5408 5408
 				strtolower($singleBodyPart['charSet'])
5409 5409
 			);
5410 5410
 			$ct = 0;
5411
-			$newStyle=array();
5412
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5413
-			if ($ct>0)
5411
+			$newStyle = array();
5412
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5413
+			if ($ct > 0)
5414 5414
 			{
5415 5415
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5416
-				$style2buffer = implode('',$newStyle[0]);
5416
+				$style2buffer = implode('', $newStyle[0]);
5417 5417
 			}
5418 5418
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5419 5419
 			{
@@ -5421,7 +5421,7 @@  discard block
 block discarded – undo
5421 5421
 				$test = json_encode($style2buffer);
5422 5422
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5423 5423
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5424
-				if ($test=="null" && strlen($style2buffer)>0)
5424
+				if ($test == "null" && strlen($style2buffer) > 0)
5425 5425
 				{
5426 5426
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5427 5427
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.Translation::detect_encoding($style2buffer));
@@ -5432,19 +5432,19 @@  discard block
 block discarded – undo
5432 5432
 		}
5433 5433
 		// clean out comments and stuff
5434 5434
 		$search = array(
5435
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5435
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5436 5436
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5437 5437
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5438 5438
 		);
5439
-		$style = preg_replace($search,"",$style);
5439
+		$style = preg_replace($search, "", $style);
5440 5440
 
5441 5441
 		// CSS Security
5442 5442
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5443
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5444
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5443
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5444
+		if (stripos($css, 'script') !== false) Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5445 5445
 		// 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
5446 5446
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5447
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5447
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5448 5448
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5449 5449
 		// TODO: we may have to strip urls and maybe comments and ifs
5450 5450
 		return $css;
@@ -5458,16 +5458,16 @@  discard block
 block discarded – undo
5458 5458
 	 * @param string $_folder folder to work on
5459 5459
 	 * @return string the message body
5460 5460
 	 */
5461
-	function getMessageRawBody($_uid, $_partID = '', $_folder='')
5461
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '')
5462 5462
 	{
5463 5463
 		//TODO: caching einbauen static!
5464 5464
 		static $rawBody;
5465 5465
 		if (is_null($rawBody)) $rawBody = array();
5466
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5467
-		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5466
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5467
+		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5468 5468
 		{
5469 5469
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5470
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5470
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5471 5471
 		}
5472 5472
 
5473 5473
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5480,13 +5480,13 @@  discard block
 block discarded – undo
5480 5480
 		if ($_partID != '')
5481 5481
 		{
5482 5482
 			$fquery->structure();
5483
-			$fquery->bodyPart($_partID,array('peek'=>true));
5483
+			$fquery->bodyPart($_partID, array('peek'=>true));
5484 5484
 		}
5485 5485
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5486 5486
 			'ids' => $uidsToFetch,
5487 5487
 		));
5488 5488
 		if (is_object($headersNew)) {
5489
-			foreach($headersNew as &$_headerObject) {
5489
+			foreach ($headersNew as &$_headerObject) {
5490 5490
 				$body = $_headerObject->getFullMsg();
5491 5491
 				if ($_partID != '')
5492 5492
 				{
@@ -5494,7 +5494,7 @@  discard block
 block discarded – undo
5494 5494
 					//_debug_array($mailStructureObject->contentTypeMap());
5495 5495
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5496 5496
 					{
5497
-						if ($mime_id==$_partID)
5497
+						if ($mime_id == $_partID)
5498 5498
 						{
5499 5499
 							$body = $_headerObject->getBodyPart($mime_id);
5500 5500
 						}
@@ -5503,7 +5503,7 @@  discard block
 block discarded – undo
5503 5503
 			}
5504 5504
 		}
5505 5505
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5506
-		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5506
+		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5507 5507
 		return $body;
5508 5508
 	}
5509 5509
 
@@ -5517,13 +5517,13 @@  discard block
 block discarded – undo
5517 5517
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5518 5518
 	 * @return Horde_Mime_Part
5519 5519
 	 */
5520
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5520
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5521 5521
 	{
5522
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5522
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5523 5523
 
5524 5524
 		if (empty($_folder))
5525 5525
 		{
5526
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5526
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5527 5527
 		}
5528 5528
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5529 5529
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5541,7 +5541,7 @@  discard block
 block discarded – undo
5541 5541
 				'ids' => $uidsToFetch,
5542 5542
 			))->first();
5543 5543
 
5544
-			return is_object($mail)?$mail->getStructure():null;
5544
+			return is_object($mail) ? $mail->getStructure() : null;
5545 5545
 		}
5546 5546
 		catch (\Exception $e)
5547 5547
 		{
@@ -5564,14 +5564,14 @@  discard block
 block discarded – undo
5564 5564
 	 * @param string $_folder folder to work on
5565 5565
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5566 5566
 	 */
5567
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5567
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5568 5568
 	{
5569
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5570
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5569
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5570
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5571 5571
 		$attachments = array();
5572 5572
 		if (!isset($_structure))
5573 5573
 		{
5574
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5574
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5575 5575
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5576 5576
 		}
5577 5577
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5579,7 +5579,7 @@  discard block
 block discarded – undo
5579 5579
 		$skipParts = array();
5580 5580
 		$tnefParts = array();
5581 5581
 		$skip = 0;
5582
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5582
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5583 5583
 		{
5584 5584
 			// skip multipart/encrypted incl. its two sub-parts, as we show 2. sub-part as body to be decrypted client-side
5585 5585
 			if ($mime_type == 'multipart/encrypted')
@@ -5587,7 +5587,7 @@  discard block
 block discarded – undo
5587 5587
 				$skip = 2;
5588 5588
 				continue;
5589 5589
 			}
5590
-			elseif($skip)
5590
+			elseif ($skip)
5591 5591
 			{
5592 5592
 				$skip--;
5593 5593
 				continue;
@@ -5601,10 +5601,10 @@  discard block
 block discarded – undo
5601 5601
 			$partPrimaryType = $part->getPrimaryType();
5602 5602
 			// we only want to retrieve the attachments of the current mail, not those of possible
5603 5603
 			// attached mails
5604
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5604
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5605 5605
 			{
5606 5606
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5607
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5607
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5608 5608
 			}
5609 5609
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5610 5610
 			{
@@ -5612,27 +5612,27 @@  discard block
 block discarded – undo
5612 5612
 				// attachment with no link to show the attachment inline.
5613 5613
 				// Considering this: we "list" everything that matches the above criteria
5614 5614
 				// as attachment in order to not loose/miss information on our data
5615
-				$partDisposition='attachment';
5615
+				$partDisposition = 'attachment';
5616 5616
 			}
5617 5617
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5618
-			if (array_key_exists($mime_id,$skipParts)) continue;
5618
+			if (array_key_exists($mime_id, $skipParts)) continue;
5619 5619
 
5620 5620
 			if ($partDisposition == 'attachment' ||
5621
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5621
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5622 5622
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5623
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5623
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5624 5624
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5625 5625
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5626 5626
 			{
5627 5627
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5628 5628
 				// we attempt to fetch "ourselves"
5629
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5629
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5630 5630
 				$attachment = $part->getAllDispositionParameters();
5631 5631
 				$attachment['disposition'] = $part->getDisposition();
5632 5632
 				$attachment['mimeType'] = $mime_type;
5633 5633
 				$attachment['uid'] = $_uid;
5634 5634
 				$attachment['partID'] = $mime_id;
5635
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5635
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5636 5636
 				if ($fetchTextCalendar)
5637 5637
 				{
5638 5638
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5642,11 +5642,11 @@  discard block
 block discarded – undo
5642 5642
 				}
5643 5643
 				$attachment['size'] = $part->getBytes();
5644 5644
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5645
-				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);
5645
+				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);
5646 5646
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5647 5647
 				//typical winmail.dat attachment is
5648 5648
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5649
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5649
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5650 5650
 				{
5651 5651
 					$tnefParts[] = $attachment;
5652 5652
 				}
@@ -5661,31 +5661,31 @@  discard block
 block discarded – undo
5661 5661
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5662 5662
 			foreach ($tnefParts as $k => $tnp)
5663 5663
 			{
5664
-				$tnefResolved=false;
5665
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5664
+				$tnefResolved = false;
5665
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5666 5666
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5667 5667
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5668 5668
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5669 5669
 				// we need to build Something that meets the needs
5670 5670
 				if ($myTnef)
5671 5671
 				{
5672
-					foreach($myTnef->getParts() as $mime_id => $part)
5672
+					foreach ($myTnef->getParts() as $mime_id => $part)
5673 5673
 					{
5674
-						$tnefResolved=true;
5674
+						$tnefResolved = true;
5675 5675
 						$attachment = $part->getAllDispositionParameters();
5676 5676
 						$attachment['disposition'] = $part->getDisposition();
5677 5677
 						$attachment['mimeType'] = $part->getType();
5678 5678
 						$attachment['uid'] = $tnp['uid'];
5679 5679
 						$attachment['partID'] = $tnp['partID'];
5680 5680
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5681
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5681
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5682 5682
 						$attachment['size'] = $part->getBytes();
5683 5683
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5684
-						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']);
5684
+						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']);
5685 5685
 						$attachments[] = $attachment;
5686 5686
 					}
5687 5687
 				}
5688
-				if ($tnefResolved===false) $attachments[]=$tnp;
5688
+				if ($tnefResolved === false) $attachments[] = $tnp;
5689 5689
 			}
5690 5690
 		}
5691 5691
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5700,9 +5700,9 @@  discard block
 block discarded – undo
5700 5700
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5701 5701
 	 *	return false if there's no attachments or failure
5702 5702
 	 */
5703
-	public function tnef_decoder( $data )
5703
+	public function tnef_decoder($data)
5704 5704
 	{
5705
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5705
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5706 5706
 		{
5707 5707
 			if (!class_exists($class))
5708 5708
 			{
@@ -5734,7 +5734,7 @@  discard block
 block discarded – undo
5734 5734
 				$tmp_part->setContents($data['stream']);
5735 5735
 				$tmp_part->setDescription($data['name']);
5736 5736
 
5737
-				$type = $data['type'] . '/' . $data['subtype'];
5737
+				$type = $data['type'].'/'.$data['subtype'];
5738 5738
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5739 5739
 				{
5740 5740
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5777,24 +5777,24 @@  discard block
 block discarded – undo
5777 5777
 	 *
5778 5778
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5779 5779
 	 */
5780
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5780
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5781 5781
 	{
5782
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5782
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5783 5783
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5784 5784
 		$attachments = array();
5785 5785
 		if ($tnef_parts)
5786 5786
 		{
5787
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5787
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5788 5788
 			{
5789 5789
 
5790 5790
 				$attachment = $part->getAllDispositionParameters();
5791 5791
 				$attachment['mimeType'] = $part->getType();
5792
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5792
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5793 5793
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5794 5794
 				if (empty($attachment['filename']))
5795 5795
 				{
5796
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5797
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5796
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5797
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5798 5798
 				}
5799 5799
 
5800 5800
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5818,10 +5818,10 @@  discard block
 block discarded – undo
5818 5818
 	 *
5819 5819
 	 * @return array
5820 5820
 	 */
5821
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5821
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5822 5822
 	{
5823 5823
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5824
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5824
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5825 5825
 
5826 5826
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5827 5827
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5834,36 +5834,36 @@  discard block
 block discarded – undo
5834 5834
 			'ids' => $uidsToFetch,
5835 5835
 		));
5836 5836
 		if (is_object($headersNew)) {
5837
-			foreach($headersNew as $id=>$_headerObject) {
5837
+			foreach ($headersNew as $id=>$_headerObject) {
5838 5838
 				$body = $_headerObject->getFullMsg();
5839 5839
 				if ($_partID != '')
5840 5840
 				{
5841 5841
 					$mailStructureObject = $_headerObject->getStructure();
5842 5842
 					$mailStructureObject->contentTypeMap();
5843 5843
 					$part = $mailStructureObject->getPart($_partID);
5844
-					$partDisposition = ($part?$part->getDisposition():'failed');
5845
-					if ($partDisposition=='failed')
5844
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5845
+					if ($partDisposition == 'failed')
5846 5846
 					{
5847 5847
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5848 5848
 					}
5849 5849
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5850 5850
 					// itself is only triggered to fetch attachments
5851
-					if (empty($partDisposition)) $partDisposition='attachment';
5852
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5851
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5852
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5853 5853
 					{
5854 5854
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5855 5855
 						$structure_mime = $part->getType();
5856 5856
 						$filename = $part->getName();
5857 5857
 						$charset = $part->getContentTypeParameter('charset');
5858 5858
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5859
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5859
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5860 5860
 						if ($_returnPart) return $part;
5861 5861
 					}
5862 5862
 				}
5863 5863
 			}
5864 5864
 		}
5865 5865
 		$ext = MimeMagic::mime2ext($structure_mime);
5866
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5866
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5867 5867
 		if (!$part)
5868 5868
 		{
5869 5869
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5881,20 +5881,20 @@  discard block
 block discarded – undo
5881 5881
 		// try guessing the mimetype, if we get the application/octet-stream
5882 5882
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
5883 5883
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5884
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5884
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5885 5885
 		{
5886 5886
 			//by now _uid is of type array
5887
-			$tnefResolved=false;
5888
-			$wantedPart=$_uid[0].'@'.$_partID;
5887
+			$tnefResolved = false;
5888
+			$wantedPart = $_uid[0].'@'.$_partID;
5889 5889
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5890 5890
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5891 5891
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5892 5892
 			// we need to build Something that meets the needs
5893 5893
 			if ($myTnef)
5894 5894
 			{
5895
-				foreach($myTnef->getParts() as $mime_id => $part)
5895
+				foreach ($myTnef->getParts() as $mime_id => $part)
5896 5896
 				{
5897
-					$tnefResolved=true;
5897
+					$tnefResolved = true;
5898 5898
 					$attachment = $part->getAllDispositionParameters();
5899 5899
 					$attachment['mimeType'] = $part->getType();
5900 5900
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5902,9 +5902,9 @@  discard block
 block discarded – undo
5902 5902
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5903 5903
 					{
5904 5904
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5905
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5905
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5906 5906
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5907
-						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']);
5907
+						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']);
5908 5908
 						$wmattach = $attachment;
5909 5909
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5910 5910
 
@@ -5914,7 +5914,7 @@  discard block
 block discarded – undo
5914 5914
 			if ($tnefResolved)
5915 5915
 			{
5916 5916
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5917
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5917
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5918 5918
 				$attachmentData = array(
5919 5919
 					'type'       => $wmattach['mimeType'],
5920 5920
 					'filename'   => $wmattach['filename'],
@@ -5938,21 +5938,21 @@  discard block
 block discarded – undo
5938 5938
 	 *	true:
5939 5939
 	 * @return Horde_Mime_Part
5940 5940
 	 */
5941
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5941
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5942 5942
 	{
5943 5943
 		// some static variables to avoid fetching the same mail multiple times
5944
-		static $uid=null, $part=null, $structure=null;
5944
+		static $uid = null, $part = null, $structure = null;
5945 5945
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5946 5946
 
5947
-		if(empty($_cid)) return false;
5947
+		if (empty($_cid)) return false;
5948 5948
 
5949 5949
 		if ($_uid != $uid || $_part != $part)
5950 5950
 		{
5951
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5951
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5952 5952
 		}
5953 5953
 		/** @var Horde_Mime_Part */
5954 5954
 		$attachment = null;
5955
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5955
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
5956 5956
 		{
5957 5957
 			$part = $structure->getPart($mime_id);
5958 5958
 
@@ -6004,16 +6004,16 @@  discard block
 block discarded – undo
6004 6004
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
6005 6005
 	 * @return Horde_Mime_Part
6006 6006
 	 */
6007
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
6007
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
6008 6008
 	{
6009
-		if (is_null($part)) return null;//new Horde_Mime_Part;
6009
+		if (is_null($part)) return null; //new Horde_Mime_Part;
6010 6010
 		$encoding = null;
6011 6011
 		$fetchAsBinary = true;
6012
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
6012
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
6013 6013
 		// we need to set content on structure to decode transfer encoding
6014 6014
 		$part->setContents(
6015 6015
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
6016
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
6016
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
6017 6017
 
6018 6018
 		return $part;
6019 6019
 	}
@@ -6031,17 +6031,17 @@  discard block
 block discarded – undo
6031 6031
 	 * @return the id of the message appended or exception
6032 6032
 	 * @throws Exception\WrongUserinput
6033 6033
 	 */
6034
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
6034
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
6035 6035
 	{
6036 6036
 		if (!is_resource($_header))
6037 6037
 		{
6038
-			if (stripos($_header,'message-id:')===false)
6038
+			if (stripos($_header, 'message-id:') === false)
6039 6039
 			{
6040 6040
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
6041 6041
 			}
6042 6042
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
6043
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
6044
-			$_header .= str_replace("\n","\r\n",$_body);
6043
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
6044
+			$_header .= str_replace("\n", "\r\n", $_body);
6045 6045
 		}
6046 6046
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
6047 6047
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -6059,7 +6059,7 @@  discard block
 block discarded – undo
6059 6059
 			// searched for the message-id then returning the uid found
6060 6060
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
6061 6061
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
6062
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
6062
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
6063 6063
 		}
6064 6064
 		catch (\Exception $e)
6065 6065
 		{
@@ -6071,7 +6071,7 @@  discard block
 block discarded – undo
6071 6071
 		//$messageid = true; // for debug reasons only
6072 6072
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
6073 6073
 		{
6074
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
6074
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
6075 6075
 			if ($list)
6076 6076
 			{
6077 6077
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -6111,27 +6111,27 @@  discard block
 block discarded – undo
6111 6111
 	 *				'attachments'=>$attachments,
6112 6112
 	 *				'headers'=>$headers,; boolean false on failure
6113 6113
 	 */
6114
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
6114
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
6115 6115
 	{
6116 6116
 			//echo __METHOD__." called for $uid,$partid <br>";
6117
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6117
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
6118 6118
 			if (empty($headers)) return false;
6119 6119
 			// dont force retrieval of the textpart, let mailClass preferences decide
6120
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6120
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
6121 6121
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
6122
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
6122
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
6123 6123
 			{
6124
-				foreach($bodyParts as $i => $part)
6124
+				foreach ($bodyParts as $i => $part)
6125 6125
 				{
6126
-					if ($bodyParts[$i]['mimeType']=='text/html')
6126
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
6127 6127
 					{
6128
-						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
6129
-						$bodyParts[$i]['mimeType']='text/plain';
6128
+						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
6129
+						$bodyParts[$i]['mimeType'] = 'text/plain';
6130 6130
 					}
6131 6131
 				}
6132 6132
 			}
6133 6133
 			//error_log(array2string($bodyParts));
6134
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6134
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
6135 6135
 
6136 6136
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6137 6137
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -6142,7 +6142,7 @@  discard block
 block discarded – undo
6142 6142
 
6143 6143
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6144 6144
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6145
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6145
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
6146 6146
 			$message = $headdata.$message;
6147 6147
 			//echo __METHOD__.'<br>';
6148 6148
 			//_debug_array($attachments);
@@ -6158,25 +6158,25 @@  discard block
 block discarded – undo
6158 6158
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
6159 6159
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
6160 6160
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
6161
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
6162
-						$headdata ='';
6161
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
6162
+						$headdata = '';
6163 6163
 						if ($mailcontent['headers'])
6164 6164
 						{
6165
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
6165
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
6166 6166
 						}
6167 6167
 						if ($mailcontent['message'])
6168 6168
 						{
6169
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6169
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6170 6170
 							$attachedMessages[] = array(
6171 6171
 								'type' => 'TEXT/PLAIN',
6172 6172
 								'name' => $mailcontent['subject'].'.txt',
6173 6173
 								'tmp_name' => $tempname,
6174 6174
 							);
6175
-							$tmpfile = fopen($tempname,'w');
6176
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
6175
+							$tmpfile = fopen($tempname, 'w');
6176
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
6177 6177
 							fclose($tmpfile);
6178 6178
 						}
6179
-						foreach($mailcontent['attachments'] as &$tmpval)
6179
+						foreach ($mailcontent['attachments'] as &$tmpval)
6180 6180
 						{
6181 6181
 							$attachedMessages[] = $tmpval;
6182 6182
 						}
@@ -6184,36 +6184,36 @@  discard block
 block discarded – undo
6184 6184
 					}
6185 6185
 					else
6186 6186
 					{
6187
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
6187
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
6188 6188
 
6189
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
6189
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
6190 6190
 						{
6191
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
6191
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
6192 6192
 							$attachments[$num]['attachment'] = $c->getContents();
6193 6193
 						}
6194 6194
 						// no attempt to convert, if we dont know about the charset
6195
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6195
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
6196 6196
 							// we do not try guessing the charset, if it is not set
6197 6197
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6198
-							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
6198
+							Translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
6199 6199
 						}
6200
-						if(in_array($attachments[$num]['name'], $file_list))
6200
+						if (in_array($attachments[$num]['name'], $file_list))
6201 6201
 						{
6202 6202
 							$dupe_count[$attachments[$num]['name']]++;
6203
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
6204
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
6203
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
6204
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
6205 6205
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
6206 6206
 						}
6207 6207
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
6208
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6209
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
6210
-						fwrite($tmpfile,$attachments[$num]['attachment']);
6208
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6209
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
6210
+						fwrite($tmpfile, $attachments[$num]['attachment']);
6211 6211
 						fclose($tmpfile);
6212 6212
 						$file_list[] = $attachments[$num]['name'];
6213 6213
 						unset($attachments[$num]['attachment']);
6214 6214
 					}
6215 6215
 				}
6216
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6216
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
6217 6217
 			}
6218 6218
 			return array(
6219 6219
 					'mailaddress'=>$mailaddress,
@@ -6235,10 +6235,10 @@  discard block
 block discarded – undo
6235 6235
 	{
6236 6236
 		$c = 0;
6237 6237
 		// use the standardIdentity
6238
-		foreach($_identities as $key => $acc) {
6239
-			if ($c==0) $identity = $acc;
6238
+		foreach ($_identities as $key => $acc) {
6239
+			if ($c == 0) $identity = $acc;
6240 6240
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6241
-			if ($key==$_profile_id) $identity = $acc;
6241
+			if ($key == $_profile_id) $identity = $acc;
6242 6242
 			$c++;
6243 6243
 		}
6244 6244
 		return $identity;
@@ -6250,29 +6250,29 @@  discard block
 block discarded – undo
6250 6250
 	 * @param bool createHTML do it with HTML breaks
6251 6251
 	 * @return string a preformatted string with the information of the header worked into it
6252 6252
 	 */
6253
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
6253
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
6254 6254
 	{
6255 6255
 		$headdata = null;
6256 6256
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6257
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6258
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6259
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6260
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6261
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6262
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6263
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6264
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6265
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
6257
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
6258
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
6259
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
6260
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
6261
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
6262
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
6263
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
6264
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
6265
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
6266 6266
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6267 6267
 		if (!empty($headdata))
6268 6268
 		{
6269
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6270
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
6271
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6269
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
6270
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
6271
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6272 6272
 		}
6273 6273
 		else
6274 6274
 		{
6275
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6275
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6276 6276
 		}
6277 6277
 		return $headdata;
6278 6278
 	}
@@ -6285,8 +6285,8 @@  discard block
 block discarded – undo
6285 6285
 	 */
6286 6286
 	static function adaptSubjectForImport($subject)
6287 6287
 	{
6288
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
6289
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
6288
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
6289
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
6290 6290
 		return $subject;
6291 6291
 	}
6292 6292
 
@@ -6298,15 +6298,15 @@  discard block
 block discarded – undo
6298 6298
 	static function convertAddressArrayToString($rfcAddressArray)
6299 6299
 	{
6300 6300
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
6301
-		$returnAddr ='';
6301
+		$returnAddr = '';
6302 6302
 		if (is_array($rfcAddressArray))
6303 6303
 		{
6304
-			foreach((array)$rfcAddressArray as $addressData) {
6304
+			foreach ((array)$rfcAddressArray as $addressData) {
6305 6305
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6306
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
6306
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
6307 6307
 					continue;
6308 6308
 				}
6309
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6309
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6310 6310
 					continue;
6311 6311
 				}
6312 6312
 				if ($addressData['RFC822_EMAIL'])
@@ -6315,7 +6315,7 @@  discard block
 block discarded – undo
6315 6315
 				}
6316 6316
 				else
6317 6317
 				{
6318
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
6318
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
6319 6319
 					$addressObjectA = self::parseAddressList($emailaddress);
6320 6320
 				}
6321 6321
 				$addressObject = $addressObjectA[0];
@@ -6324,10 +6324,10 @@  discard block
 block discarded – undo
6324 6324
 				//$mb =(string)$addressObject->mailbox;
6325 6325
 				//$h = (string)$addressObject->host;
6326 6326
 				//$p = (string)$addressObject->personal;
6327
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
6327
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
6328 6328
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
6329 6329
 				$buff = imap_rfc822_write_address($addressObject->mailbox, Horde_Idna::decode($addressObject->host), $addressObject->personal);
6330
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
6330
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
6331 6331
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6332 6332
 				$returnAddr .= $buff;
6333 6333
 			}
@@ -6335,8 +6335,8 @@  discard block
 block discarded – undo
6335 6335
 		else
6336 6336
 		{
6337 6337
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6338
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6339
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6338
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6339
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6340 6340
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6341 6341
 		}
6342 6342
 		return $returnAddr;
@@ -6350,12 +6350,12 @@  discard block
 block discarded – undo
6350 6350
 	 * @param string &$err error-message on error
6351 6351
 	 * @return string/boolean merged content or false on error
6352 6352
 	 */
6353
-	static function merge($content,$ids,$mimetype='')
6353
+	static function merge($content, $ids, $mimetype = '')
6354 6354
 	{
6355 6355
 		$mergeobj = new Contacts\Merge();
6356 6356
 
6357
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6358
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6357
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6358
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6359 6359
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6360 6360
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6361 6361
 		return $rv;
@@ -6397,12 +6397,12 @@  discard block
 block discarded – undo
6397 6397
 		else
6398 6398
 			settype($bytes, 'integer');
6399 6399
 
6400
-		return $bytes . ' ' . $type ;
6400
+		return $bytes.' '.$type;
6401 6401
 	}
6402 6402
 
6403 6403
 	static function detect_qp(&$sting) {
6404 6404
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6405
-		return preg_match("$needle",$string);
6405
+		return preg_match("$needle", $string);
6406 6406
 	}
6407 6407
 
6408 6408
 	/**
@@ -6415,11 +6415,11 @@  discard block
 block discarded – undo
6415 6415
 	 * @param string $_methodNline - Information where the log was taken
6416 6416
 	 * @return void
6417 6417
 	 */
6418
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6418
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6419 6419
 	{
6420 6420
 		if (is_null($_endtime)) $_endtime = microtime(true);
6421 6421
 		$usagetime = microtime(true) - $_starttime;
6422
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6422
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6423 6423
 	}
6424 6424
 
6425 6425
 	/**
@@ -6432,9 +6432,9 @@  discard block
 block discarded – undo
6432 6432
 	 *
6433 6433
 	 * @throws Exception\WrongUserinput
6434 6434
 	 */
6435
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6435
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6436 6436
 	{
6437
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6437
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6438 6438
 
6439 6439
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6440 6440
 		$importfailed = $tmpFileName = false;
@@ -6444,7 +6444,7 @@  discard block
 block discarded – undo
6444 6444
 			$importfailed = true;
6445 6445
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6446 6446
 		}
6447
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6447
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6448 6448
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6449 6449
 		{
6450 6450
 			// ensure existance of eGW temp dir
@@ -6452,7 +6452,7 @@  discard block
 block discarded – undo
6452 6452
 			// and different from any other temp file location set in php.ini
6453 6453
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6454 6454
 			{
6455
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6455
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6456 6456
 			}
6457 6457
 
6458 6458
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6479,14 +6479,14 @@  discard block
 block discarded – undo
6479 6479
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6480 6480
 			// so we check for the suffix too
6481 6481
 			// trust vfs mime-types, trust the mimetype if it contains a method
6482
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6482
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6483 6483
 			{
6484
-				$buff = explode('.',$_formData['name']);
6484
+				$buff = explode('.', $_formData['name']);
6485 6485
 				$suffix = '';
6486 6486
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6487 6487
 				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
6488 6488
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6489
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6489
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6490 6490
 				{
6491 6491
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6492 6492
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6501,13 +6501,13 @@  discard block
 block discarded – undo
6501 6501
 			if ($reqMimeType)
6502 6502
 			{
6503 6503
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6504
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6504
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6505 6505
 				{
6506 6506
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6507 6507
 					{
6508 6508
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6509 6509
 						$importfailed = true;
6510
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6510
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6511 6511
 					}
6512 6512
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6513 6513
 					{
@@ -6516,17 +6516,17 @@  discard block
 block discarded – undo
6516 6516
 				}
6517 6517
 			}
6518 6518
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6519
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6519
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6520 6520
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6521 6521
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6522 6522
 
6523
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6523
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6524 6524
 			{
6525
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6525
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6526 6526
 			}
6527 6527
 			elseif (is_uploaded_file($_formData['file']))
6528 6528
 			{
6529
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);	// requirement for safe_mode!
6529
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); // requirement for safe_mode!
6530 6530
 			}
6531 6531
 			else
6532 6532
 			{
@@ -6535,7 +6535,7 @@  discard block
 block discarded – undo
6535 6535
 		} else {
6536 6536
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6537 6537
 			$importfailed = true;
6538
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6538
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6539 6539
 		}
6540 6540
 		if ($importfailed == true)
6541 6541
 		{
@@ -6543,7 +6543,7 @@  discard block
 block discarded – undo
6543 6543
 		}
6544 6544
 		else
6545 6545
 		{
6546
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6546
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6547 6547
 			{
6548 6548
 				Vfs::load_wrapper('vfs');
6549 6549
 			}
@@ -6568,7 +6568,7 @@  discard block
 block discarded – undo
6568 6568
 		$images = null;
6569 6569
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6570 6570
 		{
6571
-			foreach($images[2] as $i => $url)
6571
+			foreach ($images[2] as $i => $url)
6572 6572
 			{
6573 6573
 				//$isData = false;
6574 6574
 				$basedir = $data = '';
@@ -6580,20 +6580,20 @@  discard block
 block discarded – undo
6580 6580
 					$filename = basename($url);
6581 6581
 					if (($directory = dirname($url)) == '.') $directory = '';
6582 6582
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6583
-					$mimeType  = MimeMagic::ext2mime($ext);
6584
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6583
+					$mimeType = MimeMagic::ext2mime($ext);
6584
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6585 6585
 					$myUrl = $directory.$filename;
6586
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6586
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6587 6587
 					{
6588
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6588
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6589 6589
 					}
6590 6590
 					// use vfs instead of url containing webdav.php
6591 6591
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6592 6592
 					// webdav.php urls as vfs
6593
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6593
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6594 6594
 					{
6595 6595
 						Vfs::load_wrapper('vfs');
6596
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6596
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6597 6597
 						$basedir = 'vfs://default';
6598 6598
 						$needTempFile = false;
6599 6599
 					}
@@ -6606,11 +6606,11 @@  discard block
 block discarded – undo
6606 6606
 						// Strips the url and store it into a temp for further procss
6607 6607
 						$tmp_url = html_entity_decode($myUrl);
6608 6608
 
6609
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6609
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6610 6610
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6611 6611
 						{
6612 6612
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6613
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6613
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6614 6614
 							$mail_bo->closeConnection();
6615 6615
 							if ($attachment)
6616 6616
 							{
@@ -6621,32 +6621,32 @@  discard block
 block discarded – undo
6621 6621
 						}
6622 6622
 					}
6623 6623
 
6624
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6625
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6624
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6625
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6626 6626
 				}
6627
-				if (substr($url,0,strlen('data:'))=='data:')
6627
+				if (substr($url, 0, strlen('data:')) == 'data:')
6628 6628
 				{
6629 6629
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6630 6630
 					// we only support base64 encoded data
6631
-					$tmp = substr($url,strlen('data:'));
6632
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6631
+					$tmp = substr($url, strlen('data:'));
6632
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6633 6633
 					$data = base64_decode($data_base64);
6634 6634
 					// FF currently does NOT add any mime-type
6635 6635
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6636 6636
 					{
6637 6637
 						$mimeType = MimeMagic::analyze_data($data);
6638 6638
 					}
6639
-					list($what,$exactly) = explode('/',$mimeType);
6639
+					list($what, $exactly) = explode('/', $mimeType);
6640 6640
 					$needTempFile = true;
6641
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6641
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6642 6642
 				}
6643 6643
 				if ($data || $needTempFile === false)
6644 6644
 				{
6645 6645
 					if ($needTempFile)
6646 6646
 					{
6647
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6648
-						$tmpfile = fopen($attachment_file,'w');
6649
-						fwrite($tmpfile,$data);
6647
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6648
+						$tmpfile = fopen($attachment_file, 'w');
6649
+						fwrite($tmpfile, $data);
6650 6650
 						fclose($tmpfile);
6651 6651
 					}
6652 6652
 					else
@@ -6657,7 +6657,7 @@  discard block
 block discarded – undo
6657 6657
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6658 6658
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6659 6659
 					// on upload. filename itself is not sufficient to determine the sameness of images
6660
-					$cid = 'cid:' . md5($attachment_file);
6660
+					$cid = 'cid:'.md5($attachment_file);
6661 6661
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), urldecode($filename), $mimeType) !== null)
6662 6662
 					{
6663 6663
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6679,10 +6679,10 @@  discard block
 block discarded – undo
6679 6679
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6680 6680
 	 * @return mixed array of messages with success and failed messages or exception
6681 6681
 	 */
6682
-	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6682
+	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6683 6683
 	{
6684 6684
 		$importfailed = false;
6685
-		$processStats = array('success'=>array(),'failed'=>array());
6685
+		$processStats = array('success'=>array(), 'failed'=>array());
6686 6686
 		if (empty($SendAndMergeTocontacts))
6687 6687
 		{
6688 6688
 			$importfailed = true;
@@ -6723,7 +6723,7 @@  discard block
 block discarded – undo
6723 6723
 				$_folder = $this->getSentFolder();
6724 6724
 			}
6725 6725
 			$delimiter = $this->getHierarchyDelimiter();
6726
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6726
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6727 6727
 			if ($importfailed === false)
6728 6728
 			{
6729 6729
 				$Subject = $mailObject->getHeader('Subject');
@@ -6741,9 +6741,9 @@  discard block
 block discarded – undo
6741 6741
 				{
6742 6742
 					$mailObject->clearReplyTos();
6743 6743
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6744
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6744
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6745 6745
 
6746
-					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']),Mail::generateIdentityString($activeMailProfile,false));
6746
+					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']), Mail::generateIdentityString($activeMailProfile, false));
6747 6747
 				}
6748 6748
 				foreach ($SendAndMergeTocontacts as $k => $val)
6749 6749
 				{
@@ -6757,12 +6757,12 @@  discard block
 block discarded – undo
6757 6757
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6758 6758
 
6759 6759
 						// Parse destinations for placeholders
6760
-						foreach(Mailer::$type2header as $type => $h)
6760
+						foreach (Mailer::$type2header as $type => $h)
6761 6761
 						{
6762 6762
 							//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));
6763
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6764
-							$mailObject->addAddress($merged,'',$type);
6765
-							if($type == 'to')
6763
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6764
+							$mailObject->addAddress($merged, '', $type);
6765
+							if ($type == 'to')
6766 6766
 							{
6767 6767
 								$email = $merged;
6768 6768
 							}
@@ -6775,26 +6775,26 @@  discard block
 block discarded – undo
6775 6775
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6776 6776
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6777 6777
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6778
-							if($email)
6778
+							if ($email)
6779 6779
 							{
6780 6780
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6781 6781
 							}
6782 6782
 						}
6783 6783
 
6784 6784
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6785
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6785
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6786 6786
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6787 6787
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6788
-							self::generateIdentityString($activeMailProfile,false));
6788
+							self::generateIdentityString($activeMailProfile, false));
6789 6789
 
6790 6790
 						$mailObject->removeHeader('Message-ID');
6791 6791
 						$mailObject->removeHeader('Date');
6792 6792
 						$mailObject->clearCustomHeaders();
6793 6793
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6794 6794
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6795
-						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));
6795
+						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));
6796 6796
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6797
-						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));
6797
+						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));
6798 6798
 
6799 6799
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6800 6800
 						// set a higher timeout for big messages
@@ -6803,7 +6803,7 @@  discard block
 block discarded – undo
6803 6803
 						try {
6804 6804
 							$mailObject->send();
6805 6805
 						}
6806
-						catch(Exception $e) {
6806
+						catch (Exception $e) {
6807 6807
 							$sendOK = false;
6808 6808
 							$errorInfo = $e->getMessage();
6809 6809
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6817,41 +6817,41 @@  discard block
 block discarded – undo
6817 6817
 						$mailObject->clearCustomHeaders();
6818 6818
 
6819 6819
 						// Parse destinations for placeholders
6820
-						foreach(Mailer::$type2header as $type => $h)
6820
+						foreach (Mailer::$type2header as $type => $h)
6821 6821
 						{
6822
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6822
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6823 6823
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6824
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6824
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6825 6825
 						}
6826 6826
 
6827 6827
 						// No addresses from placeholders?  Treat it as just a contact ID
6828
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6828
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6829 6829
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6830 6830
 						{
6831 6831
 							$contact = $bo_merge->contacts->read($val);
6832 6832
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6833 6833
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6834 6834
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6835
-							if($email)
6835
+							if ($email)
6836 6836
 							{
6837 6837
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6838 6838
 							}
6839 6839
 						}
6840 6840
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6841 6841
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6842
-						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));
6842
+						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));
6843 6843
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6844
-						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));
6844
+						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));
6845 6845
 						$_folder = $this->getDraftFolder();
6846 6846
 					}
6847 6847
 					if ($sendOK || $openAsDraft)
6848 6848
 					{
6849
-						if ($this->folderExists($_folder,true))
6849
+						if ($this->folderExists($_folder, true))
6850 6850
 						{
6851
-						    if($this->isSentFolder($_folder))
6851
+						    if ($this->isSentFolder($_folder))
6852 6852
 							{
6853 6853
 						        $flags = '\\Seen';
6854
-						    } elseif($this->isDraftFolder($_folder)) {
6854
+						    } elseif ($this->isDraftFolder($_folder)) {
6855 6855
 						        $flags = '\\Draft';
6856 6856
 						    } else {
6857 6857
 						        $flags = '';
@@ -6859,7 +6859,7 @@  discard block
 block discarded – undo
6859 6859
 							$savefailed = false;
6860 6860
 							try
6861 6861
 							{
6862
-								$messageUid =$this->appendMessage($_folder,
6862
+								$messageUid = $this->appendMessage($_folder,
6863 6863
 									$mailObject->getRaw(),
6864 6864
 									null,
6865 6865
 									$flags);
@@ -6867,10 +6867,10 @@  discard block
 block discarded – undo
6867 6867
 							catch (\Exception\WrongUserinput $e)
6868 6868
 							{
6869 6869
 								$savefailed = true;
6870
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6870
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6871 6871
 							}
6872 6872
 							// no send, save successful, and message_uid present
6873
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6873
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6874 6874
 							{
6875 6875
 								$importID = $messageUid;
6876 6876
 								$openComposeWindow = true;
@@ -6879,20 +6879,20 @@  discard block
 block discarded – undo
6879 6879
 						else
6880 6880
 						{
6881 6881
 							$savefailed = true;
6882
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6882
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6883 6883
 						}
6884 6884
 						if ($sendOK)
6885 6885
 						{
6886
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6886
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6887 6887
 						}
6888 6888
 						else
6889 6889
 						{
6890
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6890
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6891 6891
 						}
6892 6892
 					}
6893
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6893
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6894 6894
 					{
6895
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6895
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6896 6896
 					}
6897 6897
 				}
6898 6898
 			}
@@ -6962,19 +6962,18 @@  discard block
 block discarded – undo
6962 6962
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
6963 6963
 
6964 6964
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
6965
-			$start = is_string($message) ? substr($message, 0, 8192) :
6966
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6965
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6967 6966
 
6968 6967
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6969
-			if ($length===false) $length = strlen($start);
6970
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6968
+			if ($length === false) $length = strlen($start);
6969
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
6971 6970
 
6972
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
6971
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
6973 6972
 			{
6974
-				foreach((array)$value as $n => $val)
6973
+				foreach ((array)$value as $n => $val)
6975 6974
 				{
6976 6975
 					$overwrite = !$n;
6977
-					switch($header)
6976
+					switch ($header)
6978 6977
 					{
6979 6978
 						case 'Content-Transfer-Encoding':
6980 6979
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -6995,7 +6994,7 @@  discard block
 block discarded – undo
6995 6994
 		}
6996 6995
 		else
6997 6996
 		{
6998
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
6997
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
6999 6998
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
7000 6999
 		}
7001 7000
 	}
@@ -7009,50 +7008,50 @@  discard block
 block discarded – undo
7009 7008
 	 * @param string $default_domain
7010 7009
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
7011 7010
 	 */
7012
-	public static function parseAddressList($addresses, $default_domain=null)
7011
+	public static function parseAddressList($addresses, $default_domain = null)
7013 7012
 	{
7014 7013
 		$rfc822 = new Horde_Mail_Rfc822();
7015 7014
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
7016 7015
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
7017
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
7016
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
7018 7017
 		{
7019 7018
 			$matches = array();
7020
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
7019
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
7021 7020
 			//error_log(__METHOD__.__LINE__.array2string($matches));
7022
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
7023
-			$addresses = implode(',',$matches[0]);
7021
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
7022
+			$addresses = implode(',', $matches[0]);
7024 7023
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
7025 7024
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
7026 7025
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
7027 7026
 		}
7028
-		$previousFailed=false;
7027
+		$previousFailed = false;
7029 7028
 		$ret2 = new Horde_Mail_Rfc822_List();
7030 7029
 		// handle known problems on emailaddresses
7031
-		foreach($ret as $i => $adr)
7030
+		foreach ($ret as $i => $adr)
7032 7031
 		{
7033 7032
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
7034
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
7035
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
7033
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
7034
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
7036 7035
 			{
7037
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
7038
-				$adr->host = str_replace("'","",$adr->host);
7036
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
7037
+				$adr->host = str_replace("'", "", $adr->host);
7039 7038
 			}
7040 7039
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
7041 7040
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
7042 7041
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
7043 7042
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
7044 7043
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
7045
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
7044
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
7046 7045
 			{
7047
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
7048
-				$previousFailed=true;
7046
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
7047
+				$previousFailed = true;
7049 7048
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
7050 7049
 			}
7051 7050
 			else
7052 7051
 			{
7053
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
7052
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
7054 7053
 				$remember = '';
7055
-				$previousFailed=false;
7054
+				$previousFailed = false;
7056 7055
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
7057 7056
 				$ret2->add($adr);
7058 7057
 			}
@@ -7068,7 +7067,7 @@  discard block
 block discarded – undo
7068 7067
 	 * @param string $_folder
7069 7068
 	 * @return boolean
7070 7069
 	 */
7071
-	function sendMDN($uid,$_folder)
7070
+	function sendMDN($uid, $_folder)
7072 7071
 	{
7073 7072
 		$acc = Mail\Account::read($this->profileID);
7074 7073
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
@@ -7098,7 +7097,7 @@  discard block
 block discarded – undo
7098 7097
 	 */
7099 7098
 	function addAccount($_hookValues)
7100 7099
 	{
7101
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7100
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7102 7101
 
7103 7102
 	}
7104 7103
 
@@ -7112,7 +7111,7 @@  discard block
 block discarded – undo
7112 7111
 	 */
7113 7112
 	function deleteAccount($_hookValues)
7114 7113
 	{
7115
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7114
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7116 7115
 
7117 7116
 	}
7118 7117
 
@@ -7126,7 +7125,7 @@  discard block
 block discarded – undo
7126 7125
 	 */
7127 7126
 	function updateAccount($_hookValues)
7128 7127
 	{
7129
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7128
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7130 7129
 
7131 7130
 	}
7132 7131
 }
Please login to merge, or discard this patch.
Braces   +1814 added lines, -541 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
@@ -1313,13 +1485,19 @@  discard block
 block discarded – undo
1313 1485
 				}
1314 1486
 				catch (\Exception $ee)
1315 1487
 				{
1316
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1488
+					if (self::$debug)
1489
+					{
1490
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1491
+					}
1317 1492
 				}
1318 1493
 			}
1319 1494
 		}
1320 1495
 		catch (\Exception $e)
1321 1496
 		{
1322
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1497
+			if (self::$debug)
1498
+			{
1499
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1500
+			}
1323 1501
 		}
1324 1502
 
1325 1503
 		return $retValue;
@@ -1344,8 +1522,14 @@  discard block
 block discarded – undo
1344 1522
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1345 1523
 	{
1346 1524
 		//self::$debug=true;
1347
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1348
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1525
+		if (self::$debug)
1526
+		{
1527
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1528
+		}
1529
+		if (self::$debug)
1530
+		{
1531
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1532
+		}
1349 1533
 		$reverse = (bool)$_reverse;
1350 1534
 		// get the list of messages to fetch
1351 1535
 		$this->reopen($_folderName);
@@ -1366,21 +1550,34 @@  discard block
 block discarded – undo
1366 1550
 				//$_filter['range'] ="$start:$end";
1367 1551
 				//$_filter['range'] ="$_startMessage:*";
1368 1552
 			}
1369
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1370
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1553
+			if (self::$debug)
1554
+			{
1555
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1556
+			}
1557
+			if (self::$debug||self::$debugTimes)
1558
+			{
1559
+				$starttime = microtime (true);
1560
+			}
1371 1561
 			//see this example below for a 12 week datefilter (since)
1372 1562
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1373 1563
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1374 1564
 			$sortResult = $_sortResult['match']->ids;
1375 1565
 			//$modseq = $_sortResult['modseq'];
1376 1566
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1377
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1567
+			if (self::$debug||self::$debugTimes)
1568
+			{
1569
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1570
+			}
1378 1571
 
1379
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1572
+			if (self::$debug)
1573
+			{
1574
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1575
+			}
1380 1576
 			#$this->icServer->setDebug(false);
1381 1577
 			#print "</pre>";
1382 1578
 			// nothing found
1383
-			if(!is_array($sortResult) || empty($sortResult)) {
1579
+			if(!is_array($sortResult) || empty($sortResult))
1580
+			{
1384 1581
 				$retValue = array();
1385 1582
 				$retValue['info']['total']	= 0;
1386 1583
 				$retValue['info']['first']	= 0;
@@ -1392,7 +1589,8 @@  discard block
 block discarded – undo
1392 1589
 			#_debug_array($sortResult);
1393 1590
 			#_debug_array(array_slice($sortResult, -5, -2));
1394 1591
 			//error_log("REVERSE: $reverse");
1395
-			if($reverse === true) {
1592
+			if($reverse === true)
1593
+			{
1396 1594
 				if  ($_startMessage<=$total)
1397 1595
 				{
1398 1596
 					$startMessage = $_startMessage-1;
@@ -1404,7 +1602,10 @@  discard block
 block discarded – undo
1404 1602
 					{
1405 1603
 						$numberOfMessages = $total%$_numberOfMessages;
1406 1604
 						//$numberOfMessages = abs($_startMessage-$total-1);
1407
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1605
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1606
+						{
1607
+							$_numberOfMessages = $numberOfMessages;
1608
+						}
1408 1609
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1409 1610
 					}
1410 1611
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1418,19 +1619,36 @@  discard block
 block discarded – undo
1418 1619
 					//$retValue['info']['first'] = $startMessage;
1419 1620
 					//$retValue['info']['last'] = $total;
1420 1621
 				}
1421
-				if($startMessage > 0) {
1422
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1622
+				if($startMessage > 0)
1623
+				{
1624
+					if (self::$debug)
1625
+					{
1626
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1627
+					}
1423 1628
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1424
-				} else {
1425
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1629
+				}
1630
+				else
1631
+				{
1632
+					if (self::$debug)
1633
+					{
1634
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1635
+					}
1426 1636
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1427 1637
 				}
1428 1638
 				$sortResult = array_reverse($sortResult);
1429
-			} else {
1430
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1639
+			}
1640
+			else
1641
+			{
1642
+				if (self::$debug)
1643
+				{
1644
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1645
+				}
1431 1646
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1432 1647
 			}
1433
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1648
+			if (self::$debug)
1649
+			{
1650
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1651
+			}
1434 1652
 		}
1435 1653
 		else
1436 1654
 		{
@@ -1439,7 +1657,10 @@  discard block
 block discarded – undo
1439 1657
 
1440 1658
 
1441 1659
 		// fetch the data for the selected messages
1442
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1660
+		if (self::$debug||self::$debugTimes)
1661
+		{
1662
+			$starttime = microtime(true);
1663
+		}
1443 1664
 		try
1444 1665
 		{
1445 1666
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1463,7 +1684,10 @@  discard block
 block discarded – undo
1463 1684
 			$fquery->flags();
1464 1685
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1465 1686
 			// if $_fetchPreviews is activated fetch part of the messages too
1466
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1687
+			if ($_fetchPreviews)
1688
+			{
1689
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1690
+			}
1467 1691
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1468 1692
 				'ids' => $uidsToFetch,
1469 1693
 			));
@@ -1486,14 +1710,20 @@  discard block
 block discarded – undo
1486 1710
 
1487 1711
 		$cnt = 0;
1488 1712
 
1489
-		foreach((array)$sortResult as $uid) {
1713
+		foreach((array)$sortResult as $uid)
1714
+		{
1490 1715
 			$sortOrder[$uid] = $cnt++;
1491 1716
 		}
1492 1717
 
1493 1718
 		$count = 0;
1494
-		if (is_object($headersNew)) {
1495
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1496
-			foreach($headersNew->ids() as $id) {
1719
+		if (is_object($headersNew))
1720
+		{
1721
+			if (self::$debug||self::$debugTimes)
1722
+			{
1723
+				$starttime = microtime(true);
1724
+			}
1725
+			foreach($headersNew->ids() as $id)
1726
+			{
1497 1727
 				$_headerObject = $headersNew->get($id);
1498 1728
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1499 1729
 				$headerObject = array();
@@ -1506,7 +1736,10 @@  discard block
 block discarded – undo
1506 1736
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1507 1737
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1508 1738
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1509
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1739
+				if (empty($headerForPrio))
1740
+				{
1741
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1742
+				}
1510 1743
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1511 1744
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1512 1745
 				if ($_fetchPreviews)
@@ -1517,12 +1750,16 @@  discard block
 block discarded – undo
1517 1750
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1518 1751
 					{
1519 1752
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1520
-						if ($length===false) $length = strlen($bodyPreview);
1753
+						if ($length===false)
1754
+						{
1755
+							$length = strlen($bodyPreview);
1756
+						}
1521 1757
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1522 1758
 					}
1523 1759
 				}
1524 1760
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1525
-				if (self::$debug) {
1761
+				if (self::$debug)
1762
+				{
1526 1763
 					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'));
1527 1764
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1528 1765
 				}
@@ -1532,11 +1769,16 @@  discard block
 block discarded – undo
1532 1769
 					$total--;
1533 1770
 					continue;
1534 1771
 				}
1535
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1772
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1773
+				{
1536 1774
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1537
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1775
+				}
1776
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1777
+				{
1538 1778
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1539
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1779
+				}
1780
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1781
+				{
1540 1782
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1541 1783
 				} /*else $sent_not = "";*/
1542 1784
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1567,7 +1809,11 @@  discard block
 block discarded – undo
1567 1809
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1568 1810
 						foreach ($rfcAddr as $_rfcAddr)
1569 1811
 						{
1570
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1812
+							if (!$_rfcAddr->valid)
1813
+							{
1814
+								continue;
1815
+							}
1816
+							// skip. not a valid address
1571 1817
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1572 1818
 						}
1573 1819
 					}
@@ -1583,7 +1829,10 @@  discard block
 block discarded – undo
1583 1829
 				{
1584 1830
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1585 1831
 					// needed to parse the Headers of the Message
1586
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1832
+					if (empty($bodyPreview))
1833
+					{
1834
+						$bodyPreview = $_headerObject->getFullMsg();
1835
+					}
1587 1836
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1588 1837
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1589 1838
 					foreach($base->partIterator() as $part)
@@ -1596,7 +1845,8 @@  discard block
 block discarded – undo
1596 1845
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1597 1846
 											)), $charset, 'utf-8');
1598 1847
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1599
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1848
+						}
1849
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1600 1850
 						{
1601 1851
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1602 1852
 						}
@@ -1612,7 +1862,10 @@  discard block
 block discarded – undo
1612 1862
 				$messageMimeType='';
1613 1863
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1614 1864
 				{
1615
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1865
+					if ($mime_id==0 || $messageMimeType==='')
1866
+					{
1867
+						$messageMimeType = $mime_type;
1868
+					}
1616 1869
 					$part = $mailStructureObject->getPart($mime_id);
1617 1870
 					$partdisposition = $part->getDisposition();
1618 1871
 					$partPrimaryType = $part->getPrimaryType();
@@ -1622,7 +1875,8 @@  discard block
 block discarded – undo
1622 1875
 					// bodypreview could be found (multipart/....)
1623 1876
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1624 1877
 						((intval($mime_id) === 1) || !$mime_id) &&
1625
-						($partdisposition !== 'attachment')) {
1878
+						($partdisposition !== 'attachment'))
1879
+					{
1626 1880
 							$_structure=$part;
1627 1881
 							$this->fetchPartContents($uid, $_structure, false,true);
1628 1882
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1644,10 +1898,19 @@  discard block
 block discarded – undo
1644 1898
 					if ($mime_type=='message/rfc822')
1645 1899
 					{
1646 1900
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1647
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1901
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1902
+						{
1903
+if ($sub_id != $mime_id)
1904
+						{
1905
+							$skipParts[$sub_id] = $sub_type;
1906
+						}
1907
+						}
1648 1908
 					}
1649 1909
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1650
-					if (array_key_exists($mime_id,$skipParts)) continue;
1910
+					if (array_key_exists($mime_id,$skipParts))
1911
+					{
1912
+						continue;
1913
+					}
1651 1914
 					if ($partdisposition=='attachment' ||
1652 1915
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1653 1916
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1658,7 +1921,10 @@  discard block
 block discarded – undo
1658 1921
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1659 1922
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1660 1923
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1661
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1924
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1925
+						{
1926
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1927
+						}
1662 1928
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1663 1929
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1664 1930
 						{
@@ -1672,18 +1938,27 @@  discard block
 block discarded – undo
1672 1938
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1673 1939
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1674 1940
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1675
-				if (empty($headerObject['UID'])) continue;
1941
+				if (empty($headerObject['UID']))
1942
+				{
1943
+					continue;
1944
+				}
1676 1945
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1677 1946
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1678
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1947
+				if(substr($headerObject['DATE'],-2) === 'UT')
1948
+				{
1679 1949
 					$headerObject['DATE'] .= 'C';
1680 1950
 				}
1681
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1951
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1952
+				{
1682 1953
 					$headerObject['INTERNALDATE'] .= 'C';
1683 1954
 				}
1684 1955
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1685 1956
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1686
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1957
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1958
+				{
1959
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1960
+				}
1961
+				}
1687 1962
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1688 1963
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1689 1964
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1694,22 +1969,31 @@  discard block
 block discarded – undo
1694 1969
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1695 1970
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1696 1971
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1697
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1698
-				if (is_array($headerObject['FLAGS'])) {
1972
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1973
+				{
1974
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1975
+				}
1976
+				if (is_array($headerObject['FLAGS']))
1977
+				{
1699 1978
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1700 1979
 				}
1701 1980
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1702
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1981
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1982
+				{
1703 1983
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1704 1984
 				}
1705
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1985
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1986
+				{
1706 1987
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1707 1988
 					if (count($headerObject['TO'])>1)
1708 1989
 					{
1709 1990
 						$ki=0;
1710 1991
 						foreach($headerObject['TO'] as $k => $add)
1711 1992
 						{
1712
-							if ($k==0) continue;
1993
+							if ($k==0)
1994
+							{
1995
+								continue;
1996
+							}
1713 1997
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1714 1998
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1715 1999
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1717,7 +2001,8 @@  discard block
 block discarded – undo
1717 2001
 						}
1718 2002
 					}
1719 2003
 				}
1720
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
2004
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
2005
+				{
1721 2006
 					$ki=0;
1722 2007
 					foreach($headerObject['CC'] as $k => $add)
1723 2008
 					{
@@ -1731,27 +2016,41 @@  discard block
 block discarded – undo
1731 2016
 
1732 2017
 				$count++;
1733 2018
 			}
1734
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2019
+			if (self::$debug||self::$debugTimes)
2020
+			{
2021
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2022
+			}
1735 2023
 			//self::$debug=false;
1736 2024
 			// sort the messages to the requested displayorder
1737
-			if(is_array($retValue['header'])) {
2025
+			if(is_array($retValue['header']))
2026
+			{
1738 2027
 				$countMessages = $total;
1739
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2028
+				if (isset($_filter['range']))
2029
+				{
2030
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2031
+				}
1740 2032
 				ksort($retValue['header']);
1741 2033
 				$retValue['info']['total']	= $total;
1742 2034
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1743 2035
 				$retValue['info']['first']	= $_startMessage;
1744 2036
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1745 2037
 				return $retValue;
1746
-			} else {
2038
+			}
2039
+			else
2040
+			{
1747 2041
 				$retValue = array();
1748 2042
 				$retValue['info']['total']	= 0;
1749 2043
 				$retValue['info']['first']	= 0;
1750 2044
 				$retValue['info']['last']	= 0;
1751 2045
 				return $retValue;
1752 2046
 			}
1753
-		} else {
1754
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2047
+		}
2048
+		else
2049
+		{
2050
+			if ($headersNew == null && empty($_thisUIDOnly))
2051
+			{
2052
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2053
+			}
1755 2054
 			$retValue = array();
1756 2055
 			$retValue['info']['total']  = 0;
1757 2056
 			$retValue['info']['first']  = 0;
@@ -1768,7 +2067,10 @@  discard block
 block discarded – undo
1768 2067
 	 */
1769 2068
 	static function prepareFlagsArray($headerObject)
1770 2069
 	{
1771
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2070
+		if (is_array($headerObject['FLAGS']))
2071
+		{
2072
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2073
+		}
1772 2074
 		$retValue = array();
1773 2075
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1774 2076
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1819,26 +2121,45 @@  discard block
 block discarded – undo
1819 2121
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1820 2122
 		$try2useCache = true;
1821 2123
 		static $eMailListContainsDeletedMessages = null;
1822
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2124
+		if (is_null($eMailListContainsDeletedMessages))
2125
+		{
2126
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2127
+		}
1823 2128
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1824 2129
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1825 2130
 		{
1826
-			if (self::$debugTimes) $starttime = microtime(true);
1827
-			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);
2131
+			if (self::$debugTimes)
2132
+			{
2133
+				$starttime = microtime(true);
2134
+			}
2135
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2136
+			{
2137
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2138
+			}
1828 2139
 			$five=true;
1829 2140
 			$dReverse=1;
1830 2141
 			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false);
1831
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2142
+			if (self::$debug)
2143
+			{
2144
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2145
+			}
1832 2146
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1833 2147
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1834
-			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']);
2148
+			if (self::$debugTimes)
2149
+			{
2150
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2151
+			}
2152
+			//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']);
1835 2153
 		}
1836 2154
 		$try2useCache = false;
1837 2155
 		//self::$supportsORinQuery[$this->profileID]=true;
1838 2156
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1839 2157
 		{
1840 2158
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1841
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2159
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2160
+			{
2161
+				self::$supportsORinQuery[$this->profileID]=true;
2162
+			}
1842 2163
 		}
1843 2164
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1844 2165
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1849,15 +2170,26 @@  discard block
 block discarded – undo
1849 2170
 		}
1850 2171
 		//_debug_array($filter);
1851 2172
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1852
-		if($this->icServer->hasCapability('SORT')) {
2173
+		if($this->icServer->hasCapability('SORT'))
2174
+		{
1853 2175
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1854 2176
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1855 2177
 			// there is no messing with the dates)
1856 2178
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1857
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2179
+			if (self::$debug)
2180
+			{
2181
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2182
+			}
1858 2183
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1859
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1860
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2184
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2185
+			{
2186
+				$_reverse=false;
2187
+			}
2188
+			// as we reversed the result already
2189
+			if (self::$debug)
2190
+			{
2191
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2192
+			}
1861 2193
 			try
1862 2194
 			{
1863 2195
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1869,7 +2201,10 @@  discard block
 block discarded – undo
1869 2201
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1870 2202
 				$resultByUid = false;
1871 2203
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1872
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2204
+				if ($_reverse)
2205
+				{
2206
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2207
+				}
1873 2208
 				try
1874 2209
 				{
1875 2210
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1881,9 +2216,17 @@  discard block
 block discarded – undo
1881 2216
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1882 2217
 				}
1883 2218
 			}
1884
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1885
-		} else {
1886
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2219
+			if (self::$debug)
2220
+			{
2221
+				error_log(__METHOD__.print_r($sortResult,true));
2222
+			}
2223
+		}
2224
+		else
2225
+		{
2226
+			if (self::$debug)
2227
+			{
2228
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2229
+			}
1887 2230
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1888 2231
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1889 2232
 			try
@@ -1897,7 +2240,10 @@  discard block
 block discarded – undo
1897 2240
 				// possible error OR Query. But Horde gives no detailed Info :-(
1898 2241
 				self::$supportsORinQuery[$this->profileID]=false;
1899 2242
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1900
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2243
+				if (self::$debug)
2244
+				{
2245
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2246
+				}
1901 2247
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1902 2248
 				try
1903 2249
 				{
@@ -1908,11 +2254,15 @@  discard block
 block discarded – undo
1908 2254
 				{
1909 2255
 				}
1910 2256
 			}
1911
-			if(is_array($sortResult['match'])) {
2257
+			if(is_array($sortResult['match']))
2258
+			{
1912 2259
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1913 2260
 					sort($sortResult['match'], SORT_NUMERIC);
1914 2261
 			}
1915
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2262
+			if (self::$debug)
2263
+			{
2264
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2265
+			}
1916 2266
 		}
1917 2267
 		if ($setSession)
1918 2268
 		{
@@ -1941,7 +2291,8 @@  discard block
 block discarded – undo
1941 2291
 		$_reverse=false;
1942 2292
 		if (is_numeric($_sort))
1943 2293
 		{
1944
-			switch($_sort) {
2294
+			switch($_sort)
2295
+			{
1945 2296
 				case 2:
1946 2297
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1947 2298
 					break;
@@ -1963,7 +2314,8 @@  discard block
 block discarded – undo
1963 2314
 		}
1964 2315
 		else
1965 2316
 		{
1966
-			switch(strtoupper($_sort)) {
2317
+			switch(strtoupper($_sort))
2318
+			{
1967 2319
 				case 'FROMADDRESS':
1968 2320
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1969 2321
 					break;
@@ -1989,7 +2341,10 @@  discard block
 block discarded – undo
1989 2341
 					break;
1990 2342
 			}
1991 2343
 		}
1992
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2344
+		if ($_reverse)
2345
+		{
2346
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2347
+		}
1993 2348
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1994 2349
 		return $retValue;
1995 2350
 	}
@@ -2008,7 +2363,10 @@  discard block
 block discarded – undo
2008 2363
 		$imapFilter->charset('UTF-8');
2009 2364
 
2010 2365
 		//_debug_array($_criterias);
2011
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2366
+		if (self::$debug)
2367
+		{
2368
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2369
+		}
2012 2370
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2013 2371
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2014 2372
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -2023,11 +2381,13 @@  discard block
 block discarded – undo
2023 2381
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2024 2382
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2025 2383
 		$statusQueryValid = false;
2026
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2384
+		foreach((array)$_criterias['status'] as $k => $criteria)
2385
+		{
2027 2386
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2028 2387
 			$imapStatusFilter->charset('UTF-8');
2029 2388
 			$criteria = strtoupper($criteria);
2030
-			switch ($criteria) {
2389
+			switch ($criteria)
2390
+			{
2031 2391
 				case 'ANSWERED':
2032 2392
 				case 'DELETED':
2033 2393
 				case 'FLAGGED':
@@ -2110,9 +2470,11 @@  discard block
 block discarded – undo
2110 2470
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2111 2471
 		$imapSearchFilter->charset('UTF-8');
2112 2472
 
2113
-		if(!empty($_criterias['string'])) {
2473
+		if(!empty($_criterias['string']))
2474
+		{
2114 2475
 			$criteria = strtoupper($_criterias['type']);
2115
-			switch ($criteria) {
2476
+			switch ($criteria)
2477
+			{
2116 2478
 				case 'BYDATE':
2117 2479
 				case 'QUICK':
2118 2480
 				case 'QUICKWITHCC':
@@ -2120,9 +2482,12 @@  discard block
 block discarded – undo
2120 2482
 					//$imapSearchFilter->charset('UTF-8');
2121 2483
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2122 2484
 					$imapFilter2->charset('UTF-8');
2123
-					if($this->isSentFolder($_folder)) {
2485
+					if($this->isSentFolder($_folder))
2486
+					{
2124 2487
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2125
-					} else {
2488
+					}
2489
+					else
2490
+					{
2126 2491
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2127 2492
 					}
2128 2493
 					if ($_supportsOrInQuery)
@@ -2153,7 +2518,10 @@  discard block
 block discarded – undo
2153 2518
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2154 2519
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2155 2520
 						$numberinBytes=(float)$_criterias['string'];
2156
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2521
+						if (isset($multipleBy[$unit]))
2522
+						{
2523
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2524
+						}
2157 2525
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2158 2526
 						$_criterias['string']=$numberinBytes;
2159 2527
 					}
@@ -2190,8 +2558,14 @@  discard block
 block discarded – undo
2190 2558
 					break;
2191 2559
 			}
2192 2560
 		}
2193
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2194
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2561
+		if ($statusQueryValid && !$queryValid)
2562
+		{
2563
+			$queryValid=true;
2564
+		}
2565
+		if ($queryValid)
2566
+		{
2567
+			$imapFilter->andSearch($imapSearchFilter);
2568
+		}
2195 2569
 
2196 2570
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2197 2571
 		{
@@ -2206,7 +2580,8 @@  discard block
 block discarded – undo
2206 2580
 				unset($_criterias['before']);
2207 2581
 				$criteria=$_criterias['range']='ON';
2208 2582
 			}
2209
-			switch ($criteria) {
2583
+			switch ($criteria)
2584
+			{
2210 2585
 				case 'BETWEEN':
2211 2586
 					//try to be smart about missing
2212 2587
 					//enddate
@@ -2242,8 +2617,14 @@  discard block
 block discarded – undo
2242 2617
 					$rangeValid = true;
2243 2618
 					break;
2244 2619
 			}
2245
-			if ($rangeValid && !$queryValid) $queryValid=true;
2246
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2620
+			if ($rangeValid && !$queryValid)
2621
+			{
2622
+				$queryValid=true;
2623
+			}
2624
+			if ($rangeValid)
2625
+			{
2626
+				$imapFilter->andSearch($imapRangeFilter);
2627
+			}
2247 2628
 		}
2248 2629
 		if (self::$debug)
2249 2630
 		{
@@ -2251,10 +2632,13 @@  discard block
 block discarded – undo
2251 2632
 			$query_str = $imapFilter->build();
2252 2633
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2253 2634
 		}
2254
-		if($queryValid==false) {
2635
+		if($queryValid==false)
2636
+		{
2255 2637
 			$imapFilter->flag('DELETED', $set=false);
2256 2638
 			return $imapFilter;
2257
-		} else {
2639
+		}
2640
+		else
2641
+		{
2258 2642
 			return $imapFilter;
2259 2643
 		}
2260 2644
 	}
@@ -2311,7 +2695,10 @@  discard block
 block discarded – undo
2311 2695
 					}
2312 2696
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2313 2697
 				}
2314
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2698
+				if (!empty($stringA))
2699
+				{
2700
+					$_string = implode(',',$stringA);
2701
+				}
2315 2702
 			}
2316 2703
 			if ($_tryIDNConversion==='FORCE')
2317 2704
 			{
@@ -2336,7 +2723,10 @@  discard block
 block discarded – undo
2336 2723
 		{
2337 2724
 			return 'No Subject';
2338 2725
 		}
2339
-		if ($decode) $_string = self::decode_header($_string);
2726
+		if ($decode)
2727
+		{
2728
+			$_string = self::decode_header($_string);
2729
+		}
2340 2730
 		// make sure its utf-8
2341 2731
 		$test = @json_encode($_string);
2342 2732
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2374,7 +2764,8 @@  discard block
 block discarded – undo
2374 2764
 	 * @param string _parent the parent foldername
2375 2765
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2376 2766
 	 */
2377
-	function _encodeFolderName($_folderName) {
2767
+	function _encodeFolderName($_folderName)
2768
+	{
2378 2769
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2379 2770
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2380 2771
 	}
@@ -2390,21 +2781,36 @@  discard block
 block discarded – undo
2390 2781
 	 */
2391 2782
 	function createFolder($_parent, $_folderName, &$_error)
2392 2783
 	{
2393
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2784
+		if (self::$debug)
2785
+		{
2786
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2787
+		}
2394 2788
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2395 2789
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2396 2790
 
2397
-		if(empty($parent)) {
2791
+		if(empty($parent))
2792
+		{
2398 2793
 			$newFolderName = $folderName;
2399
-		} else {
2794
+		}
2795
+		else
2796
+		{
2400 2797
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2401 2798
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2402 2799
 		}
2403
-		if (empty($newFolderName)) return false;
2404
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2800
+		if (empty($newFolderName))
2801
+		{
2802
+			return false;
2803
+		}
2804
+		if (self::$debug)
2805
+		{
2806
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2807
+		}
2405 2808
 		if ($this->folderExists($newFolderName,true))
2406 2809
 		{
2407
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2810
+			if (self::$debug)
2811
+			{
2812
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2813
+			}
2408 2814
 			return $newFolderName;
2409 2815
 		}
2410 2816
 		try
@@ -2452,13 +2858,19 @@  discard block
 block discarded – undo
2452 2858
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2453 2859
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2454 2860
 
2455
-		if(empty($parent)) {
2861
+		if(empty($parent))
2862
+		{
2456 2863
 			$newFolderName = $folderName;
2457
-		} else {
2864
+		}
2865
+		else
2866
+		{
2458 2867
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2459 2868
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2460 2869
 		}
2461
-		if (self::$debug) error_log("create folder: $newFolderName");
2870
+		if (self::$debug)
2871
+		{
2872
+			error_log("create folder: $newFolderName");
2873
+		}
2462 2874
 		try
2463 2875
 		{
2464 2876
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2532,8 +2944,14 @@  discard block
 block discarded – undo
2532 2944
 	 */
2533 2945
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2534 2946
 	{
2535
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2536
-		if (self::$debugTimes) $starttime = microtime (true);
2947
+		if (self::$debug)
2948
+		{
2949
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2950
+		}
2951
+		if (self::$debugTimes)
2952
+		{
2953
+			$starttime = microtime (true);
2954
+		}
2537 2955
 		static $folders2return;
2538 2956
 		//$_subscribedOnly=false;
2539 2957
 		// always use static on single request if info is available;
@@ -2541,23 +2959,35 @@  discard block
 block discarded – undo
2541 2959
 		// set $_useCacheIfPossible to false !
2542 2960
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2543 2961
 		{
2544
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2962
+			if (self::$debugTimes)
2963
+			{
2964
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2965
+			}
2545 2966
 			return $folders2return[$this->icServer->ImapServerId];
2546 2967
 		}
2547 2968
 
2548 2969
 		if ($_subscribedOnly && $_getCounters===false)
2549 2970
 		{
2550
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2971
+			if (is_null($folders2return))
2972
+			{
2973
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2974
+			}
2551 2975
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2552 2976
 			{
2553 2977
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2554
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2978
+				if (self::$debugTimes)
2979
+				{
2980
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2981
+				}
2555 2982
 				return $folders2return[$this->icServer->ImapServerId];
2556 2983
 			}
2557 2984
 		}
2558 2985
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2559 2986
 		static $folderBasicInfo;
2560
-		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);
2987
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2988
+		{
2989
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2990
+		}
2561 2991
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2562 2992
 
2563 2993
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2570,7 +3000,8 @@  discard block
 block discarded – undo
2570 3000
 		$inboxData->shortFolderName	= 'INBOX';
2571 3001
 		$inboxData->shortDisplayName	= lang('INBOX');
2572 3002
 		$inboxData->subscribed = true;
2573
-		if($_getCounters == true) {
3003
+		if($_getCounters == true)
3004
+		{
2574 3005
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2575 3006
 		}
2576 3007
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2589,12 +3020,14 @@  discard block
 block discarded – undo
2589 3020
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2590 3021
 		if (is_array($nameSpace))
2591 3022
 		{
2592
-			foreach($nameSpace as $k => $singleNameSpace) {
3023
+			foreach($nameSpace as $k => $singleNameSpace)
3024
+			{
2593 3025
 				$type = $singleNameSpace['type'];
2594 3026
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2595 3027
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2596 3028
 
2597
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
3029
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
3030
+				{
2598 3031
 					// fetch and sort the subscribed folders
2599 3032
 					// we alway fetch the subscribed, as this provides the only way to tell
2600 3033
 					// if a folder is subscribed or not
@@ -2645,8 +3078,12 @@  discard block
 block discarded – undo
2645 3078
 							}
2646 3079
 						}
2647 3080
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2648
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2649
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3081
+						if (!is_array($foldersNameSpace[$type]['all']))
3082
+						{
3083
+							$foldersNameSpace[$type]['all'] = array();
3084
+						}
3085
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3086
+						{
2650 3087
 							continue;
2651 3088
 						}
2652 3089
 
@@ -2676,7 +3113,8 @@  discard block
 block discarded – undo
2676 3113
 					}
2677 3114
 
2678 3115
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2679
-					foreach ($allMailboxesExt as $mbx) {
3116
+					foreach ($allMailboxesExt as $mbx)
3117
+					{
2680 3118
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2681 3119
 						{
2682 3120
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2699,20 +3137,33 @@  discard block
 block discarded – undo
2699 3137
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2700 3138
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2701 3139
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2702
-						) continue;
3140
+						)
3141
+						{
3142
+							continue;
3143
+						}
2703 3144
 
2704 3145
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2705 3146
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2706 3147
 					}
2707
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3148
+					if (is_array($allMailBoxesExtSorted))
3149
+					{
3150
+						ksort($allMailBoxesExtSorted);
3151
+					}
2708 3152
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2709 3153
 					$allMailboxes = array();
2710
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2711
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3154
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3155
+					{
3156
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3157
+						{
3158
+							$allMailboxes[] = $mbx['MAILBOX'];
3159
+						}
2712 3160
 						//echo "Result:";_debug_array($allMailboxes);
2713 3161
 					}
2714 3162
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2715
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3163
+					if (is_array($foldersNameSpace[$type]['all']))
3164
+					{
3165
+						sort($foldersNameSpace[$type]['all']);
3166
+					}
2716 3167
 				}
2717 3168
 			}
2718 3169
 		}
@@ -2721,24 +3172,50 @@  discard block
 block discarded – undo
2721 3172
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2722 3173
 		$autoFolderObjects = $folders = array();
2723 3174
 		$autofolder_exists = array();
2724
-		foreach( array('personal', 'others', 'shared') as $type) {
2725
-			if(isset($foldersNameSpace[$type])) {
2726
-				if($_subscribedOnly) {
2727
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2728
-				} else {
2729
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2730
-				}
2731
-				foreach((array)$listOfFolders as $folderName) {
3175
+		foreach( array('personal', 'others', 'shared') as $type)
3176
+		{
3177
+			if(isset($foldersNameSpace[$type]))
3178
+			{
3179
+				if($_subscribedOnly)
3180
+				{
3181
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3182
+					{
3183
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3184
+					}
3185
+				}
3186
+				else
3187
+				{
3188
+					if( !empty($foldersNameSpace[$type]['all']))
3189
+					{
3190
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3191
+					}
3192
+				}
3193
+				foreach((array)$listOfFolders as $folderName)
3194
+				{
2732 3195
 					//echo "<br>FolderToCheck:$folderName<br>";
2733 3196
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2734
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2735
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3197
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3198
+					{
3199
+						continue;
3200
+					}
3201
+					//when subscribedonly, we fetch all folders in one go.
3202
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3203
+					{
2736 3204
 						#echo "$folderName failed to be here <br>";
2737 3205
 						continue;
2738 3206
 					}
2739
-					if (isset($folders[$folderName])) continue;
2740
-					if (isset($autoFolderObjects[$folderName])) continue;
2741
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3207
+					if (isset($folders[$folderName]))
3208
+					{
3209
+						continue;
3210
+					}
3211
+					if (isset($autoFolderObjects[$folderName]))
3212
+					{
3213
+						continue;
3214
+					}
3215
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3216
+					{
3217
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3218
+					}
2742 3219
 					$folderParts = explode($delimiter, $folderName);
2743 3220
 					$shortName = array_pop($folderParts);
2744 3221
 
@@ -2746,17 +3223,20 @@  discard block
 block discarded – undo
2746 3223
 					$folderObject->delimiter	= $delimiter;
2747 3224
 					$folderObject->folderName	= $folderName;
2748 3225
 					$folderObject->shortFolderName	= $shortName;
2749
-					if(!$_subscribedOnly) {
3226
+					if(!$_subscribedOnly)
3227
+					{
2750 3228
 						#echo $folderName."->".$type."<br>";
2751 3229
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2752 3230
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2753 3231
 					}
2754 3232
 
2755
-					if($_getCounters == true) {
3233
+					if($_getCounters == true)
3234
+					{
2756 3235
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2757 3236
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2758 3237
 					}
2759
-					if(strtoupper($folderName) == 'INBOX') {
3238
+					if(strtoupper($folderName) == 'INBOX')
3239
+					{
2760 3240
 						$folderName = 'INBOX';
2761 3241
 						$folderObject->folderName	= 'INBOX';
2762 3242
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2764,24 +3244,34 @@  discard block
 block discarded – undo
2764 3244
 						$folderObject->shortDisplayName = lang('INBOX');
2765 3245
 						$folderObject->subscribed	= true;
2766 3246
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2767
-					} elseif (in_array($shortName,self::$autoFolders)) {
3247
+					}
3248
+					elseif (in_array($shortName,self::$autoFolders))
3249
+					{
2768 3250
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2769 3251
 						array_pop($tmpfolderparts);
2770 3252
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2771 3253
 						$folderObject->shortDisplayName = lang($shortName);
2772 3254
 						unset($tmpfolderparts);
2773
-					} else {
3255
+					}
3256
+					else
3257
+					{
2774 3258
 						$folderObject->displayName = $folderObject->folderName;
2775 3259
 						$folderObject->shortDisplayName = $shortName;
2776 3260
 					}
2777 3261
 					//$folderName = $folderName;
2778
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3262
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3263
+					{
2779 3264
 						$autoFolderObjects[$folderName] = $folderObject;
2780
-					} else {
3265
+					}
3266
+					else
3267
+					{
2781 3268
 						$folders[$folderName] = $folderObject;
2782 3269
 					}
2783 3270
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2784
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3271
+					if (!isset(self::$specialUseFolders))
3272
+					{
3273
+						$this->getSpecialUseFolders ();
3274
+					}
2785 3275
 					if (isset(self::$specialUseFolders[$folderName]))
2786 3276
 					{
2787 3277
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2789,7 +3279,8 @@  discard block
 block discarded – undo
2789 3279
 				}
2790 3280
 			}
2791 3281
 		}
2792
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3282
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3283
+		{
2793 3284
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2794 3285
 		}
2795 3286
 		// check if some standard folders are missing and need to be created
@@ -2798,7 +3289,10 @@  discard block
 block discarded – undo
2798 3289
 			// if new folders have been created, re-read folders ignoring the cache
2799 3290
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2800 3291
 		}
2801
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3292
+		if (is_array($folders))
3293
+		{
3294
+			uasort($folders,array($this,"sortByDisplayName"));
3295
+		}
2802 3296
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2803 3297
 		//_debug_array($folders2return); #exit;
2804 3298
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2810,7 +3304,10 @@  discard block
 block discarded – undo
2810 3304
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2811 3305
 		}
2812 3306
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2813
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3307
+		if (self::$debugTimes)
3308
+		{
3309
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3310
+		}
2814 3311
 		return $folders2return[$this->icServer->ImapServerId];
2815 3312
 	}
2816 3313
 
@@ -2838,31 +3335,44 @@  discard block
 block discarded – undo
2838 3335
 
2839 3336
 		$folders = $nameSpace =  array();
2840 3337
 		$nameSpaceTmp = $this->_getNameSpaces();
2841
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3338
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3339
+		{
2842 3340
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2843 3341
 		}
2844 3342
 		unset($nameSpaceTmp);
2845 3343
 
2846 3344
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2847 3345
 		// Get special use folders
2848
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3346
+		if (!isset(self::$specialUseFolders))
3347
+		{
3348
+			$this->getSpecialUseFolders ();
3349
+		}
3350
+		// Set self::$specialUseFolders
2849 3351
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2850
-		if ($_onlyTopLevel) // top level leaves
3352
+		if ($_onlyTopLevel)
3353
+		{
3354
+			// top level leaves
2851 3355
 		{
2852 3356
 			// Get top mailboxes of icServer
2853 3357
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3358
+		}
2854 3359
 			// Trigger examination of namespace to retrieve
2855 3360
 			// folders located in other and shared; needed only for some servers
2856
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3361
+			if (is_null(self::$mailConfig))
3362
+			{
3363
+				self::$mailConfig = Config::read('mail');
3364
+			}
2857 3365
 			if (self::$mailConfig['examineNamespace'])
2858 3366
 			{
2859 3367
 				$prefixes=array();
2860 3368
 				if (is_array($nameSpace))
2861 3369
 				{
2862
-					foreach($nameSpace as $k => $singleNameSpace) {
3370
+					foreach($nameSpace as $k => $singleNameSpace)
3371
+					{
2863 3372
 						$type = $singleNameSpace['type'];
2864 3373
 
2865
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3374
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3375
+						{
2866 3376
 							$prefixes[$type] = $singleNameSpace['prefix'];
2867 3377
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2868 3378
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2938,7 +3448,10 @@  discard block
 block discarded – undo
2938 3448
 							$nFolders [$path] = $folder;
2939 3449
 						}
2940 3450
 					}
2941
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3451
+					if (is_array($aFolders))
3452
+					{
3453
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3454
+					}
2942 3455
 					//ksort($aFolders);
2943 3456
 
2944 3457
 					// Sort none auto folders base on mailbox name
@@ -2948,12 +3461,17 @@  discard block
 block discarded – undo
2948 3461
 				}
2949 3462
 				else
2950 3463
 				{
2951
-					if (is_array($subFolders)) ksort($subFolders);
3464
+					if (is_array($subFolders))
3465
+					{
3466
+						ksort($subFolders);
3467
+					}
2952 3468
 				}
2953 3469
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2954 3470
 			}
2955 3471
 		}
2956
-		elseif ($_nodePath) // single node
3472
+		elseif ($_nodePath)
3473
+		{
3474
+			// single node
2957 3475
 		{
2958 3476
 			switch ($_search)
2959 3477
 			{
@@ -2961,6 +3479,7 @@  discard block
 block discarded – undo
2961 3479
 				case 0:
2962 3480
 				case 2:
2963 3481
 					$path = $_nodePath.''.$delimiter;
3482
+		}
2964 3483
 					break;
2965 3484
 				// Node itself
2966 3485
 				// shouldn't contain next level delimiter
@@ -2979,11 +3498,14 @@  discard block
 block discarded – undo
2979 3498
 
2980 3499
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2981 3500
 		}
2982
-		elseif(!$_nodePath) // all
3501
+		elseif(!$_nodePath)
3502
+		{
3503
+			// all
2983 3504
 		{
2984 3505
 			if ($_subscribedOnly)
2985 3506
 			{
2986 3507
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3508
+		}
2987 3509
 			}
2988 3510
 			else
2989 3511
 			{
@@ -2995,7 +3517,10 @@  discard block
 block discarded – undo
2995 3517
 		{
2996 3518
 			// SORTING FOLDERS
2997 3519
 			//self::$debugTimes=true;
2998
-			if (self::$debugTimes) $starttime = microtime (true);
3520
+			if (self::$debugTimes)
3521
+			{
3522
+				$starttime = microtime (true);
3523
+			}
2999 3524
 			// Merge of all auto folders and specialusefolders
3000 3525
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
3001 3526
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -3005,73 +3530,103 @@  discard block
 block discarded – undo
3005 3530
 			$isGoogleMail=false;
3006 3531
 			foreach($autoFoldersTmp as $afk=>$aF)
3007 3532
 			{
3008
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3533
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3534
+				{
3535
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3536
+				}
3009 3537
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3010 3538
 			}
3011 3539
 			//error_log(array2string($mySpecialUseFolders));
3012
-			foreach ($tmpFolders as $k => $f) {
3540
+			foreach ($tmpFolders as $k => $f)
3541
+			{
3013 3542
 				$sorted=false;
3014
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3015
-					if (strtoupper($k)=='INBOX') {
3543
+				if (strtoupper(substr($k,0,5))=='INBOX')
3544
+				{
3545
+					if (strtoupper($k)=='INBOX')
3546
+					{
3016 3547
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3017 3548
 						$inboxFolderObject[$k]=$f;
3018 3549
 						unset($folders[$k]);
3019 3550
 						$sorted=true;
3020
-					} else {
3551
+					}
3552
+					else
3553
+					{
3021 3554
 						$isAutoFolder=false;
3022 3555
 						foreach($autoFoldersTmp as $afk=>$aF)
3023 3556
 						{
3024 3557
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3025 3558
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3026 3559
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3027
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3560
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3561
+							{
3562
+								// k is parent of an autofolder
3028 3563
 							{
3029 3564
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3030 3565
 								$isAutoFolder=true;
3566
+							}
3031 3567
 								$autoFolderObjects[$k]=$f;
3032 3568
 								break;
3033 3569
 							}
3034 3570
 						}
3035
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3571
+						if ($isAutoFolder==false)
3572
+						{
3573
+							$inboxSubFolderObjects[$k]=$f;
3574
+						}
3036 3575
 						unset($folders[$k]);
3037 3576
 						$sorted=true;
3038 3577
 					}
3039
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3578
+				}
3579
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3580
+				{
3040 3581
 					$isGoogleMail=true;
3041
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3582
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3583
+					{
3042 3584
 						$googleMailFolderObject[$k]=$f;
3043 3585
 						unset($folders[$k]);
3044 3586
 						$sorted=true;
3045
-					} else {
3587
+					}
3588
+					else
3589
+					{
3046 3590
 						$isAutoFolder=false;
3047 3591
 						foreach($autoFoldersTmp as $afk=>$aF)
3048 3592
 						{
3049 3593
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3050 3594
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3051 3595
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3052
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3596
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3597
+							{
3598
+								// k is parent of an autofolder
3053 3599
 							{
3054 3600
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3055 3601
 								$isAutoFolder=true;
3602
+							}
3056 3603
 								$googleAutoFolderObjects[$k]=$f;
3057 3604
 								break;
3058 3605
 							}
3059 3606
 						}
3060
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3607
+						if ($isAutoFolder==false)
3608
+						{
3609
+							$googleSubFolderObjects[$k]=$f;
3610
+						}
3061 3611
 						unset($folders[$k]);
3062 3612
 						$sorted=true;
3063 3613
 					}
3064
-				} else {
3614
+				}
3615
+				else
3616
+				{
3065 3617
 					$isAutoFolder=false;
3066 3618
 					foreach($autoFoldersTmp as $afk=>$aF)
3067 3619
 					{
3068 3620
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3069 3621
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3070 3622
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3071
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3623
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3624
+						{
3625
+							// k is parent of an autofolder
3072 3626
 						{
3073 3627
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3074 3628
 							$isAutoFolder=true;
3629
+						}
3075 3630
 							$autoFolderObjects[$k]=$f;
3076 3631
 							unset($folders[$k]);
3077 3632
 							$sorted=true;
@@ -3087,7 +3642,8 @@  discard block
 block discarded – undo
3087 3642
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3088 3643
 						{
3089 3644
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3090
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3645
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3646
+							{
3091 3647
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3092 3648
 								$typeFolderObject[$type][$k]=$f;
3093 3649
 								unset($folders[$k]);
@@ -3114,9 +3670,12 @@  discard block
 block discarded – undo
3114 3670
 				}
3115 3671
 			}
3116 3672
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3117
-			if (!$isGoogleMail) {
3673
+			if (!$isGoogleMail)
3674
+			{
3118 3675
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3119
-			} else {
3676
+			}
3677
+			else
3678
+			{
3120 3679
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3121 3680
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3122 3681
 				unset($googleAutoFolderObjects);
@@ -3133,7 +3692,10 @@  discard block
 block discarded – undo
3133 3692
 				}
3134 3693
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3135 3694
 			}
3136
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3695
+			if (self::$debugTimes)
3696
+			{
3697
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3698
+			}
3137 3699
 			//self::$debugTimes=false;
3138 3700
 		}
3139 3701
 		// Get counter information and add them to each fetched folders array
@@ -3183,7 +3745,13 @@  discard block
 block discarded – undo
3183 3745
 		$rv = false;
3184 3746
 		foreach ($haystack as $k => $v)
3185 3747
 		{
3186
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3748
+			foreach($v as &$sv)
3749
+			{
3750
+if (trim($sv)==trim($needle))
3751
+			{
3752
+				return $k;
3753
+			}
3754
+			}
3187 3755
 		}
3188 3756
 		return $rv;
3189 3757
 	}
@@ -3210,7 +3778,10 @@  discard block
 block discarded – undo
3210 3778
 	 */
3211 3779
 	static function pathToFolderData ($_path, $_hDelimiter)
3212 3780
 	{
3213
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3781
+		if (!strpos($_path, self::DELIMITER))
3782
+		{
3783
+			$_path = self::DELIMITER.$_path;
3784
+		}
3214 3785
 		list(,$path) = explode(self::DELIMITER, $_path);
3215 3786
 		$path_chain = $parts = explode($_hDelimiter, $path);
3216 3787
 		$name = array_pop($parts);
@@ -3239,7 +3810,10 @@  discard block
 block discarded – undo
3239 3810
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3240 3811
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3241 3812
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3242
-		if ($pos1 == $pos2) return 0;
3813
+		if ($pos1 == $pos2)
3814
+		{
3815
+			return 0;
3816
+		}
3243 3817
 		return ($pos1 < $pos2) ? -1 : 1;
3244 3818
 	}
3245 3819
 
@@ -3270,7 +3844,10 @@  discard block
 block discarded – undo
3270 3844
 		// 0, 1 und -1
3271 3845
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3272 3846
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3273
-		if ($pos1 == $pos2) return 0;
3847
+		if ($pos1 == $pos2)
3848
+		{
3849
+			return 0;
3850
+		}
3274 3851
 		return ($pos1 < $pos2) ? -1 : 1;
3275 3852
 	}
3276 3853
 
@@ -3291,11 +3868,18 @@  discard block
 block discarded – undo
3291 3868
 		}
3292 3869
 		catch (\Exception $e)
3293 3870
 		{
3294
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3871
+			if (self::$debug)
3872
+			{
3873
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3874
+			}
3295 3875
 			return false;
3296 3876
 		}
3297
-		if(is_array($folderStatus)) {
3298
-			if ($_returnObject===false) return $folderStatus;
3877
+		if(is_array($folderStatus))
3878
+		{
3879
+			if ($_returnObject===false)
3880
+			{
3881
+				return $folderStatus;
3882
+			}
3299 3883
 			$status =  new \stdClass;
3300 3884
 			$status->messages   = $folderStatus['MESSAGES'];
3301 3885
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3322,7 +3906,8 @@  discard block
 block discarded – undo
3322 3906
 	{
3323 3907
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3324 3908
 		$maxreclevel=25;
3325
-		if ($reclevel > $maxreclevel) {
3909
+		if ($reclevel > $maxreclevel)
3910
+		{
3326 3911
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3327 3912
 			return array();
3328 3913
 		}
@@ -3336,7 +3921,8 @@  discard block
 block discarded – undo
3336 3921
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3337 3922
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3338 3923
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3339
-		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"]))) {
3924
+		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"])))
3925
+		{
3340 3926
 			// if there are children fetch them
3341 3927
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3342 3928
 
@@ -3344,7 +3930,8 @@  discard block
 block discarded – undo
3344 3930
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3345 3931
 			//_debug_array($buff);
3346 3932
 			$allMailboxes = array();
3347
-			foreach ($buff as $mbxname) {
3933
+			foreach ($buff as $mbxname)
3934
+			{
3348 3935
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3349 3936
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3350 3937
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3353,9 +3940,14 @@  discard block
 block discarded – undo
3353 3940
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3354 3941
 				}
3355 3942
 			}
3356
-			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'];
3943
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3944
+			{
3945
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3946
+			}
3357 3947
 			return $allMailboxes;
3358
-		} else {
3948
+		}
3949
+		else
3950
+		{
3359 3951
 			return array($_mailbox);
3360 3952
 		}
3361 3953
 	}
@@ -3379,14 +3971,21 @@  discard block
 block discarded – undo
3379 3971
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3380 3972
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3381 3973
 		);
3382
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3974
+		if ($_type == 'Templates')
3975
+		{
3976
+			$_type = 'Template';
3977
+		}
3978
+		// for some reason self::$autofolders uses 'Templates'!
3383 3979
 		$created = false;
3384 3980
 		if (!isset($types[$_type]))
3385 3981
 		{
3386 3982
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3387 3983
 			return false;
3388 3984
 		}
3389
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3985
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3986
+		{
3987
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3988
+		}
3390 3989
 
3391 3990
 		//highest precedence
3392 3991
 		try
@@ -3396,25 +3995,39 @@  discard block
 block discarded – undo
3396 3995
 		catch (\Exception $e)
3397 3996
 		{
3398 3997
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3399
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3998
+			if ($_type != 'Outbox')
3999
+			{
4000
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
4001
+			}
3400 4002
 			$_folderName = false;
3401 4003
 		}
3402 4004
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3403
-		if ($_type == 'Archive') {
3404
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4005
+		if ($_type == 'Archive')
4006
+		{
4007
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4008
+			{
3405 4009
 				return false;
3406
-			} else {
4010
+			}
4011
+			else
4012
+			{
3407 4013
 				return $_folderName;
3408 4014
 			}
3409 4015
 
3410 4016
 		}
3411 4017
 		// does the folder exist??? (is configured/preset, but non-existent)
3412
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4018
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4019
+		{
3413 4020
 			try
3414 4021
 			{
3415 4022
 				$error = null;
3416
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3417
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4023
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
4024
+				{
4025
+					$created = true;
4026
+				}
4027
+				if ($error)
4028
+				{
4029
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4030
+				}
3418 4031
 			}
3419 4032
 			catch(Exception $e)
3420 4033
 			{
@@ -3423,9 +4036,16 @@  discard block
 block discarded – undo
3423 4036
 			}
3424 4037
 		}
3425 4038
 		// not sure yet if false is the correct behavior on none
3426
-		if ($_folderName =='none') return 'none' ; //false;
4039
+		if ($_folderName =='none')
4040
+		{
4041
+			return 'none' ;
4042
+		}
4043
+		//false;
3427 4044
 		//no (valid) folder found yet; try specialUseFolders
3428
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
4045
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
4046
+		{
4047
+			$_folderName = $f;
4048
+		}
3429 4049
 		//no specialUseFolder; try some Defaults
3430 4050
 		if (empty($_folderName) && isset($types[$_type]))
3431 4051
 		{
@@ -3451,7 +4071,10 @@  discard block
 block discarded – undo
3451 4071
 					$error = null;
3452 4072
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3453 4073
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3454
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4074
+					if ($error)
4075
+					{
4076
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4077
+					}
3455 4078
 				}
3456 4079
 				catch(Exception $e)
3457 4080
 				{
@@ -3554,25 +4177,35 @@  discard block
 block discarded – undo
3554 4177
 	function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3555 4178
 	{
3556 4179
 		$sentFolder = $this->getSentFolder($_checkexistance);
3557
-		if(empty($sentFolder)) {
4180
+		if(empty($sentFolder))
4181
+		{
3558 4182
 			return false;
3559 4183
 		}
3560 4184
 		// does the folder exist???
3561
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4185
+		if ($_checkexistance && !$this->folderExists($_folderName))
4186
+		{
3562 4187
 			return false;
3563 4188
 		}
3564 4189
 
3565 4190
 		if ($_exactMatch)
3566 4191
 		{
3567
-			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) {
4192
+			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder))
4193
+			{
3568 4194
 				return true;
3569
-			} else {
4195
+			}
4196
+			else
4197
+			{
3570 4198
 				return false;
3571 4199
 			}
3572
-		} else {
3573
-			if(false !== stripos($_folderName, $sentFolder)) {
4200
+		}
4201
+		else
4202
+		{
4203
+			if(false !== stripos($_folderName, $sentFolder))
4204
+			{
3574 4205
 				return true;
3575
-			} else {
4206
+			}
4207
+			else
4208
+			{
3576 4209
 				return false;
3577 4210
 			}
3578 4211
 		}
@@ -3587,23 +4220,33 @@  discard block
 block discarded – undo
3587 4220
 	 */
3588 4221
 	function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3589 4222
 	{
3590
-		if (stripos($_folderName, 'Outbox')===false) {
4223
+		if (stripos($_folderName, 'Outbox')===false)
4224
+		{
3591 4225
 			return false;
3592 4226
 		}
3593 4227
 		// does the folder exist???
3594
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4228
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4229
+		{
3595 4230
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3596 4231
 			if ($_exactMatch)
3597 4232
 			{
3598
-				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) {
4233
+				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder))
4234
+				{
3599 4235
 					return true;
3600
-				} else {
4236
+				}
4237
+				else
4238
+				{
3601 4239
 					return false;
3602 4240
 				}
3603
-			} else {
3604
-				if(false !== stripos($_folderName, $outboxFolder)) {
4241
+			}
4242
+			else
4243
+			{
4244
+				if(false !== stripos($_folderName, $outboxFolder))
4245
+				{
3605 4246
 					return true;
3606
-				} else {
4247
+				}
4248
+				else
4249
+				{
3607 4250
 					return false;
3608 4251
 				}
3609 4252
 			}
@@ -3621,25 +4264,38 @@  discard block
 block discarded – undo
3621 4264
 	function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3622 4265
 	{
3623 4266
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3624
-		if(empty($draftFolder)) {
4267
+		if(empty($draftFolder))
4268
+		{
3625 4269
 			return false;
3626 4270
 		}
3627 4271
 		// does the folder exist???
3628
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4272
+		if ($_checkexistance && !$this->folderExists($_folderName))
4273
+		{
3629 4274
 			return false;
3630 4275
 		}
3631
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3632
-		if ($_exactMatch)
4276
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4277
+		{
4278
+			$_folderName = $_folderName->utf8;
4279
+		}
4280
+		if ($_exactMatch)
4281
+		{
4282
+			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder))
4283
+			{
4284
+				return true;
4285
+			}
4286
+			else
4287
+			{
4288
+				return false;
4289
+			}
4290
+		}
4291
+		else
3633 4292
 		{
3634
-			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) {
4293
+			if(false !== stripos($_folderName, $draftFolder))
4294
+			{
3635 4295
 				return true;
3636
-			} else {
3637
-				return false;
3638 4296
 			}
3639
-		} else {
3640
-			if(false !== stripos($_folderName, $draftFolder)) {
3641
-				return true;
3642
-			} else {
4297
+			else
4298
+			{
3643 4299
 				return false;
3644 4300
 			}
3645 4301
 		}
@@ -3655,25 +4311,35 @@  discard block
 block discarded – undo
3655 4311
 	function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3656 4312
 	{
3657 4313
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3658
-		if(empty($trashFolder)) {
4314
+		if(empty($trashFolder))
4315
+		{
3659 4316
 			return false;
3660 4317
 		}
3661 4318
 		// does the folder exist???
3662
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4319
+		if ($_checkexistance && !$this->folderExists($_folderName))
4320
+		{
3663 4321
 			return false;
3664 4322
 		}
3665 4323
 
3666 4324
 		if ($_exactMatch)
3667 4325
 		{
3668
-			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) {
4326
+			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder))
4327
+			{
3669 4328
 				return true;
3670
-			} else {
4329
+			}
4330
+			else
4331
+			{
3671 4332
 				return false;
3672 4333
 			}
3673
-		} else {
3674
-			if(false !== stripos($_folderName, $trashFolder)) {
4334
+		}
4335
+		else
4336
+		{
4337
+			if(false !== stripos($_folderName, $trashFolder))
4338
+			{
3675 4339
 				return true;
3676
-			} else {
4340
+			}
4341
+			else
4342
+			{
3677 4343
 				return false;
3678 4344
 			}
3679 4345
 		}
@@ -3689,24 +4355,34 @@  discard block
 block discarded – undo
3689 4355
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3690 4356
 	{
3691 4357
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3692
-		if(empty($templateFolder)) {
4358
+		if(empty($templateFolder))
4359
+		{
3693 4360
 			return false;
3694 4361
 		}
3695 4362
 		// does the folder exist???
3696
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4363
+		if ($_checkexistance && !$this->folderExists($_folderName))
4364
+		{
3697 4365
 			return false;
3698 4366
 		}
3699 4367
 		if ($_exactMatch)
3700 4368
 		{
3701
-			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) {
4369
+			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder))
4370
+			{
3702 4371
 				return true;
3703
-			} else {
4372
+			}
4373
+			else
4374
+			{
3704 4375
 				return false;
3705 4376
 			}
3706
-		} else {
3707
-			if(false !== stripos($_folderName, $templateFolder)) {
4377
+		}
4378
+		else
4379
+		{
4380
+			if(false !== stripos($_folderName, $templateFolder))
4381
+			{
3708 4382
 				return true;
3709
-			} else {
4383
+			}
4384
+			else
4385
+			{
3710 4386
 				return false;
3711 4387
 			}
3712 4388
 		}
@@ -3725,15 +4401,27 @@  discard block
 block discarded – undo
3725 4401
 		if (empty($_folder))
3726 4402
 		{
3727 4403
 			// this error is more or less without significance, unless we force the check
3728
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4404
+			if ($_forceCheck===true)
4405
+			{
4406
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4407
+			}
3729 4408
 			return false;
3730 4409
 		}
3731 4410
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3732
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3733
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4411
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4412
+		{
4413
+			return true;
4414
+		}
4415
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4416
+		{
4417
+			$_folder =  $_folder->utf8;
4418
+		}
3734 4419
 		// reduce traffic within the Instance per User; Expire every 5 hours
3735 4420
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3736
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4421
+		if (is_null($folderInfo))
4422
+		{
4423
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4424
+		}
3737 4425
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3738 4426
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3739 4427
 		{
@@ -3751,7 +4439,8 @@  discard block
 block discarded – undo
3751 4439
 
3752 4440
 		// does the folder exist???
3753 4441
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3754
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4442
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4443
+		{
3755 4444
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3756 4445
 			//return false;
3757 4446
 			//try to connect
@@ -3792,9 +4481,12 @@  discard block
 block discarded – undo
3792 4481
 
3793 4482
 		$this->icServer->openMailbox($folderName);
3794 4483
 
3795
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4484
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4485
+		{
3796 4486
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3797
-		} else {
4487
+		}
4488
+		else
4489
+		{
3798 4490
 			$this->icServer->expunge($folderName);
3799 4491
 		}
3800 4492
 	}
@@ -3813,10 +4505,16 @@  discard block
 block discarded – undo
3813 4505
 	{
3814 4506
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3815 4507
 		$oldMailbox = '';
3816
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4508
+		if (is_null($_folder) || empty($_folder))
4509
+		{
4510
+			$_folder = $this->sessionData['mailbox'];
4511
+		}
3817 4512
 		if (empty($_messageUID))
3818 4513
 		{
3819
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4514
+			if (self::$debug)
4515
+			{
4516
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4517
+			}
3820 4518
 			return false;
3821 4519
 		}
3822 4520
 		elseif ($_messageUID==='all')
@@ -3826,32 +4524,48 @@  discard block
 block discarded – undo
3826 4524
 		else
3827 4525
 		{
3828 4526
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3829
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4527
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4528
+			{
4529
+				$_messageUID = (array)$_messageUID;
4530
+			}
3830 4531
 			$uidsToDelete->add($_messageUID);
3831 4532
 		}
3832 4533
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3833
-		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");
4534
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4535
+		{
4536
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4537
+		}
3834 4538
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3835 4539
 		$trashFolder    = $this->getTrashFolder();
3836 4540
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3837 4541
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3838 4542
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3839
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4543
+		   (strtolower($_folder) == strtolower($draftFolder)))
4544
+		{
3840 4545
 			$deleteOptions = "remove_immediately";
3841 4546
 		}
3842
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4547
+		if($this->icServer->getCurrentMailbox() != $_folder)
4548
+		{
3843 4549
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3844 4550
 			$this->icServer->openMailbox($_folder);
3845 4551
 		}
3846 4552
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3847 4553
 		$updateCache = false;
3848
-		switch($deleteOptions) {
4554
+		switch($deleteOptions)
4555
+		{
3849 4556
 			case "move_to_trash":
3850 4557
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3851 4558
 				$updateCache = true;
3852
-				if(!empty($trashFolder)) {
3853
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3854
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4559
+				if(!empty($trashFolder))
4560
+				{
4561
+					if (self::$debug)
4562
+					{
4563
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4564
+					}
4565
+					if (self::$debug)
4566
+					{
4567
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4568
+					}
3855 4569
 					// copy messages
3856 4570
 					try
3857 4571
 					{
@@ -3867,7 +4581,10 @@  discard block
 block discarded – undo
3867 4581
 			case "mark_as_deleted":
3868 4582
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3869 4583
 				// mark messages as deleted
3870
-				if (is_null($_messageUID)) $_messageUID='all';
4584
+				if (is_null($_messageUID))
4585
+				{
4586
+					$_messageUID='all';
4587
+				}
3871 4588
 				foreach((array)$_messageUID as $key =>$uid)
3872 4589
 				{
3873 4590
 					//flag messages, that are flagged for deletion as seen too
@@ -3875,7 +4592,10 @@  discard block
 block discarded – undo
3875 4592
 					$flags = $this->getFlags($uid);
3876 4593
 					$this->flagMessages('delete', $uid, $_folder);
3877 4594
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3878
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4595
+					if (strpos( array2string($flags),'Deleted')!==false)
4596
+					{
4597
+						$undelete[] = $uid;
4598
+					}
3879 4599
 					unset($flags);
3880 4600
 				}
3881 4601
 				foreach((array)$undelete as $key =>$uid)
@@ -3887,7 +4607,10 @@  discard block
 block discarded – undo
3887 4607
 			case "remove_immediately":
3888 4608
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3889 4609
 				$updateCache = true;
3890
-				if (is_null($_messageUID)) $_messageUID='all';
4610
+				if (is_null($_messageUID))
4611
+				{
4612
+					$_messageUID='all';
4613
+				}
3891 4614
 				if (is_object($_messageUID))
3892 4615
 				{
3893 4616
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3904,7 +4627,8 @@  discard block
 block discarded – undo
3904 4627
 				$this->icServer->expunge($_folder);
3905 4628
 				break;
3906 4629
 		}
3907
-		if($oldMailbox != '') {
4630
+		if($oldMailbox != '')
4631
+		{
3908 4632
 			$this->icServer->openMailbox($oldMailbox);
3909 4633
 		}
3910 4634
 
@@ -3918,11 +4642,15 @@  discard block
 block discarded – undo
3918 4642
 	 *
3919 4643
 	 * @return null/array flags
3920 4644
 	 */
3921
-	function getFlags ($_messageUID) {
4645
+	function getFlags ($_messageUID)
4646
+	{
3922 4647
 		try
3923 4648
 		{
3924 4649
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3925
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4650
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4651
+			{
4652
+				$_messageUID = (array)$_messageUID;
4653
+			}
3926 4654
 			$uidsToFetch->add($_messageUID);
3927 4655
 			$_folderName = $this->icServer->getCurrentMailbox();
3928 4656
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3930,8 +4658,10 @@  discard block
 block discarded – undo
3930 4658
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3931 4659
 				'ids' => $uidsToFetch,
3932 4660
 			));
3933
-			if (is_object($headersNew)) {
3934
-				foreach($headersNew->ids() as $id) {
4661
+			if (is_object($headersNew))
4662
+			{
4663
+				foreach($headersNew->ids() as $id)
4664
+				{
3935 4665
 					$_headerObject = $headersNew->get($id);
3936 4666
 					$flags = $_headerObject->getFlags();
3937 4667
 				}
@@ -3956,10 +4686,16 @@  discard block
 block discarded – undo
3956 4686
 	 */
3957 4687
 	function getNotifyFlags ($_messageUID, $flags=null)
3958 4688
 	{
3959
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4689
+		if (self::$debug)
4690
+		{
4691
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4692
+		}
3960 4693
 		try
3961 4694
 		{
3962
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4695
+			if($flags===null)
4696
+			{
4697
+				$flags =  $this->getFlags($_messageUID);
4698
+			}
3963 4699
 		}
3964 4700
 		catch (\Exception $e)
3965 4701
 		{
@@ -3967,10 +4703,14 @@  discard block
 block discarded – undo
3967 4703
 		}
3968 4704
 
3969 4705
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3970
-			return true;
4706
+		{
4707
+					return true;
4708
+		}
3971 4709
 
3972 4710
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3973
-			return false;
4711
+		{
4712
+					return false;
4713
+		}
3974 4714
 
3975 4715
 		return null;
3976 4716
 	}
@@ -3991,7 +4731,10 @@  discard block
 block discarded – undo
3991 4731
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3992 4732
 		if (empty($_messageUID))
3993 4733
 		{
3994
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4734
+			if (self::$debug)
4735
+			{
4736
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4737
+			}
3995 4738
 			return false;
3996 4739
 		}
3997 4740
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3999,7 +4742,10 @@  discard block
 block discarded – undo
3999 4742
 		if (is_array($_messageUID)&& count($_messageUID)>50)
4000 4743
 		{
4001 4744
 			$count = $this->getMailBoxCounters($folder,true);
4002
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4745
+			if ($count->messages == count($_messageUID))
4746
+			{
4747
+				$_messageUID='all';
4748
+			}
4003 4749
 		}
4004 4750
 
4005 4751
 		if ($_messageUID==='all')
@@ -4008,7 +4754,10 @@  discard block
 block discarded – undo
4008 4754
 		}
4009 4755
 		else
4010 4756
 		{
4011
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4757
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4758
+			{
4759
+				$_messageUID = (array)$_messageUID;
4760
+			}
4012 4761
 			$messageUIDs = array_chunk($_messageUID,50,true);
4013 4762
 		}
4014 4763
 		try
@@ -4024,7 +4773,8 @@  discard block
 block discarded – undo
4024 4773
 					$uidsToModify = new Horde_Imap_Client_Ids();
4025 4774
 					$uidsToModify->add($uids);
4026 4775
 				}
4027
-				switch($_flag) {
4776
+				switch($_flag)
4777
+				{
4028 4778
 					case "delete":
4029 4779
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
4030 4780
 						break;
@@ -4110,7 +4860,10 @@  discard block
 block discarded – undo
4110 4860
 		{
4111 4861
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4112 4862
 		}
4113
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4863
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4864
+		{
4865
+			$_folder = $folder->utf8;
4866
+		}
4114 4867
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4115 4868
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4116 4869
 
@@ -4139,7 +4892,10 @@  discard block
 block discarded – undo
4139 4892
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4140 4893
 		if (empty($_messageUID))
4141 4894
 		{
4142
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4895
+			if (self::$debug)
4896
+			{
4897
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4898
+			}
4143 4899
 			return false;
4144 4900
 		}
4145 4901
 		elseif ($_messageUID==='all')
@@ -4151,7 +4907,10 @@  discard block
 block discarded – undo
4151 4907
 		{
4152 4908
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4153 4909
 			$uidsToMove = new Horde_Imap_Client_Ids();
4154
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4910
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4911
+			{
4912
+				$_messageUID = (array)$_messageUID;
4913
+			}
4155 4914
 			$uidsToMove->add($_messageUID);
4156 4915
 		}
4157 4916
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4173,12 +4932,14 @@  discard block
 block discarded – undo
4173 4932
 
4174 4933
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4175 4934
 
4176
-			if (is_object($headersNew)) {
4935
+			if (is_object($headersNew))
4936
+			{
4177 4937
 				$c=0;
4178 4938
 				$retUid = new Horde_Imap_Client_Ids();
4179 4939
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4180 4940
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4181
-				foreach($headersNew as &$_headerObject) {
4941
+				foreach($headersNew as &$_headerObject)
4942
+				{
4182 4943
 					$c++;
4183 4944
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4184 4945
 					$date = $_headerObject->getImapDate();
@@ -4262,7 +5023,11 @@  discard block
 block discarded – undo
4262 5023
 	{
4263 5024
 		try {
4264 5025
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4265
-			if ($convert2usertime) $date->setUser();	// convert to user-time
5026
+			if ($convert2usertime)
5027
+			{
5028
+				$date->setUser();
5029
+			}
5030
+			// convert to user-time
4266 5031
 			$date2return = $date->format($format);
4267 5032
 		}
4268 5033
 		catch(\Exception $e)
@@ -4294,9 +5059,15 @@  discard block
 block discarded – undo
4294 5059
 	static function htmlentities($_string, $_charset=false)
4295 5060
 	{
4296 5061
 		//setting the charset (if not given)
4297
-		if ($_charset===false) $_charset = self::$displayCharset;
5062
+		if ($_charset===false)
5063
+		{
5064
+			$_charset = self::$displayCharset;
5065
+		}
4298 5066
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4299
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
5067
+		if (empty($string) && !empty($_string))
5068
+		{
5069
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
5070
+		}
4300 5071
 		return $string;
4301 5072
 	}
4302 5073
 
@@ -4316,18 +5087,41 @@  discard block
 block discarded – undo
4316 5087
 		$_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>'),
4317 5088
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4318 5089
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4319
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4320
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
5090
+		if (stripos($_html,'style')!==false)
5091
+		{
5092
+			Mail\Html::replaceTagsCompletley($_html,'style');
5093
+		}
5094
+		// clean out empty or pagewide style definitions / left over tags
5095
+		if (stripos($_html,'head')!==false)
5096
+		{
5097
+			Mail\Html::replaceTagsCompletley($_html,'head');
5098
+		}
5099
+		// Strip out stuff in head
4321 5100
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4322 5101
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4323 5102
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4324 5103
 
4325
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
5104
+		if (get_magic_quotes_gpc() === 1)
5105
+		{
5106
+			$_html = stripslashes($_html);
5107
+		}
4326 5108
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4327
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4328
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4329
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4330
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5109
+		if (stripos($_html,'!doctype')!==false)
5110
+		{
5111
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
5112
+		}
5113
+		if (stripos($_html,'?xml:namespace')!==false)
5114
+		{
5115
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
5116
+		}
5117
+		if (stripos($_html,'?xml version')!==false)
5118
+		{
5119
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
5120
+		}
5121
+		if (strpos($_html,'!CURSOR')!==false)
5122
+		{
5123
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5124
+		}
4331 5125
 		// htmLawed filter only the 'body'
4332 5126
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4333 5127
 		//if ($matches[2])
@@ -4366,8 +5160,10 @@  discard block
 block discarded – undo
4366 5160
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4367 5161
 		$CharsetFound=false;
4368 5162
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4369
-		if(is_array($_mimePartObject->parameters)) {
4370
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5163
+		if(is_array($_mimePartObject->parameters))
5164
+		{
5165
+			if(isset($_mimePartObject->parameters['CHARSET']))
5166
+			{
4371 5167
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4372 5168
 				$CharsetFound=true;
4373 5169
 			}
@@ -4388,7 +5184,10 @@  discard block
 block discarded – undo
4388 5184
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4389 5185
 	{
4390 5186
 		// decode the part
4391
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5187
+		if (self::$debug)
5188
+		{
5189
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5190
+		}
4392 5191
 		switch (strtoupper($_encoding))
4393 5192
 		{
4394 5193
 			case 'BASE64':
@@ -4428,13 +5227,19 @@  discard block
 block discarded – undo
4428 5227
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4429 5228
 		// as attachment AND as abstracted ical information (we use our notification style here).
4430 5229
 		$partText = $partCalendar = $partHTML = null;
4431
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5230
+		if (self::$debug)
5231
+		{
5232
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5233
+		}
4432 5234
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4433 5235
 		$ignore_first_part = true;
4434 5236
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4435 5237
 		{
4436 5238
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4437
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5239
+			if (self::$debug)
5240
+			{
5241
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5242
+			}
4438 5243
 
4439 5244
 			if ($ignore_first_part)
4440 5245
 			{
@@ -4450,11 +5255,17 @@  discard block
 block discarded – undo
4450 5255
 					switch($mimePart->getSubType())
4451 5256
 					{
4452 5257
 						case 'plain':
4453
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5258
+							if ($mimePart->getBytes() > 0)
5259
+							{
5260
+								$partText = $mimePart;
5261
+							}
4454 5262
 							break;
4455 5263
 
4456 5264
 						case 'html':
4457
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5265
+							if ($mimePart->getBytes() > 0)
5266
+							{
5267
+								$partHTML = $mimePart;
5268
+							}
4458 5269
 							break;
4459 5270
 					}
4460 5271
 					break;
@@ -4467,7 +5278,10 @@  discard block
 block discarded – undo
4467 5278
 							if (count($mimePart->getParts()) > 1)
4468 5279
 							{
4469 5280
 								// in a multipart alternative we treat the multipart/related as html part
4470
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5281
+								if (self::$debug)
5282
+								{
5283
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5284
+								}
4471 5285
 								$partHTML = $mimePart;
4472 5286
 								break 3; // GET OUT OF LOOP, will be processed according to type
4473 5287
 							}
@@ -4548,9 +5362,15 @@  discard block
 block discarded – undo
4548 5362
 	 */
4549 5363
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4550 5364
 	{
4551
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5365
+		if (self::$debug)
5366
+		{
5367
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5368
+		}
4552 5369
 		$bodyPart = array();
4553
-		if (self::$debug) _debug_array($_structure);
5370
+		if (self::$debug)
5371
+		{
5372
+			_debug_array($_structure);
5373
+		}
4554 5374
 
4555 5375
 		$ignore_first_part = true;
4556 5376
 		//$skipParts = array();
@@ -4558,7 +5378,10 @@  discard block
 block discarded – undo
4558 5378
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4559 5379
 		{
4560 5380
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4561
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5381
+			if (self::$debug)
5382
+			{
5383
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5384
+			}
4562 5385
 			if ($ignore_first_part)
4563 5386
 			{
4564 5387
 				$ignore_first_part = false;
@@ -4576,7 +5399,10 @@  discard block
 block discarded – undo
4576 5399
 			switch($part->getPrimaryType())
4577 5400
 			{
4578 5401
 				case 'multipart':
4579
-					if ($part->getDisposition() == 'attachment') continue;
5402
+					if ($part->getDisposition() == 'attachment')
5403
+					{
5404
+						continue;
5405
+					}
4580 5406
 					switch($part->getSubType())
4581 5407
 					{
4582 5408
 						case 'alternative':
@@ -4641,7 +5467,9 @@  discard block
 block discarded – undo
4641 5467
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4642 5468
 					{
4643 5469
 						$skipParts[$mime_id.'.0'] = $mime_type;
4644
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5470
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5471
+						{
5472
+$skipParts[$sub_id] = $sub_type;}
4645 5473
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4646 5474
 						//break 2;
4647 5475
 					}
@@ -4684,7 +5512,10 @@  discard block
 block discarded – undo
4684 5512
 	 */
4685 5513
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4686 5514
 	{
4687
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5515
+		if (self::$debug)
5516
+		{
5517
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5518
+		}
4688 5519
 
4689 5520
 		if (empty($_folder))
4690 5521
 		{
@@ -4693,7 +5524,10 @@  discard block
 block discarded – undo
4693 5524
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4694 5525
 		// querying contents of body part
4695 5526
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4696
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5527
+		if (!(is_object($_uid) || is_array($_uid)))
5528
+		{
5529
+			$_uid = (array)$_uid;
5530
+		}
4697 5531
 		$uidsToFetch->add($_uid);
4698 5532
 
4699 5533
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4701,9 +5535,12 @@  discard block
 block discarded – undo
4701 5535
 			'peek' => $_preserveSeen,
4702 5536
 			'decode' => true,	// try decode on server, does NOT neccessary work
4703 5537
 		);
4704
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5538
+		if ($_tryDecodingServerside===false)
5539
+		{
5540
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4705 5541
 		{
4706 5542
 			$_tryDecodingServerside=false;
5543
+		}
4707 5544
 			$fetchParams = array(
4708 5545
 				'peek' => $_preserveSeen,
4709 5546
 			);
@@ -4745,7 +5582,10 @@  discard block
 block discarded – undo
4745 5582
 	{
4746 5583
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4747 5584
 		$bodyPart = array();
4748
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5585
+		if (self::$debug)
5586
+		{
5587
+			_debug_array(array($_structure,function_backtrace()));
5588
+		}
4749 5589
 
4750 5590
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4751 5591
 		{
@@ -4795,8 +5635,12 @@  discard block
 block discarded – undo
4795 5635
 	 */
4796 5636
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4797 5637
 	{
4798
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4799
-		if($_htmlOptions != '') {
5638
+		if (self::$debug)
5639
+		{
5640
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5641
+		}
5642
+		if($_htmlOptions != '')
5643
+		{
4800 5644
 			$this->htmlOptions = $_htmlOptions;
4801 5645
 		}
4802 5646
 		if (empty($_folder))
@@ -4885,7 +5729,9 @@  discard block
 block discarded – undo
4885 5729
 						default:
4886 5730
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4887 5731
 					}
4888
-				} else {
5732
+				}
5733
+				else
5734
+				{
4889 5735
 					// what if the structure->disposition is attachment ,...
4890 5736
 				}
4891 5737
 				return self::normalizeBodyParts($bodyPart);
@@ -4896,13 +5742,18 @@  discard block
 block discarded – undo
4896 5742
 				{
4897 5743
 					case 'rfc822':
4898 5744
 						$newStructure = $_structure->getParts();
4899
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5745
+						if (self::$debug)
5746
+						{
5747
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4900 5748
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4901 5749
 				}
4902 5750
 				break;
4903 5751
 
4904 5752
 			default:
4905
-				if (self::$debug) _debug_array($_structure);
5753
+				if (self::$debug)
5754
+				{
5755
+					_debug_array($_structure);
5756
+				}
4906 5757
 				return array(
4907 5758
 					array(
4908 5759
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4926,9 +5777,12 @@  discard block
 block discarded – undo
4926 5777
 		{
4927 5778
 			foreach($_bodyParts as $singleBodyPart)
4928 5779
 			{
4929
-				if (!isset($singleBodyPart['body'])) {
5780
+				if (!isset($singleBodyPart['body']))
5781
+				{
4930 5782
 					$buff = self::normalizeBodyParts($singleBodyPart);
4931
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5783
+					foreach ((array)$buff as $val)
5784
+					{
5785
+$body2return[] = $val;}
4932 5786
 					continue;
4933 5787
 				}
4934 5788
 				$body2return[] = $singleBodyPart;
@@ -4954,13 +5808,20 @@  discard block
 block discarded – undo
4954 5808
 		$message='';
4955 5809
 		for($i=0; $i<count($bodyParts); $i++)
4956 5810
 		{
4957
-			if (!isset($bodyParts[$i]['body'])) {
5811
+			if (!isset($bodyParts[$i]['body']))
5812
+			{
4958 5813
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4959 5814
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4960 5815
 				continue;
4961 5816
 			}
4962
-			if (isset($bodyParts[$i]['error'])) continue;
4963
-			if (empty($bodyParts[$i]['body'])) continue;
5817
+			if (isset($bodyParts[$i]['error']))
5818
+			{
5819
+				continue;
5820
+			}
5821
+			if (empty($bodyParts[$i]['body']))
5822
+			{
5823
+				continue;
5824
+			}
4964 5825
 			// some characterreplacements, as they fail to translate
4965 5826
 			$sar = array(
4966 5827
 				'@(\x84|\x93|\x94)@',
@@ -4987,13 +5848,17 @@  discard block
 block discarded – undo
4987 5848
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4988 5849
 			}
4989 5850
 
4990
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5851
+			if ($bodyParts[$i]['charSet']===false)
5852
+			{
5853
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5854
+			}
4991 5855
 			// add line breaks to $bodyParts
4992 5856
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4993 5857
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4994 5858
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4995 5859
 			$mailClass->activeMimeType = 'text/plain';
4996
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5860
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5861
+			{
4997 5862
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4998 5863
 				if (!$preserveHTML)
4999 5864
 				{
@@ -5039,15 +5904,28 @@  discard block
 block discarded – undo
5039 5904
 						// as we switched off HTMLaweds tidy functionality
5040 5905
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
5041 5906
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
5042
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5907
+						if ($hasOther && $preserveHTML)
5908
+						{
5909
+							$newBody = $matches[1]. $newBody. $matches[3];
5910
+						}
5043 5911
 						$alreadyHtmlLawed=true;
5044 5912
 					}
5045 5913
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
5046
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5914
+					if ($preserveHTML==false)
5915
+					{
5916
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5917
+					}
5047 5918
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
5048
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5919
+					if ($preserveHTML==false)
5920
+					{
5921
+						$newBody = nl2br($newBody);
5922
+					}
5923
+					// we need this, as htmLawed removes \r\n
5049 5924
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
5050
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5925
+					if ($preserveHTML==false)
5926
+					{
5927
+						$newBody = str_replace("<br />","\r\n",$newBody);
5928
+					}
5051 5929
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5052 5930
 				}
5053 5931
 				$message .= $newBody;
@@ -5084,12 +5962,12 @@  discard block
 block discarded – undo
5084 5962
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5085 5963
 				 )
5086 5964
 				)
5087
-			   )
5088
-			{
5965
+			   ) {
5089 5966
 				$s=explode(" ", $line);
5090 5967
 				$line = "";
5091 5968
 				$linecnt = 0;
5092
-				foreach ($s as &$v) {
5969
+				foreach ($s as &$v)
5970
+				{
5093 5971
 					$cnt = strlen($v);
5094 5972
 					// only break long words within the wordboundaries,
5095 5973
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -5099,14 +5977,20 @@  discard block
 block discarded – undo
5099 5977
 						$v=wordwrap($v, $allowedLength, $cut, true);
5100 5978
 					}
5101 5979
 					// the rest should be broken at the start of the new word that exceeds the limit
5102
-					if ($linecnt+$cnt > $allowedLength) {
5980
+					if ($linecnt+$cnt > $allowedLength)
5981
+					{
5103 5982
 						$v=$cut.$v;
5104 5983
 						#$linecnt = 0;
5105 5984
 						$linecnt =strlen($v)-strlen($cut);
5106
-					} else {
5985
+					}
5986
+					else
5987
+					{
5107 5988
 						$linecnt += $cnt;
5108 5989
 					}
5109
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5990
+					if (strlen($v))
5991
+					{
5992
+						$line .= (strlen($line) ? " " : "").$v;
5993
+					}
5110 5994
 				}
5111 5995
 			}
5112 5996
 			$newStr .= $line . "\n";
@@ -5127,11 +6011,18 @@  discard block
 block discarded – undo
5127 6011
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5128 6012
 	{
5129 6013
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5130
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6014
+		if (empty($_folder))
6015
+		{
6016
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6017
+		}
5131 6018
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5132
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
6019
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
6020
+		{
5133 6021
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5134
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6022
+			if (!(is_object($_uid) || is_array($_uid)))
6023
+			{
6024
+				$_uid = (array)$_uid;
6025
+			}
5135 6026
 			$uidsToFetch->add($_uid);
5136 6027
 
5137 6028
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5141,8 +6032,10 @@  discard block
 block discarded – undo
5141 6032
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5142 6033
 				'ids' => $uidsToFetch,
5143 6034
 			));
5144
-			if (is_object($headersNew)) {
5145
-				foreach($headersNew as &$_headerObject) {
6035
+			if (is_object($headersNew))
6036
+			{
6037
+				foreach($headersNew as &$_headerObject)
6038
+				{
5146 6039
 					$env = $_headerObject->getEnvelope();
5147 6040
 					//_debug_array($envFields->singleFields());
5148 6041
 					$singleFields = $envFields->singleFields();
@@ -5159,7 +6052,10 @@  discard block
 block discarded – undo
5159 6052
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5160 6053
 								$envelope[$v]=$env->$v->addresses;
5161 6054
 								$address = array();
5162
-								if (!is_array($envelope[$v])) break;
6055
+								if (!is_array($envelope[$v]))
6056
+								{
6057
+									break;
6058
+								}
5163 6059
 								foreach ($envelope[$v] as $k => $ad)
5164 6060
 								{
5165 6061
 									if (stripos($ad,'@')===false)
@@ -5196,7 +6092,9 @@  discard block
 block discarded – undo
5196 6092
 				}
5197 6093
 			}
5198 6094
 			return $envelope;
5199
-		} else {
6095
+		}
6096
+		else
6097
+		{
5200 6098
 
5201 6099
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5202 6100
 
@@ -5207,19 +6105,43 @@  discard block
 block discarded – undo
5207 6105
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5208 6106
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5209 6107
 			);
5210
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5211
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5212
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5213
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5214
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5215
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
6108
+			if (isset($headers['IN-REPLY-TO']))
6109
+			{
6110
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
6111
+			}
6112
+			if (isset($headers['REFERENCES']))
6113
+			{
6114
+				$newData['REFERENCES'] = $headers['REFERENCES'];
6115
+			}
6116
+			if (isset($headers['THREAD-TOPIC']))
6117
+			{
6118
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
6119
+			}
6120
+			if (isset($headers['THREAD-INDEX']))
6121
+			{
6122
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6123
+			}
6124
+			if (isset($headers['LIST-ID']))
6125
+			{
6126
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6127
+			}
6128
+			if (isset($headers['SIZE']))
6129
+			{
6130
+				$newData['SIZE'] = $headers['SIZE'];
6131
+			}
5216 6132
 			//_debug_array($newData);
5217 6133
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5218
-			foreach($recepientList as $recepientType) {
5219
-				if(isset($headers[$recepientType])) {
5220
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6134
+			foreach($recepientList as $recepientType)
6135
+			{
6136
+				if(isset($headers[$recepientType]))
6137
+				{
6138
+					if ($decode)
6139
+					{
6140
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6141
+					}
5221 6142
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5222
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6143
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6144
+					{
5223 6145
 						$addressData = array(
5224 6146
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5225 6147
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5227,17 +6149,25 @@  discard block
 block discarded – undo
5227 6149
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5228 6150
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5229 6151
 						);
5230
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6152
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6153
+						{
5231 6154
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5232
-						} else {
6155
+						}
6156
+						else
6157
+						{
5233 6158
 							$addressData['RFC822_EMAIL'] = 'NIL';
5234 6159
 						}
5235 6160
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5236 6161
 					}
5237
-				} else {
5238
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6162
+				}
6163
+				else
6164
+				{
6165
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6166
+					{
5239 6167
 						$newData[$recepientType] = $newData['FROM'];
5240
-					} else {
6168
+					}
6169
+					else
6170
+					{
5241 6171
 						$newData[$recepientType] = array();
5242 6172
 					}
5243 6173
 				}
@@ -5260,9 +6190,15 @@  discard block
 block discarded – undo
5260 6190
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5261 6191
 	{
5262 6192
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5263
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6193
+		if (empty($_folder))
6194
+		{
6195
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6196
+		}
5264 6197
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5265
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6198
+		if (!(is_object($_uid) || is_array($_uid)))
6199
+		{
6200
+			$_uid = (array)$_uid;
6201
+		}
5266 6202
 		$uidsToFetch->add($_uid);
5267 6203
 
5268 6204
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5280,7 +6216,8 @@  discard block
 block discarded – undo
5280 6216
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5281 6217
 			'ids' => $uidsToFetch,
5282 6218
 		));
5283
-		if (is_object($headersNew)) {
6219
+		if (is_object($headersNew))
6220
+		{
5284 6221
 			foreach($headersNew as $_fetchObject)
5285 6222
 			{
5286 6223
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5302,11 +6239,17 @@  discard block
 block discarded – undo
5302 6239
 			}
5303 6240
 			if ($decode === 'object')
5304 6241
 			{
5305
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6242
+				if (is_object($headers))
6243
+				{
6244
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6245
+				}
5306 6246
 				return $headers;
5307 6247
 			}
5308 6248
 			$retValue = is_object($headers) ? $headers->toArray():array();
5309
-			if ($size) $retValue['size'] = $size;
6249
+			if ($size)
6250
+			{
6251
+				$retValue['size'] = $size;
6252
+			}
5310 6253
 		}
5311 6254
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5312 6255
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5338,10 +6281,16 @@  discard block
 block discarded – undo
5338 6281
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5339 6282
 	{
5340 6283
 		static $rawHeaders;
5341
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6284
+		if (empty($_folder))
6285
+		{
6286
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6287
+		}
5342 6288
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5343 6289
 
5344
-		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);
6290
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6291
+		{
6292
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6293
+		}
5345 6294
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5346 6295
 		{
5347 6296
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5349,7 +6298,10 @@  discard block
 block discarded – undo
5349 6298
 		}
5350 6299
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5351 6300
 		$uid = $_uid;
5352
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6301
+		if (!(is_object($_uid) || is_array($_uid)))
6302
+		{
6303
+			$uid = (array)$_uid;
6304
+		}
5353 6305
 		$uidsToFetch->add($uid);
5354 6306
 
5355 6307
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5365,8 +6317,10 @@  discard block
 block discarded – undo
5365 6317
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5366 6318
 			'ids' => $uidsToFetch,
5367 6319
 		));
5368
-		if (is_object($headersNew)) {
5369
-			foreach($headersNew as &$_headerObject) {
6320
+		if (is_object($headersNew))
6321
+		{
6322
+			foreach($headersNew as &$_headerObject)
6323
+			{
5370 6324
 				$retValue = $_headerObject->getHeaderText();
5371 6325
 				if ($_partID != '')
5372 6326
 				{
@@ -5394,22 +6348,33 @@  discard block
 block discarded – undo
5394 6348
 	static function &getStyles($_bodyParts)
5395 6349
 	{
5396 6350
 		$style = '';
5397
-		if (empty($_bodyParts)) return "";
5398
-		foreach((array)$_bodyParts as $singleBodyPart) {
5399
-			if (!isset($singleBodyPart['body'])) {
6351
+		if (empty($_bodyParts))
6352
+		{
6353
+			return "";
6354
+		}
6355
+		foreach((array)$_bodyParts as $singleBodyPart)
6356
+		{
6357
+			if (!isset($singleBodyPart['body']))
6358
+			{
5400 6359
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5401 6360
 				$style .= $singleBodyPart['body'];
5402 6361
 				continue;
5403 6362
 			}
5404 6363
 
5405
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6364
+			if ($singleBodyPart['charSet']===false)
6365
+			{
6366
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6367
+			}
5406 6368
 			$singleBodyPart['body'] = Translation::convert(
5407 6369
 				$singleBodyPart['body'],
5408 6370
 				strtolower($singleBodyPart['charSet'])
5409 6371
 			);
5410 6372
 			$ct = 0;
5411 6373
 			$newStyle=array();
5412
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6374
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6375
+			{
6376
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6377
+			}
5413 6378
 			if ($ct>0)
5414 6379
 			{
5415 6380
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5441,7 +6406,11 @@  discard block
 block discarded – undo
5441 6406
 		// CSS Security
5442 6407
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5443 6408
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5444
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6409
+		if (stripos($css,'script')!==false)
6410
+		{
6411
+			Mail\Html::replaceTagsCompletley($css,'script');
6412
+		}
6413
+		// Strip out script that may be included
5445 6414
 		// 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
5446 6415
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5447 6416
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5462,8 +6431,14 @@  discard block
 block discarded – undo
5462 6431
 	{
5463 6432
 		//TODO: caching einbauen static!
5464 6433
 		static $rawBody;
5465
-		if (is_null($rawBody)) $rawBody = array();
5466
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6434
+		if (is_null($rawBody))
6435
+		{
6436
+			$rawBody = array();
6437
+		}
6438
+		if (empty($_folder))
6439
+		{
6440
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6441
+		}
5467 6442
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5468 6443
 		{
5469 6444
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5472,7 +6447,10 @@  discard block
 block discarded – undo
5472 6447
 
5473 6448
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5474 6449
 		$uid = $_uid;
5475
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6450
+		if (!(is_object($_uid) || is_array($_uid)))
6451
+		{
6452
+			$uid = (array)$_uid;
6453
+		}
5476 6454
 		$uidsToFetch->add($uid);
5477 6455
 
5478 6456
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5485,8 +6463,10 @@  discard block
 block discarded – undo
5485 6463
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5486 6464
 			'ids' => $uidsToFetch,
5487 6465
 		));
5488
-		if (is_object($headersNew)) {
5489
-			foreach($headersNew as &$_headerObject) {
6466
+		if (is_object($headersNew))
6467
+		{
6468
+			foreach($headersNew as &$_headerObject)
6469
+			{
5490 6470
 				$body = $_headerObject->getFullMsg();
5491 6471
 				if ($_partID != '')
5492 6472
 				{
@@ -5519,14 +6499,20 @@  discard block
 block discarded – undo
5519 6499
 	 */
5520 6500
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5521 6501
 	{
5522
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6502
+		if (self::$debug)
6503
+		{
6504
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6505
+		}
5523 6506
 
5524 6507
 		if (empty($_folder))
5525 6508
 		{
5526 6509
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5527 6510
 		}
5528 6511
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5529
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6512
+		if (!(is_object($_uid) || is_array($_uid)))
6513
+		{
6514
+			$_uid = (array)$_uid;
6515
+		}
5530 6516
 		$uidsToFetch->add($_uid);
5531 6517
 		try
5532 6518
 		{
@@ -5535,7 +6521,10 @@  discard block
 block discarded – undo
5535 6521
 	//		$fquery->envelope();
5536 6522
 	//		$fquery->size();
5537 6523
 			$_fquery->structure();
5538
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6524
+			if ($_partID)
6525
+			{
6526
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6527
+			}
5539 6528
 
5540 6529
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5541 6530
 				'ids' => $uidsToFetch,
@@ -5566,16 +6555,28 @@  discard block
 block discarded – undo
5566 6555
 	 */
5567 6556
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5568 6557
 	{
5569
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5570
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6558
+		if (self::$debug)
6559
+		{
6560
+			error_log( __METHOD__.":$_uid, $_partID");
6561
+		}
6562
+		if (empty($_folder))
6563
+		{
6564
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6565
+		}
5571 6566
 		$attachments = array();
5572 6567
 		if (!isset($_structure))
5573 6568
 		{
5574 6569
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5575 6570
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5576 6571
 		}
5577
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5578
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6572
+		if (!$_structure || !$_structure->contentTypeMap())
6573
+		{
6574
+			return array();
6575
+		}
6576
+		if (!empty($_partID))
6577
+		{
6578
+			$_structure = $_structure->getPart($_partID);
6579
+		}
5579 6580
 		$skipParts = array();
5580 6581
 		$tnefParts = array();
5581 6582
 		$skip = 0;
@@ -5604,7 +6605,13 @@  discard block
 block discarded – undo
5604 6605
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5605 6606
 			{
5606 6607
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5607
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6608
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6609
+				{
6610
+if ($sub_id != $mime_id)
6611
+				{
6612
+					$skipParts[$sub_id] = $sub_type;
6613
+				}
6614
+				}
5608 6615
 			}
5609 6616
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5610 6617
 			{
@@ -5615,7 +6622,10 @@  discard block
 block discarded – undo
5615 6622
 				$partDisposition='attachment';
5616 6623
 			}
5617 6624
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5618
-			if (array_key_exists($mime_id,$skipParts)) continue;
6625
+			if (array_key_exists($mime_id,$skipParts))
6626
+			{
6627
+				continue;
6628
+			}
5619 6629
 
5620 6630
 			if ($partDisposition == 'attachment' ||
5621 6631
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5626,23 +6636,41 @@  discard block
 block discarded – undo
5626 6636
 			{
5627 6637
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5628 6638
 				// we attempt to fetch "ourselves"
5629
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6639
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6640
+				{
6641
+					continue;
6642
+				}
5630 6643
 				$attachment = $part->getAllDispositionParameters();
5631 6644
 				$attachment['disposition'] = $part->getDisposition();
5632 6645
 				$attachment['mimeType'] = $mime_type;
5633 6646
 				$attachment['uid'] = $_uid;
5634 6647
 				$attachment['partID'] = $mime_id;
5635
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6648
+				if (!isset($attachment['name'])||empty($attachment['name']))
6649
+				{
6650
+					$attachment['name'] = $part->getName();
6651
+				}
5636 6652
 				if ($fetchTextCalendar)
5637 6653
 				{
5638 6654
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5639 6655
 					$method = $part->getContentTypeParameter('method');
5640
-					if ($method) $attachment['method'] = $method;
5641
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6656
+					if ($method)
6657
+					{
6658
+						$attachment['method'] = $method;
6659
+					}
6660
+					if (!isset($attachment['name']))
6661
+					{
6662
+						$attachment['name'] = 'event.ics';
6663
+					}
5642 6664
 				}
5643 6665
 				$attachment['size'] = $part->getBytes();
5644
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5645
-				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);
6666
+				if (($cid = $part->getContentId()))
6667
+				{
6668
+					$attachment['cid'] = $cid;
6669
+				}
6670
+				if (empty($attachment['name']))
6671
+				{
6672
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6673
+				}
5646 6674
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5647 6675
 				//typical winmail.dat attachment is
5648 6676
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5678,14 +6706,26 @@  discard block
 block discarded – undo
5678 6706
 						$attachment['uid'] = $tnp['uid'];
5679 6707
 						$attachment['partID'] = $tnp['partID'];
5680 6708
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5681
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6709
+						if (!isset($attachment['name'])||empty($attachment['name']))
6710
+						{
6711
+							$attachment['name'] = $part->getName();
6712
+						}
5682 6713
 						$attachment['size'] = $part->getBytes();
5683
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5684
-						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']);
6714
+						if (($cid = $part->getContentId()))
6715
+						{
6716
+							$attachment['cid'] = $cid;
6717
+						}
6718
+						if (empty($attachment['name']))
6719
+						{
6720
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6721
+						}
5685 6722
 						$attachments[] = $attachment;
5686 6723
 					}
5687 6724
 				}
5688
-				if ($tnefResolved===false) $attachments[]=$tnp;
6725
+				if ($tnefResolved===false)
6726
+				{
6727
+					$attachments[]=$tnp;
6728
+				}
5689 6729
 			}
5690 6730
 		}
5691 6731
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5789,8 +6829,14 @@  discard block
 block discarded – undo
5789 6829
 
5790 6830
 				$attachment = $part->getAllDispositionParameters();
5791 6831
 				$attachment['mimeType'] = $part->getType();
5792
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5793
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6832
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6833
+				{
6834
+					$attachment['filename'] = $part->getName();
6835
+				}
6836
+				if (($cid = $part->getContentId()))
6837
+				{
6838
+					$attachment['cid'] = $cid;
6839
+				}
5794 6840
 				if (empty($attachment['filename']))
5795 6841
 				{
5796 6842
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5802,7 +6848,10 @@  discard block
 block discarded – undo
5802 6848
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5803 6849
 			}
5804 6850
 		}
5805
-		if (!is_array($attachments)) return false;
6851
+		if (!is_array($attachments))
6852
+		{
6853
+			return false;
6854
+		}
5806 6855
 		return $attachments;
5807 6856
 	}
5808 6857
 
@@ -5821,10 +6870,16 @@  discard block
 block discarded – undo
5821 6870
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5822 6871
 	{
5823 6872
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5824
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6873
+		if (!isset($_folder))
6874
+		{
6875
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6876
+		}
5825 6877
 
5826 6878
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5827
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6879
+		if (!(is_object($_uid) || is_array($_uid)))
6880
+		{
6881
+			$_uid = (array)$_uid;
6882
+		}
5828 6883
 		$uidsToFetch->add($_uid);
5829 6884
 
5830 6885
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5833,8 +6888,10 @@  discard block
 block discarded – undo
5833 6888
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5834 6889
 			'ids' => $uidsToFetch,
5835 6890
 		));
5836
-		if (is_object($headersNew)) {
5837
-			foreach($headersNew as $id=>$_headerObject) {
6891
+		if (is_object($headersNew))
6892
+		{
6893
+			foreach($headersNew as $id=>$_headerObject)
6894
+			{
5838 6895
 				$body = $_headerObject->getFullMsg();
5839 6896
 				if ($_partID != '')
5840 6897
 				{
@@ -5848,7 +6905,10 @@  discard block
 block discarded – undo
5848 6905
 					}
5849 6906
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5850 6907
 					// itself is only triggered to fetch attachments
5851
-					if (empty($partDisposition)) $partDisposition='attachment';
6908
+					if (empty($partDisposition))
6909
+					{
6910
+						$partDisposition='attachment';
6911
+					}
5852 6912
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5853 6913
 					{
5854 6914
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5857,13 +6917,19 @@  discard block
 block discarded – undo
5857 6917
 						$charset = $part->getContentTypeParameter('charset');
5858 6918
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5859 6919
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5860
-						if ($_returnPart) return $part;
6920
+						if ($_returnPart)
6921
+						{
6922
+							return $part;
6923
+						}
5861 6924
 					}
5862 6925
 				}
5863 6926
 			}
5864 6927
 		}
5865 6928
 		$ext = MimeMagic::mime2ext($structure_mime);
5866
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6929
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6930
+		{
6931
+			$filename = trim($filename).'.'.$ext;
6932
+		}
5867 6933
 		if (!$part)
5868 6934
 		{
5869 6935
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5879,7 +6945,10 @@  discard block
 block discarded – undo
5879 6945
 		);
5880 6946
 
5881 6947
 		// try guessing the mimetype, if we get the application/octet-stream
5882
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6948
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6949
+		{
6950
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6951
+		}
5883 6952
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5884 6953
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5885 6954
 		{
@@ -5902,9 +6971,18 @@  discard block
 block discarded – undo
5902 6971
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5903 6972
 					{
5904 6973
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5905
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5906
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5907
-						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']);
6974
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6975
+						{
6976
+							$attachment['filename'] = $part->getName();
6977
+						}
6978
+						if (($cid = $part->getContentId()))
6979
+						{
6980
+							$attachment['cid'] = $cid;
6981
+						}
6982
+						if (empty($attachment['filename']))
6983
+						{
6984
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6985
+						}
5908 6986
 						$wmattach = $attachment;
5909 6987
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5910 6988
 
@@ -5914,7 +6992,10 @@  discard block
 block discarded – undo
5914 6992
 			if ($tnefResolved)
5915 6993
 			{
5916 6994
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5917
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6995
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6996
+				{
6997
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6998
+				}
5918 6999
 				$attachmentData = array(
5919 7000
 					'type'       => $wmattach['mimeType'],
5920 7001
 					'filename'   => $wmattach['filename'],
@@ -5944,7 +7025,10 @@  discard block
 block discarded – undo
5944 7025
 		static $uid=null, $part=null, $structure=null;
5945 7026
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5946 7027
 
5947
-		if(empty($_cid)) return false;
7028
+		if(empty($_cid))
7029
+		{
7030
+			return false;
7031
+		}
5948 7032
 
5949 7033
 		if ($_uid != $uid || $_part != $part)
5950 7034
 		{
@@ -5969,13 +7053,19 @@  discard block
 block discarded – undo
5969 7053
 					$attachment = $part;
5970 7054
 				}
5971 7055
 				// everything else we only consider after we checked all
5972
-				if (!isset($attachment)) $attachment = $part;
7056
+				if (!isset($attachment))
7057
+				{
7058
+					$attachment = $part;
7059
+				}
5973 7060
 				// do we want content fetched, can be done later, if not needed
5974 7061
 				if (isset($_stream))
5975 7062
 				{
5976 7063
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5977 7064
 				}
5978
-				if (isset($attachment)) break;
7065
+				if (isset($attachment))
7066
+				{
7067
+					break;
7068
+				}
5979 7069
 			}
5980 7070
 		}
5981 7071
 		// set name as filename, if not set
@@ -6006,10 +7096,17 @@  discard block
 block discarded – undo
6006 7096
 	 */
6007 7097
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
6008 7098
 	{
6009
-		if (is_null($part)) return null;//new Horde_Mime_Part;
7099
+		if (is_null($part))
7100
+		{
7101
+			return null;
7102
+		}
7103
+		//new Horde_Mime_Part;
6010 7104
 		$encoding = null;
6011 7105
 		$fetchAsBinary = true;
6012
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
7106
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
7107
+		{
7108
+			$fetchAsBinary = false;
7109
+		}
6013 7110
 		// we need to set content on structure to decode transfer encoding
6014 7111
 		$part->setContents(
6015 7112
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -6046,7 +7143,10 @@  discard block
 block discarded – undo
6046 7143
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
6047 7144
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
6048 7145
 		// for flags at all)
6049
-		if (empty($_flags)) $_flags = '\\Recent';
7146
+		if (empty($_flags))
7147
+		{
7148
+			$_flags = '\\Recent';
7149
+		}
6050 7150
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
6051 7151
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
6052 7152
 		try
@@ -6063,18 +7163,27 @@  discard block
 block discarded – undo
6063 7163
 		}
6064 7164
 		catch (\Exception $e)
6065 7165
 		{
6066
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7166
+			if (self::$debug)
7167
+			{
7168
+				error_log("Could not append Message: ".$e->getMessage());
7169
+			}
6067 7170
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
6068 7171
 			//return false;
6069 7172
 		}
6070 7173
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
6071 7174
 		//$messageid = true; // for debug reasons only
6072
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7175
+		if ($messageid === true || empty($messageid))
7176
+		{
7177
+			// try to figure out the message uid
6073 7178
 		{
6074 7179
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7180
+		}
6075 7181
 			if ($list)
6076 7182
 			{
6077
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7183
+				if (self::$debug)
7184
+				{
7185
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7186
+				}
6078 7187
 				$messageid = $list['header'][0]['uid'];
6079 7188
 			}
6080 7189
 		}
@@ -6115,7 +7224,10 @@  discard block
 block discarded – undo
6115 7224
 	{
6116 7225
 			//echo __METHOD__." called for $uid,$partid <br>";
6117 7226
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6118
-			if (empty($headers)) return false;
7227
+			if (empty($headers))
7228
+			{
7229
+				return false;
7230
+			}
6119 7231
 			// dont force retrieval of the textpart, let mailClass preferences decide
6120 7232
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6121 7233
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6133,15 +7245,30 @@  discard block
 block discarded – undo
6133 7245
 			//error_log(array2string($bodyParts));
6134 7246
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6135 7247
 
6136
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6137
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6138
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6139
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7248
+			if ($mailClass->isSentFolder($mailbox))
7249
+			{
7250
+				$mailaddress = $headers['TO'];
7251
+			}
7252
+			elseif (isset($headers['FROM']))
7253
+			{
7254
+				$mailaddress = $headers['FROM'];
7255
+			}
7256
+			elseif (isset($headers['SENDER']))
7257
+			{
7258
+				$mailaddress = $headers['SENDER'];
7259
+			}
7260
+			if (isset($headers['CC']))
7261
+			{
7262
+				$mailaddress .= ','.$headers['CC'];
7263
+			}
6140 7264
 			//_debug_array(array($headers,$mailaddress));
6141 7265
 			$subject = $headers['SUBJECT'];
6142 7266
 
6143 7267
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6144
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7268
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7269
+			{
7270
+				$message = '<pre>'.$message.'</pre>';
7271
+			}
6145 7272
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6146 7273
 			$message = $headdata.$message;
6147 7274
 			//echo __METHOD__.'<br>';
@@ -6192,7 +7319,8 @@  discard block
 block discarded – undo
6192 7319
 							$attachments[$num]['attachment'] = $c->getContents();
6193 7320
 						}
6194 7321
 						// no attempt to convert, if we dont know about the charset
6195
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7322
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7323
+						{
6196 7324
 							// we do not try guessing the charset, if it is not set
6197 7325
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6198 7326
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6213,7 +7341,10 @@  discard block
 block discarded – undo
6213 7341
 						unset($attachments[$num]['attachment']);
6214 7342
 					}
6215 7343
 				}
6216
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7344
+				if (is_array($attachedMessages))
7345
+				{
7346
+					$attachments = array_merge($attachments,$attachedMessages);
7347
+				}
6217 7348
 			}
6218 7349
 			return array(
6219 7350
 					'mailaddress'=>$mailaddress,
@@ -6235,10 +7366,17 @@  discard block
 block discarded – undo
6235 7366
 	{
6236 7367
 		$c = 0;
6237 7368
 		// use the standardIdentity
6238
-		foreach($_identities as $key => $acc) {
6239
-			if ($c==0) $identity = $acc;
7369
+		foreach($_identities as $key => $acc)
7370
+		{
7371
+			if ($c==0)
7372
+			{
7373
+				$identity = $acc;
7374
+			}
6240 7375
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6241
-			if ($key==$_profile_id) $identity = $acc;
7376
+			if ($key==$_profile_id)
7377
+			{
7378
+				$identity = $acc;
7379
+			}
6242 7380
 			$c++;
6243 7381
 		}
6244 7382
 		return $identity;
@@ -6254,20 +7392,53 @@  discard block
 block discarded – undo
6254 7392
 	{
6255 7393
 		$headdata = null;
6256 7394
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6257
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6258
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6259
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6260
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6261
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6262
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6263
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6264
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6265
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7395
+		if ($header['SUBJECT'])
7396
+		{
7397
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7398
+		}
7399
+		if ($header['FROM'])
7400
+		{
7401
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7402
+		}
7403
+		if ($header['SENDER'])
7404
+		{
7405
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7406
+		}
7407
+		if ($header['TO'])
7408
+		{
7409
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7410
+		}
7411
+		if ($header['CC'])
7412
+		{
7413
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7414
+		}
7415
+		if ($header['BCC'])
7416
+		{
7417
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7418
+		}
7419
+		if ($header['DATE'])
7420
+		{
7421
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7422
+		}
7423
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7424
+		{
7425
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7426
+		}
7427
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7428
+		{
7429
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7430
+		}
6266 7431
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6267 7432
 		if (!empty($headdata))
6268 7433
 		{
6269
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6270
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7434
+			if (!empty($headline) && $headline != 'SUPPRESS')
7435
+			{
7436
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7437
+			}
7438
+			if (empty($headline))
7439
+			{
7440
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7441
+			}
6271 7442
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6272 7443
 		}
6273 7444
 		else
@@ -6301,12 +7472,15 @@  discard block
 block discarded – undo
6301 7472
 		$returnAddr ='';
6302 7473
 		if (is_array($rfcAddressArray))
6303 7474
 		{
6304
-			foreach((array)$rfcAddressArray as $addressData) {
7475
+			foreach((array)$rfcAddressArray as $addressData)
7476
+			{
6305 7477
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6306
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7478
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7479
+				{
6307 7480
 					continue;
6308 7481
 				}
6309
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7482
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7483
+				{
6310 7484
 					continue;
6311 7485
 				}
6312 7486
 				if ($addressData['RFC822_EMAIL'])
@@ -6320,7 +7494,10 @@  discard block
 block discarded – undo
6320 7494
 				}
6321 7495
 				$addressObject = $addressObjectA[0];
6322 7496
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6323
-				if (!$addressObject->valid) continue;
7497
+				if (!$addressObject->valid)
7498
+				{
7499
+					continue;
7500
+				}
6324 7501
 				//$mb =(string)$addressObject->mailbox;
6325 7502
 				//$h = (string)$addressObject->host;
6326 7503
 				//$p = (string)$addressObject->personal;
@@ -6337,7 +7514,10 @@  discard block
 block discarded – undo
6337 7514
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6338 7515
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6339 7516
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6340
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7517
+			if (is_string($rfcAddressArray))
7518
+			{
7519
+				return $rfcAddressArray;
7520
+			}
6341 7521
 		}
6342 7522
 		return $returnAddr;
6343 7523
 	}
@@ -6354,10 +7534,19 @@  discard block
 block discarded – undo
6354 7534
 	{
6355 7535
 		$mergeobj = new Contacts\Merge();
6356 7536
 
6357
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7537
+		if (empty($mimetype))
7538
+		{
7539
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7540
+		}
6358 7541
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6359
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6360
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7542
+		if (empty($rv) && !empty($content) && !empty($err))
7543
+		{
7544
+			$rv = $content;
7545
+		}
7546
+		if (!empty($err) && !empty($content) && !empty($ids))
7547
+		{
7548
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7549
+		}
6361 7550
 		return $rv;
6362 7551
 	}
6363 7552
 
@@ -6394,13 +7583,15 @@  discard block
 block discarded – undo
6394 7583
 			settype($bytes, 'integer');
6395 7584
 			$bytes /= 10;
6396 7585
 		}
6397
-		else
6398
-			settype($bytes, 'integer');
7586
+		else {
7587
+					settype($bytes, 'integer');
7588
+		}
6399 7589
 
6400 7590
 		return $bytes . ' ' . $type ;
6401 7591
 	}
6402 7592
 
6403
-	static function detect_qp(&$sting) {
7593
+	static function detect_qp(&$sting)
7594
+	{
6404 7595
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6405 7596
 		return preg_match("$needle",$string);
6406 7597
 	}
@@ -6417,9 +7608,15 @@  discard block
 block discarded – undo
6417 7608
 	 */
6418 7609
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6419 7610
 	{
6420
-		if (is_null($_endtime)) $_endtime = microtime(true);
7611
+		if (is_null($_endtime))
7612
+		{
7613
+			$_endtime = microtime(true);
7614
+		}
6421 7615
 		$usagetime = microtime(true) - $_starttime;
6422
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7616
+		if (self::$debugTimes)
7617
+		{
7618
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7619
+		}
6423 7620
 	}
6424 7621
 
6425 7622
 	/**
@@ -6434,7 +7631,10 @@  discard block
 block discarded – undo
6434 7631
 	 */
6435 7632
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6436 7633
 	{
6437
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7634
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7635
+		{
7636
+			return $_formData['file'];
7637
+		}
6438 7638
 
6439 7639
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6440 7640
 		$importfailed = $tmpFileName = false;
@@ -6483,8 +7683,15 @@  discard block
 block discarded – undo
6483 7683
 			{
6484 7684
 				$buff = explode('.',$_formData['name']);
6485 7685
 				$suffix = '';
6486
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6487
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7686
+				if (is_array($buff))
7687
+				{
7688
+					$suffix = array_pop($buff);
7689
+				}
7690
+				// take the last extension to check with ext2mime
7691
+				if (!empty($suffix))
7692
+				{
7693
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7694
+				}
6488 7695
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6489 7696
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6490 7697
 				{
@@ -6532,7 +7739,9 @@  discard block
 block discarded – undo
6532 7739
 			{
6533 7740
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6534 7741
 			}
6535
-		} else {
7742
+		}
7743
+		else
7744
+		{
6536 7745
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6537 7746
 			$importfailed = true;
6538 7747
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6578,21 +7787,32 @@  discard block
 block discarded – undo
6578 7787
 				if (substr($url, 0, 5) !== 'data:')
6579 7788
 				{
6580 7789
 					$filename = basename($url);
6581
-					if (($directory = dirname($url)) == '.') $directory = '';
7790
+					if (($directory = dirname($url)) == '.')
7791
+					{
7792
+						$directory = '';
7793
+					}
6582 7794
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6583 7795
 					$mimeType  = MimeMagic::ext2mime($ext);
6584
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7796
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7797
+					{
7798
+$directory .= '/'; }
6585 7799
 					$myUrl = $directory.$filename;
6586
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7800
+					if ($myUrl[0]=='/')
7801
+					{
7802
+						// local path -> we only allow path's that are available via http/https (or vfs)
6587 7803
 					{
6588 7804
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6589 7805
 					}
7806
+					}
6590 7807
 					// use vfs instead of url containing webdav.php
6591 7808
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6592 7809
 					// webdav.php urls as vfs
6593
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7810
+					if (strpos($myUrl,'/webdav.php') !== false)
7811
+					{
7812
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6594 7813
 					{
6595 7814
 						Vfs::load_wrapper('vfs');
7815
+					}
6596 7816
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6597 7817
 						$basedir = 'vfs://default';
6598 7818
 						$needTempFile = false;
@@ -6621,8 +7841,13 @@  discard block
 block discarded – undo
6621 7841
 						}
6622 7842
 					}
6623 7843
 
6624
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6625
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7844
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7845
+					{
7846
+$basedir .= '/'; }
7847
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7848
+					{
7849
+						$data = file_get_contents($basedir.urldecode($myUrl));
7850
+					}
6626 7851
 				}
6627 7852
 				if (substr($url,0,strlen('data:'))=='data:')
6628 7853
 				{
@@ -6723,7 +7948,10 @@  discard block
 block discarded – undo
6723 7948
 				$_folder = $this->getSentFolder();
6724 7949
 			}
6725 7950
 			$delimiter = $this->getHierarchyDelimiter();
6726
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7951
+			if($_folder=='INBOX'.$delimiter)
7952
+			{
7953
+				$_folder='INBOX';
7954
+			}
6727 7955
 			if ($importfailed === false)
6728 7956
 			{
6729 7957
 				$Subject = $mailObject->getHeader('Subject');
@@ -6752,7 +7980,9 @@  discard block
 block discarded – undo
6752 7980
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6753 7981
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6754 7982
 						count($SendAndMergeTocontacts) > 1 && $val &&
6755
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7983
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7984
+					{
7985
+						// do the merge
6756 7986
 					{
6757 7987
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6758 7988
 
@@ -6761,6 +7991,7 @@  discard block
 block discarded – undo
6761 7991
 						{
6762 7992
 							//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));
6763 7993
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7994
+					}
6764 7995
 							$mailObject->addAddress($merged,'',$type);
6765 7996
 							if($type == 'to')
6766 7997
 							{
@@ -6792,9 +8023,15 @@  discard block
 block discarded – undo
6792 8023
 						$mailObject->clearCustomHeaders();
6793 8024
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6794 8025
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6795
-						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));
8026
+						if($text_body)
8027
+						{
8028
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8029
+						}
6796 8030
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6797
-						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));
8031
+						if($html_body)
8032
+						{
8033
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8034
+						}
6798 8035
 
6799 8036
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6800 8037
 						// set a higher timeout for big messages
@@ -6809,9 +8046,12 @@  discard block
 block discarded – undo
6809 8046
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6810 8047
 						}
6811 8048
 					}
6812
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
8049
+					elseif (!$k)
8050
+					{
8051
+						// 1. entry, further entries will fail for apps other then addressbook
6813 8052
 					{
6814 8053
 						$openAsDraft = true;
8054
+					}
6815 8055
 						$mailObject->removeHeader('Message-ID');
6816 8056
 						$mailObject->removeHeader('Date');
6817 8057
 						$mailObject->clearCustomHeaders();
@@ -6826,9 +8066,12 @@  discard block
 block discarded – undo
6826 8066
 
6827 8067
 						// No addresses from placeholders?  Treat it as just a contact ID
6828 8068
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6829
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
8069
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
8070
+						{
8071
+							// do the merge
6830 8072
 						{
6831 8073
 							$contact = $bo_merge->contacts->read($val);
8074
+						}
6832 8075
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6833 8076
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6834 8077
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6839,9 +8082,15 @@  discard block
 block discarded – undo
6839 8082
 						}
6840 8083
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6841 8084
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6842
-						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));
8085
+						if (!empty($Body))
8086
+						{
8087
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8088
+						}
6843 8089
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6844
-						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));
8090
+						if (!empty($AltBody))
8091
+						{
8092
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8093
+						}
6845 8094
 						$_folder = $this->getDraftFolder();
6846 8095
 					}
6847 8096
 					if ($sendOK || $openAsDraft)
@@ -6849,11 +8098,15 @@  discard block
 block discarded – undo
6849 8098
 						if ($this->folderExists($_folder,true))
6850 8099
 						{
6851 8100
 						    if($this->isSentFolder($_folder))
6852
-							{
8101
+						    {
6853 8102
 						        $flags = '\\Seen';
6854
-						    } elseif($this->isDraftFolder($_folder)) {
8103
+						    }
8104
+						    elseif($this->isDraftFolder($_folder))
8105
+						    {
6855 8106
 						        $flags = '\\Draft';
6856
-						    } else {
8107
+						    }
8108
+						    else
8109
+						    {
6857 8110
 						        $flags = '';
6858 8111
 						    }
6859 8112
 							$savefailed = false;
@@ -6887,7 +8140,10 @@  discard block
 block discarded – undo
6887 8140
 						}
6888 8141
 						else
6889 8142
 						{
6890
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8143
+							if (!$openComposeWindow)
8144
+							{
8145
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8146
+							}
6891 8147
 						}
6892 8148
 					}
6893 8149
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6935,7 +8191,10 @@  discard block
 block discarded – undo
6935 8191
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6936 8192
 				break;
6937 8193
 		}
6938
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8194
+		if (!isset($message))
8195
+		{
8196
+			$message = fopen($tmpFileName, 'r');
8197
+		}
6939 8198
 
6940 8199
 		if (!$message)
6941 8200
 		{
@@ -6966,7 +8225,10 @@  discard block
 block discarded – undo
6966 8225
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6967 8226
 
6968 8227
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6969
-			if ($length===false) $length = strlen($start);
8228
+			if ($length===false)
8229
+			{
8230
+				$length = strlen($start);
8231
+			}
6970 8232
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6971 8233
 
6972 8234
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6995,7 +8257,10 @@  discard block
 block discarded – undo
6995 8257
 		}
6996 8258
 		else
6997 8259
 		{
6998
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8260
+			if (($type = gettype($message)) == 'object')
8261
+			{
8262
+				$type = get_class ($message);
8263
+			}
6999 8264
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
7000 8265
 		}
7001 8266
 	}
@@ -7019,7 +8284,9 @@  discard block
 block discarded – undo
7019 8284
 			$matches = array();
7020 8285
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
7021 8286
 			//error_log(__METHOD__.__LINE__.array2string($matches));
7022
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8287
+			foreach ($matches[0] as &$match)
8288
+			{
8289
+$match = trim($match,', ');}
7023 8290
 			$addresses = implode(',',$matches[0]);
7024 8291
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
7025 8292
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -7050,7 +8317,10 @@  discard block
 block discarded – undo
7050 8317
 			}
7051 8318
 			else
7052 8319
 			{
7053
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8320
+				if ($previousFailed && $remember)
8321
+				{
8322
+					$adr->personal = $remember. ' ' . $adr->personal;
8323
+				}
7054 8324
 				$remember = '';
7055 8325
 				$previousFailed=false;
7056 8326
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -7072,7 +8342,10 @@  discard block
 block discarded – undo
7072 8342
 	{
7073 8343
 		$acc = Mail\Account::read($this->profileID);
7074 8344
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
7075
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8345
+		if (self::$debug)
8346
+		{
8347
+			error_log(__METHOD__.__LINE__.array2string($identity));
8348
+		}
7076 8349
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
7077 8350
 
7078 8351
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.
mail/inc/class.mail_zpush.inc.php 1 patch
Spacing   +353 added lines, -354 removed lines patch added patch discarded remove patch
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 		$this->backend = $backend;
88 88
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
89 89
 		{
90
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
90
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
91 91
 			// globals preferences add appname varname value
92
-			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
92
+			$GLOBALS['egw']->preferences->add('activesync', 'mail-ActiveSyncProfileID', 0, 'user');
93 93
 			// save prefs
94 94
 			$GLOBALS['egw']->preferences->save_repository(true);
95 95
 		}
96
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
96
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
97 97
 
98 98
 		if (is_null(self::$profileID))
99 99
 		{
100
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
101
-			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
102
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
100
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
101
+			self::$profileID = & Api\Cache::getSession('mail', 'activeSyncProfileID');
102
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
103 103
 		}
104 104
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
105 105
 		{
106
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
106
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
107 107
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
108 108
 			{
109 109
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
114 114
 			}
115 115
 		}
116
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
116
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
117 117
 
118 118
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
119 119
 		if (!isset($GLOBALS['egw_setup']))
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 			try {
122 122
 				Mail\Account::read(self::$profileID);
123 123
 			}
124
-			catch(Exception $e) {
124
+			catch (Exception $e) {
125 125
 				unset($e);
126 126
 				self::$profileID = Mail\Account::get_default_acc_id();
127 127
 			}
128 128
 		}
129
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
129
+		if ($this->debugLevel > 0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
130 130
 		//$this->debugLevel=0;
131 131
 	}
132 132
 
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
 			$this->__construct($this->backend);
215 215
 
216 216
 			try {
217
-				$this->_connect(0,true);
217
+				$this->_connect(0, true);
218 218
 				$this->_disconnect();
219 219
 
220 220
 				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
221 221
 				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
222 222
 			}
223
-			catch(Exception $e) {
223
+			catch (Exception $e) {
224 224
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
225 225
 			}
226 226
 			if ($errors)
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @param int $account integer id of account to use
239 239
 	 * @todo support different accounts
240 240
 	 */
241
-	private function _connect($account=0)
241
+	private function _connect($account = 0)
242 242
 	{
243 243
 		if (!$account) $account = self::$profileID ? self::$profileID : 0;
244 244
 		if ($this->mail && $this->account != $account) $this->_disconnect();
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 			$this->account = $account;
252 252
 			// todo: tell mail which account to use
253 253
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
254
-			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
254
+			$this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
255 255
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
256 256
 		}
257 257
 		else
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
260 260
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
261 261
 		}
262
-		$this->mail->openConnection(self::$profileID,false);
262
+		$this->mail->openConnection(self::$profileID, false);
263 263
 
264 264
 		$this->_wasteID = $this->mail->getTrashFolder(false);
265 265
 		//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	private function _disconnect()
276 276
 	{
277
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
277
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__);
278 278
 		if ($this->mail) $this->mail->closeConnection();
279 279
 
280 280
 		unset($this->mail);
@@ -290,24 +290,24 @@  discard block
 block discarded – undo
290 290
 	public function GetFolderList()
291 291
 	{
292 292
 		$folderlist = array();
293
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
293
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__);
294 294
 		/*foreach($available_accounts as $account)*/ $account = 0;
295 295
 		{
296 296
 			$this->_connect($account);
297
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
298
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
297
+			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false, $_alwaysGetDefaultFolders = true);
298
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($this->folders));
299 299
 
300 300
 			foreach ($this->folders as $folder => $folderObj) {
301
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
301
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' folder='.$folder);
302 302
 				$folderlist[] = $f = array(
303
-					'id'     => $this->createID($account,$folder),
303
+					'id'     => $this->createID($account, $folder),
304 304
 					'mod'    => $folderObj->shortDisplayName,
305
-					'parent' => $this->getParentID($account,$folder),
305
+					'parent' => $this->getParentID($account, $folder),
306 306
 				);
307
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
307
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($f));
308 308
 			}
309 309
 		}
310
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
310
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($folderlist));
311 311
 
312 312
 		return $folderlist;
313 313
 	}
@@ -356,59 +356,59 @@  discard block
 block discarded – undo
356 356
 		$ClientSideMeetingRequest = false;
357 357
 		$allowSendingInvitations = 'sendifnocalnotif';
358 358
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
359
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']=='nosend')
359
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] == 'nosend')
360 360
 		{
361 361
 			$allowSendingInvitations = false;
362 362
 		}
363 363
 		elseif (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
364
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']!='nosend')
364
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] != 'nosend')
365 365
 		{
366 366
 			$allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'];
367 367
 		}
368
-		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
368
+		$smartdata_task = ($smartdata->replyflag ? 'reply' : ($smartdata->forwardflag ? 'forward' : 'new'));
369 369
 
370
-   		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
371
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
370
+   		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.(isset($smartdata->mime) ? $smartdata->mime : "")."task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
371
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
372 372
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
373 373
 
374 374
 		// initialize our Mail
375
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
375
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
376 376
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
377 377
 		// use the standardIdentity
378
-		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
378
+		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles, self::$profileID);
379 379
 
380
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
380
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
381 381
 
382 382
 		// initialize the new Api\Mailer object for sending
383 383
 		$mailObject = new Api\Mailer(self::$profileID);
384
-		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime);
384
+		$this->mail->parseRawMessageIntoMailObject($mailObject, $smartdata->mime);
385 385
 		// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
386
-		$mailObject->Sender  = $activeMailProfile['ident_email'];
387
-		$mailObject->From 	= $activeMailProfile['ident_email'];
388
-		$mailObject->FromName = Mail::generateIdentityString($activeMailProfile,false);
386
+		$mailObject->Sender = $activeMailProfile['ident_email'];
387
+		$mailObject->From = $activeMailProfile['ident_email'];
388
+		$mailObject->FromName = Mail::generateIdentityString($activeMailProfile, false);
389 389
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
390 390
 
391 391
 
392 392
 		// prepare addressee list; moved the adding of addresses to the mailobject down
393 393
 		// to
394 394
 
395
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
395
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
396 396
 			if (!$addressObject->valid) continue;
397
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
397
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
398 398
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
399 399
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
400 400
 		}
401 401
 		// CC
402
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
402
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
403 403
 			if (!$addressObject->valid) continue;
404
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
404
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
405 405
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
406 406
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
407 407
 		}
408 408
 		// BCC
409
-		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
409
+		foreach (Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
410 410
 			if (!$addressObject->valid) continue;
411
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
411
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
412 412
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
413 413
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
414 414
 		}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 		$use_orgbody = false;
418 418
 
419 419
 		$k = 'Content-Type';
420
-		$ContentType =$mailObject->getHeader('Content-Type');
420
+		$ContentType = $mailObject->getHeader('Content-Type');
421 421
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
422 422
 		// if the message is a multipart message, then we should use the sent body
423 423
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -437,43 +437,43 @@  discard block
 block discarded – undo
437 437
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
438 438
 			$use_orgbody = true;
439 439
 		}
440
-		$Body =  $AltBody = "";
440
+		$Body = $AltBody = "";
441 441
 		// get body of the transmitted message
442 442
 		// if this is a simple message, no structure at all
443 443
 		if (preg_match("/text/i", $ContentType))
444 444
 		{
445
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
445
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
446 446
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
447
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
448
-			if  ($simpleBodyType == "text/plain")
447
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
448
+			if ($simpleBodyType == "text/plain")
449 449
 			{
450 450
 				$Body = $body;
451 451
 				$AltBody = "<pre>".nl2br($body)."</pre>";
452
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
452
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
453 453
 			}
454 454
 			else
455 455
 			{
456 456
 				$AltBody = $body;
457
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
458
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
457
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
458
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
459 459
 			}
460 460
 		}
461 461
 		else
462 462
 		{
463 463
 			// if this is a structured message
464 464
 			// prefer plain over html
465
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
465
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
466 466
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
467
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
467
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
468 468
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
469 469
 		}
470
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
471
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
470
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
471
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
472 472
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
473 473
 		// if this is a multipart message with a boundary, we must use the original body
474 474
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
475 475
         if ($use_orgbody) {
476
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
476
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
477 477
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
478 478
 			if (($cal_body = $mailObject->findBody('calendar')) &&
479 479
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -482,21 +482,21 @@  discard block
 block discarded – undo
482 482
 				{
483 483
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
484 484
 				}
485
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
485
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
486 486
 				$ClientSideMeetingRequest = true;
487 487
 			}
488 488
         }
489 489
 		// now handle the addressee list
490 490
 		$toCount = 0;
491 491
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
492
-		foreach((array)$toMailAddr as $address) {
493
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
494
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
492
+		foreach ((array)$toMailAddr as $address) {
493
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
494
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
495 495
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
496 496
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
497 497
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
498 498
 				{
499
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
499
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
500 500
 					continue;
501 501
 				}
502 502
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -504,29 +504,29 @@  discard block
 block discarded – undo
504 504
 			}
505 505
 		}
506 506
 		$ccCount = 0;
507
-		foreach((array)$ccMailAddr as $address) {
508
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
509
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
507
+		foreach ((array)$ccMailAddr as $address) {
508
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
509
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
510 510
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
511 511
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
512 512
 				$ccCount++;
513 513
 			}
514 514
 		}
515 515
 		$bccCount = 0;
516
-		foreach((array)$bccMailAddr as $address) {
517
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
518
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
516
+		foreach ((array)$bccMailAddr as $address) {
517
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
518
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
519 519
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
520 520
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
521 521
 				$bccCount++;
522 522
 			}
523 523
 		}
524 524
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
525
-		if ($toCount+$ccCount+$bccCount == 0)
525
+		if ($toCount + $ccCount + $bccCount == 0)
526 526
 		{
527 527
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
528 528
 		}
529
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
529
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
530 530
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
531 531
 /*
532 532
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -534,29 +534,29 @@  discard block
 block discarded – undo
534 534
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body (modified):'.$body);
535 535
 */
536 536
 		// add signature!! -----------------------------------------------------------------
537
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
537
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
538 538
 		try
539 539
 		{
540 540
 			$acc = Mail\Account::read($this->mail->icServer->ImapServerId);
541 541
 			//error_log(__METHOD__.__LINE__.array2string($acc));
542
-			$_signature = Mail\Account::read_identity($acc['ident_id'],true);
542
+			$_signature = Mail\Account::read_identity($acc['ident_id'], true);
543 543
 		}
544 544
 		catch (Exception $e)
545 545
 		{
546
-			$_signature=array();
546
+			$_signature = array();
547 547
 		}
548 548
 		$signature = $_signature['ident_signature'];
549 549
 		if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
550 550
 			$preferencesArray['disableRulerForSignatureSeparation']) ||
551
-			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) =='')
551
+			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) == '')
552 552
 		{
553 553
 			$disableRuler = true;
554 554
 		}
555 555
 		$beforePlain = $beforeHtml = "";
556
-		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
557
-		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
558
-		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
559
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
556
+		$beforeHtml = ($disableRuler ? '&nbsp;<br>' : '&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
557
+		$beforePlain = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
558
+		$sigText = Mail::merge($signature, array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
559
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Signature to use:'.$sigText);
560 560
 		$sigTextHtml = $beforeHtml.$sigText;
561 561
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
562 562
 		$isreply = $isforward = false;
@@ -568,26 +568,26 @@  discard block
 block discarded – undo
568 568
 		{
569 569
 			// now get on, and fetch the original mail
570 570
 			$uid = $smartdata->source->itemid;
571
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
571
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
572 572
 			$this->splitID($smartdata->source->folderid, $account, $folder);
573 573
 
574 574
 			$this->mail->reopen($folder);
575 575
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
576
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
577
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
578
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
576
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
577
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
578
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
579 579
 				// may be html
580
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
580
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
581 581
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
582 582
 				$isreply = true;
583 583
 			}
584 584
 			// plain text Message part
585
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
585
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
586 586
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
587
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
588
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
589
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
590
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
587
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
588
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
589
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
590
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
591 591
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
592 592
 				$isreply = true;
593 593
 			}
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
 			{
596 596
 				$isreply = true;
597 597
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
598
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
598
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
599 599
 			}
600 600
 		}
601 601
 
602 602
 		// how to forward and other prefs
603
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
603
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
604 604
 
605 605
 		// forward -------------------------------------------------------------------------
606 606
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		{
611 611
 			//force the default for the forwarding -> asmail
612 612
 			if (is_array($preferencesArray)) {
613
-				if (!array_key_exists('message_forwarding',$preferencesArray)
613
+				if (!array_key_exists('message_forwarding', $preferencesArray)
614 614
 					|| !isset($preferencesArray['message_forwarding'])
615 615
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
616 616
 			} else {
@@ -618,18 +618,18 @@  discard block
 block discarded – undo
618 618
 			}
619 619
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
620 620
 			$uid = $smartdata->source->itemid;
621
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
621
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
622 622
 			$this->splitID($smartdata->source->folderid, $account, $folder);
623 623
 
624 624
 			$this->mail->reopen($folder);
625 625
             // receive entire mail (header + body)
626 626
 			// get message headers for specified message
627
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
627
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
628 628
 			// build a new mime message, forward entire old mail as file
629 629
 			if ($preferencesArray['message_forwarding'] == 'asmail')
630 630
 			{
631
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
632
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
631
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
632
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
633 633
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
634 634
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
635 635
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -639,50 +639,50 @@  discard block
 block discarded – undo
639 639
 			{
640 640
 				// now get on, and fetch the original mail
641 641
 				$uid = $smartdata->source->itemid;
642
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
642
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
643 643
 				$this->splitID($smartdata->source->folderid, $account, $folder);
644 644
 
645 645
 				$this->mail->reopen($folder);
646 646
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
647
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
648
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
649
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
647
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
648
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
649
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
650 650
 					// may be html
651
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
651
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
652 652
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
653 653
 					$isforward = true;
654 654
 				}
655 655
 				// plain text Message part
656
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
656
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
657 657
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
658
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
659
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
660
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
661
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
658
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
659
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
660
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
661
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
662 662
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
663 663
 					$isforward = true;
664 664
 				}
665 665
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
666 666
 				{
667 667
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
668
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
668
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
669 669
 					$isforward = true;
670 670
 				}
671 671
 				// get all the attachments and add them too.
672 672
 				// start handle Attachments
673 673
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
674
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
674
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
675 675
 				$attachmentNames = false;
676
-				if (is_array($attachments) && count($attachments)>0)
676
+				if (is_array($attachments) && count($attachments) > 0)
677 677
 				{
678
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
679
-					foreach((array)$attachments as $key => $attachment)
678
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
679
+					foreach ((array)$attachments as $key => $attachment)
680 680
 					{
681
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
681
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
682 682
 						$attachmentNames .= $attachment['name']."\n";
683
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
683
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
684 684
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
685
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
685
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
686 686
 					}
687 687
 				}
688 688
 			}
@@ -696,36 +696,36 @@  discard block
 block discarded – undo
696 696
 		// now set the body
697 697
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
698 698
 		{
699
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
700
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
699
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
700
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
701 701
 		}
702 702
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
703 703
 		{
704
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
705
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
704
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
705
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
706 706
 		}
707 707
 		//advanced debugging
708 708
 		// Horde SMTP Class uses utf-8 by default.
709 709
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
710
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
710
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
711 711
 
712 712
 		// set a higher timeout for big messages
713 713
 		@set_time_limit(120);
714
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
714
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
715 715
 		// send
716 716
 		$send = true;
717 717
 		try {
718 718
 			$mailObject->Send();
719 719
 		}
720
-		catch(Exception $e) {
721
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
720
+		catch (Exception $e) {
721
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
722 722
 			$send = false;
723 723
 		}
724 724
 
725
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
725
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
726 726
 		{
727 727
 			$uid = $smartdata->source->itemid;
728
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
728
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
729 729
 			$this->splitID($smartdata->source->folderid, $account, $folder);
730 730
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
731 731
 			$this->mail->reopen($folder);
@@ -733,89 +733,89 @@  discard block
 block discarded – undo
733 733
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
734 734
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
735 735
 			{
736
-				$this->mail->deleteMessages(array($uid),$folder);
736
+				$this->mail->deleteMessages(array($uid), $folder);
737 737
 			} else {
738
-				$this->mail->flagMessages("answered", array($uid),$folder);
739
-				if ($smartdata_task== "forward")
738
+				$this->mail->flagMessages("answered", array($uid), $folder);
739
+				if ($smartdata_task == "forward")
740 740
 				{
741
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
741
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
742 742
 				}
743 743
 			}
744 744
 		}
745 745
 
746
-		$asf = ($send ? true:false); // initalize accordingly
747
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
746
+		$asf = ($send ? true : false); // initalize accordingly
747
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
748 748
 		{
749 749
 			$asf = false;
750 750
 			$sentFolder = $this->mail->getSentFolder();
751 751
 			if ($this->_sentID) {
752 752
 				$folderArray[] = $this->_sentID;
753 753
 			}
754
-			else if(isset($sentFolder) && $sentFolder != 'none')
754
+			else if (isset($sentFolder) && $sentFolder != 'none')
755 755
 			{
756 756
 				$folderArray[] = $sentFolder;
757 757
 			}
758 758
 			// No Sent folder set, try defaults
759 759
 			else
760 760
 			{
761
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
761
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
762 762
 				// we dont try guessing
763 763
 				$asf = true;
764 764
 			}
765 765
 			if (count($folderArray) > 0) {
766
-				foreach((array)$bccMailAddr as $address) {
767
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
768
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
766
+				foreach ((array)$bccMailAddr as $address) {
767
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
768
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
769 769
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
770 770
 					}
771 771
 				}
772
-				$BCCmail='';
773
-				if (count($mailAddr)>0) $BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
774
-				foreach($folderArray as $folderName) {
775
-					if($this->mail->isSentFolder($folderName)) {
772
+				$BCCmail = '';
773
+				if (count($mailAddr) > 0) $BCCmail = $mailObject->AddrAppend("Bcc", $mailAddr);
774
+				foreach ($folderArray as $folderName) {
775
+					if ($this->mail->isSentFolder($folderName)) {
776 776
 						$flags = '\\Seen';
777
-					} elseif($this->mail->isDraftFolder($folderName)) {
777
+					} elseif ($this->mail->isDraftFolder($folderName)) {
778 778
 						$flags = '\\Draft';
779 779
 					} else {
780 780
 						$flags = '';
781 781
 					}
782 782
 					$asf = true;
783 783
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
784
-					$this->mail->openConnection(self::$profileID,false);
784
+					$this->mail->openConnection(self::$profileID, false);
785 785
 					if ($this->mail->folderExists($folderName)) {
786 786
 						try
787 787
 						{
788
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
788
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
789 789
 									$flags);
790 790
 						}
791 791
 						catch (Api\Exception\WrongUserinput $e)
792 792
 						{
793 793
 							//$asf = false;
794
-							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$mailObject->getHeader('Subject'),$folderName,$e->getMessage()));
794
+							ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $mailObject->getHeader('Subject'), $folderName, $e->getMessage()));
795 795
 						}
796 796
 					}
797 797
 					else
798 798
 					{
799 799
 						//$asf = false;
800
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
800
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
801 801
 					}
802
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
802
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
803 803
 				}
804 804
 				//$this->mail->closeConnection();
805 805
 			}
806 806
 		}
807 807
 
808
-		$this->debugLevel=0;
808
+		$this->debugLevel = 0;
809 809
 
810 810
 		if ($send && $asf)
811 811
 		{
812
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
812
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
813 813
 			return true;
814 814
 		}
815 815
 		else
816 816
 		{
817
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
818
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
817
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
818
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
819 819
 		}
820 820
 	}
821 821
 
@@ -833,48 +833,48 @@  discard block
 block discarded – undo
833 833
 	public function GetMessage($folderid, $id, $contentparameters)
834 834
 	{
835 835
 		//$this->debugLevel=4;
836
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
836
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
837 837
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
838 838
 		$mimesupport = $contentparameters->GetMimeSupport();
839
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
839
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
840 840
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
841 841
 
842 842
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
843 843
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
844 844
 
845 845
 		//$this->debugLevel=4;
846
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
847
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
846
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
847
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
848 848
 		$account = $_folderName = $xid = null;
849
-		$this->splitID($folderid,$account,$_folderName,$xid);
849
+		$this->splitID($folderid, $account, $_folderName, $xid);
850 850
 		$this->mail->reopen($_folderName);
851 851
 		$stat = $this->StatMessage($folderid, $id);
852
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($stat));
852
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($stat));
853 853
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
854 854
 		if ($stat)
855 855
 		{
856
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($stat));
856
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($stat));
857 857
 			// initialize the object
858 858
 			$output = new SyncMail();
859
-			$headers = $this->mail->getMessageHeader($id,'',true,true,$_folderName);
859
+			$headers = $this->mail->getMessageHeader($id, '', true, true, $_folderName);
860 860
 			if (empty($headers))
861 861
 			{
862 862
 				error_log(__METHOD__.__LINE__.' Retrieval of Headers Failed! for .'.$this->account.'/'.$GLOBALS['egw_info']['user']['account_lid'].' ServerID:'.self::$profileID.'FolderID:'.$folderid.'/'.$_folderName.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference).' Stat was:'.array2string($stat));
863
-				return $output;//empty object
863
+				return $output; //empty object
864 864
 			}
865 865
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
866 866
 			// simple style
867 867
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
868
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
868
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
869 869
 
870 870
 			if ($bodypreference === false) {
871
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
872
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
871
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
872
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
873 873
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
874
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
874
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
875 875
 				// remove all other html
876 876
 				$body = strip_tags($raw_body);
877
-				if(strlen($body) > $truncsize) {
877
+				if (strlen($body) > $truncsize) {
878 878
 					$body = Utils::Utf8_truncate($body, $truncsize);
879 879
 					$output->bodytruncated = 1;
880 880
 				}
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 			else // style with bodypreferences
889 889
 			{
890 890
 				//Select body type preference
891
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
891
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
892 892
 				if ($bodypreference !== false) {
893 893
 					// bodypreference can occur multiple times
894 894
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -902,69 +902,69 @@  discard block
 block discarded – undo
902 902
 					}
903 903
 */
904 904
 				}
905
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
905
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
906 906
 				// set the protocoll class
907 907
 				$output->asbody = new SyncBaseBody();
908 908
 				// fetch the body (try to gather data only once)
909
-				$css ='';
910
-				$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
911
-				if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
912
-				$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
913
-				if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
914
-				if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
909
+				$css = '';
910
+				$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
911
+				if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
912
+				$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
913
+				if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
914
+				if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
915 915
 					// may be html
916
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
916
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
917 917
 					$css = $this->mail->getStyles($bodyStruct);
918
-					$output->nativebodytype=2;
918
+					$output->nativebodytype = 2;
919 919
 				} else {
920 920
 					// plain text Message
921
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
922
-					$output->nativebodytype=1;
923
-					$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
924
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
925
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
926
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
921
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
922
+					$output->nativebodytype = 1;
923
+					$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
924
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
925
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
926
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
927 927
 				}
928 928
 				// whatever format decode (using the correct encoding)
929
-				if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
929
+				if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
930 930
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
931 931
 				// prepare plaintextbody
932
-				$plainBody='';
932
+				$plainBody = '';
933 933
 				if ($output->nativebodytype == 2)
934 934
 				{
935
-					$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
936
-					if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
935
+					$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
936
+					if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
937 937
 					{
938 938
 						$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
939 939
 					}
940 940
 					else
941 941
 					{
942
-						$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
942
+						$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
943 943
 					}
944 944
 				}
945 945
 				//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
946
-				$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
946
+				$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
947 947
 				// remove all other html
948
-				$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
948
+				$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
949 949
 				$plainBody = strip_tags($plainBody);
950
-				if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
950
+				if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
951 951
 				//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
952
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)//4)//$mimesupport==2 || $mimesupport ==1 && stristr($headers['CONTENT-TYPE'],'signed') !== false)
952
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)//4)//$mimesupport==2 || $mimesupport ==1 && stristr($headers['CONTENT-TYPE'],'signed') !== false)
953 953
 				{
954 954
 					//SYNC_BODYPREFERENCE_MIME
955
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4 requested");
956
-					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;//4;
955
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4 requested");
956
+					$output->asbody->type = SYNC_BODYPREFERENCE_MIME; //4;
957 957
 					// use Api\Mailer::convert to convert charset of all text parts to utf-8, which is a z-push or AS requirement!
958 958
 					// ToDo: check if above is true for mime-message, otherwise with could use a stream without conversion
959 959
 					$Body = Api\Mailer::convert($this->mail->getMessageRawBody($id, '', $_folderName));
960
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Setting Mailobjectcontent to output:".$Body);
960
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Setting Mailobjectcontent to output:".$Body);
961 961
 					if ((string)$Body === '') $Body = ' ';
962 962
 					$output->asbody->data = StringStreamWrapper::Open($Body);
963 963
 					$output->asbody->estimatedDataSize = strlen($Body);
964 964
 				}
965
-				else if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
965
+				else if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
966 966
 				{
967
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
967
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
968 968
 					// Send HTML if requested and native type was html
969 969
 					$output->asbody->type = 2;
970 970
 					$htmlbody = '<html>'.
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 						$css.
975 975
 						'</head>'.
976 976
 						'<body>';
977
-					if ($output->nativebodytype==2)
977
+					if ($output->nativebodytype == 2)
978 978
 					{
979 979
 						// as we fetch html, and body is HTML, we may not need to handle this
980 980
 						$htmlbody .= $body;
@@ -982,14 +982,14 @@  discard block
 block discarded – undo
982 982
 					else
983 983
 					{
984 984
 						// html requested but got only plaintext, so fake html
985
-						$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
985
+						$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
986 986
 					}
987 987
 					$htmlbody .= '</body>'.
988 988
 							'</html>';
989 989
 
990
-					if(isset($truncsize) && strlen($htmlbody) > $truncsize)
990
+					if (isset($truncsize) && strlen($htmlbody) > $truncsize)
991 991
 					{
992
-						$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
992
+						$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
993 993
 						$output->asbody->truncated = 1;
994 994
 					}
995 995
 					// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 				else
1001 1001
 				{
1002 1002
 					// Send Plaintext as Fallback or if original body is plainttext
1003
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1003
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1004 1004
 					/* we use plainBody (set above) instead
1005 1005
 					$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1006 1006
 					$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 					*/
1011 1011
 					$output->asbody->type = 1;
1012 1012
 					$output->nativebodytype = 1;
1013
-					if(isset($truncsize) &&
1013
+					if (isset($truncsize) &&
1014 1014
 			    		strlen($plainBody) > $truncsize)
1015 1015
 					{
1016 1016
 						$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
 				}
1029 1029
 			}
1030 1030
 			// end AS12 Stuff
1031
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
1031
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
1032 1032
 			$output->read = $stat["flags"];
1033 1033
 
1034 1034
 			$output->flag = new SyncMailFlags();
@@ -1048,20 +1048,19 @@  discard block
 block discarded – undo
1048 1048
 				$output->lastverexecuted = AS_FORWARD;
1049 1049
 			}
1050 1050
 			$output->subject = $this->messages[$id]['subject'];
1051
-			$output->importance = $this->messages[$id]['priority'] > 3 ? 0 :
1052
-				($this->messages[$id]['priority'] < 3 ? 2 : 1) ;
1053
-			$output->datereceived = $this->mail->_strtotime($headers['DATE'],'ts',true);
1051
+			$output->importance = $this->messages[$id]['priority'] > 3 ? 0 : ($this->messages[$id]['priority'] < 3 ? 2 : 1);
1052
+			$output->datereceived = $this->mail->_strtotime($headers['DATE'], 'ts', true);
1054 1053
 //error_log(__METHOD__.__LINE__.' To:'.$headers['TO']);
1055 1054
 			$output->to = $headers['TO'];
1056
-			if ($headers['TO']) $output->displayto = ($headers['TO'] ? $headers['TO']:null); //$stat['FETCHED_HEADER']['to_name']
1055
+			if ($headers['TO']) $output->displayto = ($headers['TO'] ? $headers['TO'] : null); //$stat['FETCHED_HEADER']['to_name']
1057 1056
 //error_log(__METHOD__.__LINE__.' From:'.$headers['FROM']);
1058 1057
 			$output->from = $headers['FROM'];
1059
-			if (isset($headers['CC']) && $headers['CC']) $output->cc = ($headers['CC'] ? $headers['CC']:null);
1060
-			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO']) $output->reply_to = ($headers['REPLY_TO']?$headers['REPLY_TO']:null);
1058
+			if (isset($headers['CC']) && $headers['CC']) $output->cc = ($headers['CC'] ? $headers['CC'] : null);
1059
+			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO']) $output->reply_to = ($headers['REPLY_TO'] ? $headers['REPLY_TO'] : null);
1061 1060
 
1062 1061
 			$output->messageclass = "IPM.Note";
1063
-			if (stripos($this->messages[$id]['mimetype'],'multipart')!== false &&
1064
-				stripos($this->messages[$id]['mimetype'],'signed')!== false)
1062
+			if (stripos($this->messages[$id]['mimetype'], 'multipart') !== false &&
1063
+				stripos($this->messages[$id]['mimetype'], 'signed') !== false)
1065 1064
 			{
1066 1065
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1067 1066
 			}
@@ -1070,20 +1069,20 @@  discard block
 block discarded – undo
1070 1069
 			}
1071 1070
 
1072 1071
 			// start handle Attachments (include text/calendar multipart alternative)
1073
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1072
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1074 1073
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1075
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1074
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1076 1075
 			{
1077
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1076
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1078 1077
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1079 1078
 				foreach ($attachments as $key => $attach)
1080 1079
 				{
1081
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1080
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1082 1081
 
1083 1082
 					// pass meeting requests to calendar plugin
1084 1083
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1085 1084
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1086
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1085
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1087 1086
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1088 1087
 					{
1089 1088
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1093,7 +1092,7 @@  discard block
 block discarded – undo
1093 1092
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1094 1093
 						//$output->messageclass = "IPM.Schedule.Meeting";
1095 1094
 						unset($attachment);
1096
-						continue;	// do NOT add attachment as attachment
1095
+						continue; // do NOT add attachment as attachment
1097 1096
 					}
1098 1097
 					if (Request::GetProtocolVersion() >= 12.0) {
1099 1098
 						$attachment = new SyncBaseAttachment();
@@ -1101,33 +1100,33 @@  discard block
 block discarded – undo
1101 1100
 							$output->asattachments = array();
1102 1101
 						$attachment->estimatedDataSize = $attach['size'];
1103 1102
 						$attachment->method = 1;
1104
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1103
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1105 1104
 					} else {
1106 1105
 						$attachment = new SyncAttachment();
1107 1106
 						if (!isset($output->attachments) || !is_array($output->attachments))
1108 1107
 							$output->attachments = array();
1109 1108
 						$attachment->attsize = $attach['size'];
1110 1109
 						$attachment->attmethod = 1;
1111
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1110
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1112 1111
 					}
1113 1112
 
1114 1113
 					$attachment->displayname = $attach['name'];
1115 1114
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1116 1115
 
1117
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1116
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1118 1117
 					//$attachment->isinline=0; // if not inline, do not use isinline
1119
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1118
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1120 1119
 					{
1121 1120
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1122 1121
 						{
1123 1122
 							$attachment->isinline = true;
1124 1123
 						}
1125 1124
 						if (Request::GetProtocolVersion() >= 12.0) {
1126
-							$attachment->method=1;
1127
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1125
+							$attachment->method = 1;
1126
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1128 1127
 						} else {
1129
-							$attachment->attmethod=6;
1130
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1128
+							$attachment->attmethod = 6;
1129
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1131 1130
 						}
1132 1131
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1133 1132
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1148,7 +1147,7 @@  discard block
 block discarded – undo
1148 1147
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1149 1148
             $output->internetcpid = INTERNET_CPID_UTF8;
1150 1149
 
1151
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1150
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1152 1151
 //$this->debugLevel=0;
1153 1152
 			return $output;
1154 1153
 		}
@@ -1171,30 +1170,30 @@  discard block
 block discarded – undo
1171 1170
 	{
1172 1171
 		if (!class_exists('calendar_zpush'))
1173 1172
 		{
1174
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1173
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1175 1174
 			return null;
1176 1175
 		}
1177 1176
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1178 1177
 		{
1179
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1178
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1180 1179
 			return false;
1181 1180
 		}
1182 1181
 		$ret = false;
1183
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1182
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1184 1183
 		{
1185 1184
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1186
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1185
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1187 1186
 			{
1188
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1187
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1189 1188
 
1190 1189
 				// calling backend again with iCal attachment, to let calendar add the event
1191 1190
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1192
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1191
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1193 1192
 					$response);
1194 1193
 				break;
1195 1194
 			}
1196 1195
 		}
1197
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1196
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1198 1197
 		return $ret;
1199 1198
 	}
1200 1199
 
@@ -1208,9 +1207,9 @@  discard block
 block discarded – undo
1208 1207
      * @param string $attname - should contain (folder)id
1209 1208
 	 * @return SyncItemOperationsAttachment-object
1210 1209
 	 */
1211
-	function GetAttachmentData($fid,$attname) {
1212
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1213
-		return $this->_GetAttachmentData($fid,$attname);
1210
+	function GetAttachmentData($fid, $attname) {
1211
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1212
+		return $this->_GetAttachmentData($fid, $attname);
1214 1213
 	}
1215 1214
 
1216 1215
 	/**
@@ -1223,9 +1222,9 @@  discard block
 block discarded – undo
1223 1222
      * @param string $attname - should contain (folder)id
1224 1223
 	 * @return SyncItemOperationsAttachment-object
1225 1224
 	 */
1226
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1227
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1228
-		return $this->_GetAttachmentData($fid,$attname);
1225
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1226
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1227
+		return $this->_GetAttachmentData($fid, $attname);
1229 1228
 	}
1230 1229
 
1231 1230
 	/**
@@ -1237,23 +1236,23 @@  discard block
 block discarded – undo
1237 1236
      * @param string $attname - should contain (folder)id
1238 1237
 	 * @return SyncItemOperationsAttachment-object
1239 1238
 	 */
1240
-	private function _GetAttachmentData($fid,$attname)
1239
+	private function _GetAttachmentData($fid, $attname)
1241 1240
 	{
1242
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1241
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1243 1242
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1244 1243
 		list($folderid, $id, $part) = explode(":", $attname);
1245 1244
 
1246 1245
 		$this->splitID($folderid, $account, $folder);
1247 1246
 
1248
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1247
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1249 1248
 
1250 1249
 		$this->mail->reopen($folder);
1251
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1250
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1252 1251
 		$SIOattachment = new SyncItemOperationsAttachment();
1253
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1252
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1254 1253
 		$SIOattachment->data = $attachment['attachment'];
1255 1254
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1256
-		if (isset($attachment['type']) )
1255
+		if (isset($attachment['type']))
1257 1256
 			$SIOattachment->contenttype = $attachment['type'];
1258 1257
 
1259 1258
 		unset($attachment);
@@ -1296,17 +1295,17 @@  discard block
 block discarded – undo
1296 1295
 	 */
1297 1296
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1298 1297
 	{
1299
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1298
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1300 1299
 		//unset($folderid, $id, $message, $contentParameters);
1301 1300
 		$account = $folder = null;
1302 1301
 		$this->splitID($folderid, $account, $folder);
1303 1302
 		if (isset($message->flag)) {
1304 1303
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1305
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1306
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1304
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1305
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1307 1306
 			} else {
1308
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1309
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1307
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1308
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1310 1309
 			}
1311 1310
 		}
1312 1311
 		return $this->StatMessage($folderid, $id);
@@ -1328,23 +1327,23 @@  discard block
 block discarded – undo
1328 1327
 	 */
1329 1328
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1330 1329
 	{
1331
-		unset($contentParameters);	// not used, but required by function signature
1330
+		unset($contentParameters); // not used, but required by function signature
1332 1331
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1333 1332
 		$account = $srcFolder = $destFolder = null;
1334 1333
 		$this->splitID($folderid, $account, $srcFolder);
1335 1334
 		$this->splitID($newfolderid, $account, $destFolder);
1336 1335
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1337
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1336
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1338 1337
 		$this->mail->reopen($destFolder);
1339 1338
 		$status = $this->mail->getFolderStatus($destFolder);
1340 1339
 		$uidNext = $status['uidnext'];
1341 1340
 		$this->mail->reopen($srcFolder);
1342 1341
 
1343 1342
 		// move message
1344
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1345
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1343
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1344
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1346 1345
 		// return the new id "as string"
1347
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1346
+		return ($rv === true ? $uidNext : $rv[$id])."";
1348 1347
 	}
1349 1348
 
1350 1349
 	/**
@@ -1352,87 +1351,87 @@  discard block
 block discarded – undo
1352 1351
 	 *
1353 1352
 	 *  @ToDo loop over available email accounts
1354 1353
 	 */
1355
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1354
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1356 1355
 	{
1357
-		static $cutdate=null;
1358
-		if (!empty($cutoffdate) && $cutoffdate >0 && (empty($cutdate) || $cutoffdate != $cutdate))  $cutdate = $cutoffdate;
1356
+		static $cutdate = null;
1357
+		if (!empty($cutoffdate) && $cutoffdate > 0 && (empty($cutdate) || $cutoffdate != $cutdate))  $cutdate = $cutoffdate;
1359 1358
 		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$folderid.' SINCE:'.$cutdate.'/'.date("d-M-Y", $cutdate));
1360 1359
 		if (empty($cutdate))
1361 1360
 		{
1362
-			$cutdate = Api\DateTime::to('now','ts')-(3600*24*28*3);
1363
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutdate));
1361
+			$cutdate = Api\DateTime::to('now', 'ts') - (3600 * 24 * 28 * 3);
1362
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutdate));
1364 1363
 		}
1365 1364
 		return $this->fetchMessages($folderid, $cutdate);
1366 1365
 	}
1367 1366
 
1368
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL)
1367
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL)
1369 1368
 	{
1370
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1369
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1371 1370
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1372 1371
 		$rv_messages = array();
1373 1372
 		// if the message is still available within the class, we use it instead of fetching it again
1374
-		if (is_array($_id) && count($_id)==1 && is_array($this->messages) && isset($this->messages[$_id[0]]) && is_array($this->messages[$_id[0]]))
1373
+		if (is_array($_id) && count($_id) == 1 && is_array($this->messages) && isset($this->messages[$_id[0]]) && is_array($this->messages[$_id[0]]))
1375 1374
 		{
1376 1375
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." the message ".$_id[0]." is still available within the class, we use it instead of fetching it again");
1377 1376
 			$rv_messages = array('header'=>array($this->messages[$_id[0]]));
1378 1377
 		}
1379 1378
 		if (empty($rv_messages))
1380 1379
 		{
1381
-			if ($this->debugLevel>1) $starttime = microtime (true);
1380
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1382 1381
 			$this->_connect($this->account);
1383
-			if ($this->debugLevel>1)
1382
+			if ($this->debugLevel > 1)
1384 1383
 			{
1385 1384
 				$endtime = microtime(true) - $starttime;
1386
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1385
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1387 1386
 			}
1388 1387
 			$messagelist = $_filter = array();
1389 1388
 			// if not connected, any further action must fail
1390
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1391
-			if ($this->debugLevel>1) $starttime = microtime (true);
1389
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1390
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1392 1391
 			$account = $_folderName = $id = null;
1393
-			$this->splitID($folderid,$account,$_folderName,$id);
1394
-			if ($this->debugLevel>1)
1392
+			$this->splitID($folderid, $account, $_folderName, $id);
1393
+			if ($this->debugLevel > 1)
1395 1394
 			{
1396 1395
 				$endtime = microtime(true) - $starttime;
1397
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1396
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1398 1397
 			}
1399
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1400
-			if ($this->debugLevel>1) $starttime = microtime (true);
1401
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1402
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1403
-			if ($this->debugLevel>1)
1398
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1399
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1400
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1401
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1402
+			if ($this->debugLevel > 1)
1404 1403
 			{
1405 1404
 				$endtime = microtime(true) - $starttime;
1406
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1405
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1407 1406
 			}
1408 1407
 		}
1409
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1408
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1410 1409
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1411 1410
 		$messagelist = array();
1412
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1411
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1413 1412
 		//if ($_returnModHash) $messageFolderHash = array();
1414 1413
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1415 1414
 		{
1416
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1415
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1417 1416
 			$this->messages[$vars['uid']] = $vars;
1418
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1417
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1419 1418
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1420 1419
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1421
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1420
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1422 1421
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1423 1422
 			$mess["id"] = $vars['uid'];
1424 1423
 			// 'seen' aka 'read' is the only flag we want to know about
1425 1424
 			$mess["flags"] = 0;
1426 1425
 			// outlook supports additional flags, set them to 0
1427
-			if($vars["seen"]) $mess["flags"] = 1;
1428
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1426
+			if ($vars["seen"]) $mess["flags"] = 1;
1427
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1429 1428
 			$messagelist[$vars['uid']] = $mess;
1430 1429
 			unset($mess);
1431 1430
 		}
1432
-		if ($this->debugLevel>1)
1431
+		if ($this->debugLevel > 1)
1433 1432
 		{
1434 1433
 			$endtime = microtime(true) - $gstarttime;
1435
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1434
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1436 1435
 		}
1437 1436
 		return $messagelist;
1438 1437
 	}
@@ -1483,32 +1482,32 @@  discard block
 block discarded – undo
1483 1482
 	public function getSearchResultsMailbox($_searchquery)
1484 1483
 	{
1485 1484
 		//$this->debugLevel=1;
1486
-		$searchquery=$_searchquery->GetDataArray();
1485
+		$searchquery = $_searchquery->GetDataArray();
1487 1486
 		if (!is_array($searchquery)) return array();
1488
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1487
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1489 1488
 
1490 1489
 		if (isset($searchquery['searchrebuildresults'])) {
1491 1490
 			$rebuildresults = $searchquery['searchrebuildresults'];
1492 1491
 		} else {
1493 1492
 			$rebuildresults = false;
1494 1493
 		}
1495
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1494
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1496 1495
 
1497 1496
 		if (isset($searchquery['deeptraversal'])) {
1498 1497
 			$deeptraversal = $searchquery['deeptraversal'];
1499 1498
 		} else {
1500 1499
 			$deeptraversal = false;
1501 1500
 		}
1502
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1501
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1503 1502
 
1504 1503
 		if (isset($searchquery['searchrange'])) {
1505
-			$range = explode("-",$_searchquery->GetSearchRange());
1506
-			$start =$range[0] + 1;
1504
+			$range = explode("-", $_searchquery->GetSearchRange());
1505
+			$start = $range[0] + 1;
1507 1506
 			$limit = $range[1] - $range[0] + 1;
1508 1507
 		} else {
1509 1508
 			$range = false;
1510 1509
 		}
1511
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1510
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1512 1511
 
1513 1512
 		//foreach($searchquery['query'] as $k => $value) {
1514 1513
 		//	$query = $value;
@@ -1531,15 +1530,15 @@  discard block
 block discarded – undo
1531 1530
 		}
1532 1531
 		if (!$folderid)
1533 1532
 		{
1534
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1535
-			$folderid = $this->createID($account=0,$_folderName);
1533
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1534
+			$folderid = $this->createID($account = 0, $_folderName);
1536 1535
 		}
1537
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1538
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1536
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1537
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1539 1538
 		$this->_connect($account);
1540 1539
 		// this should not be needed ???
1541
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1542
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1540
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1541
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1543 1542
 						 'string'=> $searchText,
1544 1543
 						 'status'=>'any'
1545 1544
 						);
@@ -1554,22 +1553,22 @@  discard block
 block discarded – undo
1554 1553
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1555 1554
 		 */
1556 1555
 			$_filter['range'] = "BETWEEN";
1557
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1558
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1559
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1560
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1556
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1557
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1558
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1559
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1561 1560
 		}
1562 1561
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1563
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1564
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1562
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1563
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1565 1564
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1566
-		$list=array();
1565
+		$list = array();
1567 1566
 
1568 1567
 		$cnt = count($rv_messages['header']);
1569 1568
 		//$list['status'] = 1;
1570 1569
 		$list['searchtotal'] = $cnt;
1571 1570
 		$list["range"] = $_searchquery->GetSearchRange();
1572
-		foreach((array)$rv_messages['header'] as $i => $vars)
1571
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1573 1572
 		{
1574 1573
 			$list[] = array(
1575 1574
 				"class" => "Email",
@@ -1589,20 +1588,20 @@  discard block
 block discarded – undo
1589 1588
 	 * @param string $folder
1590 1589
 	 * @return string
1591 1590
 	 */
1592
-	private function getParentID($account,$folder)
1591
+	private function getParentID($account, $folder)
1593 1592
 	{
1594 1593
 		$this->_connect($account);
1595
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1594
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1596 1595
 
1597 1596
 		$mailFolder = $this->folders[$folder];
1598 1597
 		if (!isset($mailFolder)) return false;
1599
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1600
-		$parent = explode($delimiter,$folder);
1598
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1599
+		$parent = explode($delimiter, $folder);
1601 1600
 		array_pop($parent);
1602
-		$parent = implode($delimiter,$parent);
1601
+		$parent = implode($delimiter, $parent);
1603 1602
 
1604 1603
 		$id = $parent ? $this->createID($account, $parent) : '0';
1605
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1604
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1606 1605
 		return $id;
1607 1606
 	}
1608 1607
 
@@ -1622,48 +1621,48 @@  discard block
 block discarded – undo
1622 1621
 			$account = $folder = null;
1623 1622
 			$this->splitID($id, $account, $folder);
1624 1623
 		}
1625
-		catch(Exception $e) {
1626
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1627
-			return $folderObj=false;
1624
+		catch (Exception $e) {
1625
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1626
+			return $folderObj = false;
1628 1627
 		}
1629 1628
 		$this->_connect($account);
1630
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1629
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1631 1630
 
1632 1631
 		$mailFolder = $this->folders[$folder];
1633
-		if (!isset($mailFolder)) return $folderObj=false;
1632
+		if (!isset($mailFolder)) return $folderObj = false;
1634 1633
 
1635 1634
 		$folderObj = new SyncFolder();
1636 1635
 		$folderObj->serverid = $id;
1637
-		$folderObj->parentid = $this->getParentID($account,$folder);
1636
+		$folderObj->parentid = $this->getParentID($account, $folder);
1638 1637
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1639
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1638
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1640 1639
 		// get folder-type
1641
-		foreach($this->folders as $inbox => $mailFolder) break;
1640
+		foreach ($this->folders as $inbox => $mailFolder) break;
1642 1641
 		if ($folder == $inbox)
1643 1642
 		{
1644 1643
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1645 1644
 		}
1646
-		elseif($this->mail->isDraftFolder($folder, false, true))
1645
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1647 1646
 		{
1648 1647
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1649 1648
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1650 1649
 			$folderObj->parentid = 0; // required by devices
1651 1650
 		}
1652
-		elseif($this->mail->isTrashFolder($folder, false, true))
1651
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1653 1652
 		{
1654 1653
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1655 1654
 			$this->_wasteID = $folder;
1656 1655
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1657 1656
 			$folderObj->parentid = 0; // required by devices
1658 1657
 		}
1659
-		elseif($this->mail->isSentFolder($folder, false, true))
1658
+		elseif ($this->mail->isSentFolder($folder, false, true))
1660 1659
 		{
1661 1660
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1662 1661
 			$folderObj->parentid = 0; // required by devices
1663 1662
 			$this->_sentID = $folder;
1664 1663
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1665 1664
 		}
1666
-		elseif($this->mail->isOutbox($folder, false, true))
1665
+		elseif ($this->mail->isOutbox($folder, false, true))
1667 1666
 		{
1668 1667
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1669 1668
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1675,7 +1674,7 @@  discard block
 block discarded – undo
1675 1674
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1676 1675
 		}
1677 1676
 
1678
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1677
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1679 1678
 		return $folderObj;
1680 1679
 	}
1681 1680
 
@@ -1720,22 +1719,22 @@  discard block
 block discarded – undo
1720 1719
 		$account = $folder = null;
1721 1720
 		$this->splitID($folderid, $account, $folder);
1722 1721
 		if (is_numeric($account)) $type = 'mail';
1723
-        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": on $folderid -> $folder ($account) type: ". $type);
1722
+        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": on $folderid -> $folder ($account) type: ".$type);
1724 1723
 		if ($type != 'mail') return false;
1725 1724
 
1726
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1725
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1727 1726
 
1728 1727
 		$changes = array();
1729
-        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": on $folderid ($folder) stat: ". $syncstate);
1728
+        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": on $folderid ($folder) stat: ".$syncstate);
1730 1729
         $this->mail->reopen($folder);
1731
-        $status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true);
1730
+        $status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true);
1732 1731
         if (!$status) {
1733
-            ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1732
+            ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1734 1733
             return false;
1735 1734
         } else {
1736
-            $syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1735
+            $syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1737 1736
         }
1738
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' called with ('.$folderid.', ....) returning '.array2string($syncstate));
1737
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' called with ('.$folderid.', ....) returning '.array2string($syncstate));
1739 1738
 		return $changes;
1740 1739
 	}
1741 1740
 
@@ -1748,8 +1747,8 @@  discard block
 block discarded – undo
1748 1747
 	function GetWasteBasket()
1749 1748
 	{
1750 1749
 		$this->_connect($this->account);
1751
-		$id = $this->createID($account=0, $this->_wasteID);
1752
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1750
+		$id = $this->createID($account = 0, $this->_wasteID);
1751
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1753 1752
 		return $id;
1754 1753
 	}
1755 1754
 
@@ -1770,7 +1769,7 @@  discard block
 block discarded – undo
1770 1769
      */
1771 1770
     public function DeleteMessage($folderid, $id, $contentParameters)
1772 1771
 	{
1773
-		unset($contentParameters);	// not used, but required by function signature
1772
+		unset($contentParameters); // not used, but required by function signature
1774 1773
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1775 1774
 		/*
1776 1775
 		$this->imap_reopenFolder($folderid);
@@ -1781,7 +1780,7 @@  discard block
 block discarded – undo
1781 1780
 		// we may have to split folderid
1782 1781
 		$account = $folder = null;
1783 1782
 		$this->splitID($folderid, $account, $folder);
1784
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1783
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1785 1784
 		$_messageUID = (array)$id;
1786 1785
 
1787 1786
 		$this->_connect($this->account);
@@ -1793,9 +1792,9 @@  discard block
 block discarded – undo
1793 1792
 		catch (Api\Exception $e)
1794 1793
 		{
1795 1794
 			$error = $e->getMessage();
1796
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1795
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1797 1796
 			// if the server thinks the message does not exist report deletion as success
1798
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1797
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1799 1798
 			return false;
1800 1799
 		}
1801 1800
 
@@ -1829,15 +1828,15 @@  discard block
 block discarded – undo
1829 1828
      */
1830 1829
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1831 1830
 	{
1832
-		unset($contentParameters);	// not used, but required by function signature
1831
+		unset($contentParameters); // not used, but required by function signature
1833 1832
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1834 1833
 		$account = $folder = null;
1835 1834
 		$this->splitID($folderid, $account, $folder);
1836 1835
 
1837 1836
 		$_messageUID = (array)$id;
1838 1837
 		$this->_connect($this->account);
1839
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1840
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1838
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1839
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1841 1840
 
1842 1841
 		return $rv;
1843 1842
 	}
@@ -1854,7 +1853,7 @@  discard block
 block discarded – undo
1854 1853
 	 */
1855 1854
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1856 1855
 	{
1857
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1856
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1858 1857
 		return false;
1859 1858
 	}
1860 1859
 
@@ -1869,7 +1868,7 @@  discard block
 block discarded – undo
1869 1868
 	 */
1870 1869
 	public function DeleteFolder($parentid, $id)
1871 1870
 	{
1872
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$parentid', '$id') NOT supported!");
1871
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$parentid', '$id') NOT supported!");
1873 1872
 		return false;
1874 1873
 	}
1875 1874
 
@@ -1889,8 +1888,8 @@  discard block
 block discarded – undo
1889 1888
 		$this->_connect($this->account);
1890 1889
 		$account = $folder = null;
1891 1890
 		$this->splitID($folderid, $account, $folder);
1892
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1893
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1891
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1892
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1894 1893
 
1895 1894
 		return $rv;
1896 1895
 	}
@@ -1904,17 +1903,17 @@  discard block
 block discarded – undo
1904 1903
 	 * @return string
1905 1904
 	 * @throws Api\Exception\WrongParameter
1906 1905
 	 */
1907
-	private function createID($account,$folder,$id=0)
1906
+	private function createID($account, $folder, $id = 0)
1908 1907
 	{
1909 1908
 		if (!is_numeric($folder))
1910 1909
 		{
1911 1910
 			// convert string $folder in numeric id
1912
-			$folder = $this->folder2hash($account,$f=$folder);
1911
+			$folder = $this->folder2hash($account, $f = $folder);
1913 1912
 		}
1914 1913
 
1915 1914
 		$str = $this->backend->createID($account, $folder, $id);
1916 1915
 
1917
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1916
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1918 1917
 
1919 1918
 		return $str;
1920 1919
 	}
@@ -1928,14 +1927,14 @@  discard block
 block discarded – undo
1928 1927
 	 * @param int &$id=null
1929 1928
 	 * @throws Api\Exception\WrongParameter
1930 1929
 	 */
1931
-	private function splitID($str,&$account,&$folder,&$id=null)
1930
+	private function splitID($str, &$account, &$folder, &$id = null)
1932 1931
 	{
1933 1932
 		$this->backend->splitID($str, $account, $folder, $id);
1934 1933
 
1935 1934
 		// convert numeric folder-id back to folder name
1936
-		$folder = $this->hash2folder($account,$f=$folder);
1935
+		$folder = $this->hash2folder($account, $f = $folder);
1937 1936
 
1938
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
1937
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$id)");
1939 1938
 	}
1940 1939
 
1941 1940
 	/**
@@ -1952,9 +1951,9 @@  discard block
 block discarded – undo
1952 1951
 	 * @param string $folder
1953 1952
 	 * @return int
1954 1953
 	 */
1955
-	private function folder2hash($account,$folder)
1954
+	private function folder2hash($account, $folder)
1956 1955
 	{
1957
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
1956
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
1958 1957
 
1959 1958
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
1960 1959
 		{
@@ -1975,9 +1974,9 @@  discard block
 block discarded – undo
1975 1974
 	 * @param int $index
1976 1975
 	 * @return string NULL if not used so far
1977 1976
 	 */
1978
-	private function hash2folder($account,$index)
1977
+	private function hash2folder($account, $index)
1979 1978
 	{
1980
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
1979
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
1981 1980
 
1982 1981
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
1983 1982
 	}
@@ -2014,9 +2013,9 @@  discard block
 block discarded – undo
2014 2013
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2015 2014
 				($hashes = file_get_contents($file)))
2016 2015
 			{
2017
-				$this->folderHashes = json_decode($hashes,true);
2016
+				$this->folderHashes = json_decode($hashes, true);
2018 2017
 				// fallback in case hashes have been serialized instead of being json-encoded
2019
-				if (json_last_error()!=JSON_ERROR_NONE)
2018
+				if (json_last_error() != JSON_ERROR_NONE)
2020 2019
 				{
2021 2020
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2022 2021
 					$this->folderHashes = unserialize($hashes);
@@ -2062,9 +2061,9 @@  discard block
 block discarded – undo
2062 2061
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2063 2062
 	 * @throws Api\Exception\AssertionFailed
2064 2063
 	 */
2065
-	private function hashFile($old=false)
2064
+	private function hashFile($old = false)
2066 2065
 	{
2067
-		if (!($dev_id=Request::GetDeviceID()))
2066
+		if (!($dev_id = Request::GetDeviceID()))
2068 2067
 		{
2069 2068
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2070 2069
 		}
Please login to merge, or discard this patch.