Completed
Push — 16.1 ( 7ccc73...046888 )
by Nathan
64:46 queued 51:15
created
api/src/Egw/Base.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	static $sub_objects = array(
66 66
 		'log' => 'errorlog',
67
-		'link' => 'bolink',		// depricated use static egw_link methods
67
+		'link' => 'bolink', // depricated use static egw_link methods
68 68
 		'datetime' => 'egw_datetime',
69 69
 		// classes moved to new api dir
70 70
 		'template' => true,
71 71
 		'applications' => 'EGroupware\\Api\\Egw\\Applications',
72
-		'framework' => true,	// special handling in __get()
72
+		'framework' => true, // special handling in __get()
73 73
 		'ldap' => true,
74 74
 	);
75 75
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	{
96 96
 		//error_log(__METHOD__."($name)".function_backtrace());
97 97
 
98
-		if ($name == 'js') $name = 'framework';	// javascript class is integrated now into framework
98
+		if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework
99 99
 
100 100
 		if (isset($this->$name))
101 101
 		{
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace());
108 108
 			return null;
109 109
 		}
110
-		switch($name)
110
+		switch ($name)
111 111
 		{
112 112
 			case 'framework':
113 113
 				return $this->framework = Api\Framework::factory();
Please login to merge, or discard this patch.
Braces   +13 added lines, -3 removed lines patch added patch discarded remove patch
@@ -95,7 +95,11 @@  discard block
 block discarded – undo
95 95
 	{
96 96
 		//error_log(__METHOD__."($name)".function_backtrace());
97 97
 
98
-		if ($name == 'js') $name = 'framework';	// javascript class is integrated now into framework
98
+		if ($name == 'js')
99
+		{
100
+			$name = 'framework';
101
+		}
102
+		// javascript class is integrated now into framework
99 103
 
100 104
 		if (isset($this->$name))
101 105
 		{
@@ -104,7 +108,10 @@  discard block
 block discarded – undo
104 108
 
105 109
 		if (!isset(self::$sub_objects[$name]) && !class_exists('EGroupware\\Api\\'.ucfirst($name)) && !class_exists($name))
106 110
 		{
107
-			if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace());
111
+			if ($name != 'ADOdb')
112
+			{
113
+				error_log(__METHOD__.": There's NO $name object! ".function_backtrace());
114
+			}
108 115
 			return null;
109 116
 		}
110 117
 		switch($name)
@@ -121,7 +128,10 @@  discard block
 block discarded – undo
121 128
 				return $this->ldap = Api\Ldap::factory(false);
122 129
 			default:
123 130
 				$class = isset(self::$sub_objects[$name]) ? self::$sub_objects[$name] : 'EGroupware\\Api\\'.ucfirst($name);
124
-				if (!class_exists($class)) $class = $name;
131
+				if (!class_exists($class))
132
+				{
133
+					$class = $name;
134
+				}
125 135
 				break;
126 136
 		}
127 137
 		return $this->$name = new $class();
Please login to merge, or discard this patch.
api/src/Link.php 4 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		}
481 481
 		$ids = Link\Storage::get_links($app, $id, $only_app, $order, $deleted, $limit);
482 482
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
483
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
483
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
484 484
 		{
485 485
 			if (($vfs_ids = self::list_attached($app,$id)))
486 486
 			{
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 		$links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted);
537 537
 
538 538
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
539
-		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
539
+			($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
540 540
 		{
541 541
 			// todo do that in a single query, eg. directory listing, too
542 542
 			foreach($ids as $id)
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 
794 794
 		if (!isset($options['total']))
795 795
 		{
796
-		       $options['total'] = count($result);
796
+			   $options['total'] = count($result);
797 797
 		}
798 798
 		if (is_array($result) && (isset($options['start']) || (isset($options['num_rows']) && count($result) > $options['num_rows'])))
799 799
 		{
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	 * generate temporary link_id used as array-key
434 434
 	 *
435 435
 	 * @param string $app app-name
436
-	 * @param mixed $id
436
+	 * @param string $id
437 437
 	 * @return string
438 438
 	 */
439 439
 	static function temp_link_id($app,$id)
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	 * @param string|array $id ='' id if $app_link_id is an appname or array with links, if 1. entry not yet created
580 580
 	 * @param string $app2 ='' second app
581 581
 	 * @param string $id2 ='' id in $app2
582
-	 * @return array with link-data or False
582
+	 * @return string with link-data or False
583 583
 	 */
584 584
 	static function get_link($app_link_id,$id='',$app2='',$id2='')
585 585
 	{
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 	 * @param string $app appname to link the file to
1198 1198
 	 * @param string $id id in $app
1199 1199
 	 * @param string $file VFS path to link to
1200
-	 * @return boolean true on success, false on failure
1200
+	 * @return null|boolean true on success, false on failure
1201 1201
 	 */
1202 1202
 	static function link_file($app,$id,$file)
1203 1203
 	{
Please login to merge, or discard this patch.
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	/**
114 114
 	 * appname used for returned attached files (!= 'filemanager'!)
115 115
 	 */
116
-	const VFS_APPNAME = 'file';		// pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
116
+	const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
117 117
 
118 118
 	/**
119 119
 	 * Appname used of files stored via Link::set_data()
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 			'icon' => 'addressbook/accounts',
147 147
 			'query' => 'EGroupware\\Api\\Accounts::link_query',
148 148
 			'title' => 'EGroupware\\Api\\Accounts::username',
149
-			'view' => array('menuaction'=>'addressbook.addressbook_ui.view','ajax'=>'true'),
149
+			'view' => array('menuaction'=>'addressbook.addressbook_ui.view', 'ajax'=>'true'),
150 150
 			'view_id' => 'account_id'
151 151
 		),
152 152
 		'api' => array(
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 		// for performance reasons, we do it only once / cache it in the session
217 217
 		if (!($search_link_hooks = Cache::getSession(__CLASS__, 'search_link_hooks')))
218 218
 		{
219
-			$search_link_hooks = Hooks::process('search_link',array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
219
+			$search_link_hooks = Hooks::process('search_link', array(), (bool)$GLOBALS['egw_info']['flags']['async-service']);
220 220
 			Cache::setSession(__CLASS__, 'search_link_hooks', $search_link_hooks);
221 221
 		}
222 222
 		if (is_array($search_link_hooks))
223 223
 		{
224
-			foreach($search_link_hooks as $app => $data)
224
+			foreach ($search_link_hooks as $app => $data)
225 225
 			{
226 226
 				// allow apps to register additional types
227 227
 				if (isset($data['additional']))
228 228
 				{
229
-					foreach($data['additional'] as $name => $values)
229
+					foreach ($data['additional'] as $name => $values)
230 230
 					{
231
-						$values['app'] = $app;	// store name of registring app, to be able to check access
231
+						$values['app'] = $app; // store name of registring app, to be able to check access
232 232
 						self::$app_register[$name] = $values;
233 233
 					}
234 234
 					unset($data['additional']);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 				{
239 239
 					$data['list'] = array('menuaction' => $data['view_list']);
240 240
 				}
241
-				elseif(isset($data['list']) && !isset($data['view_list']))
241
+				elseif (isset($data['list']) && !isset($data['view_list']))
242 242
 				{
243 243
 					$data['view_list'] = $data['list']['menuaction'];
244 244
 				}
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
 	public static function json_registry()
283 283
 	{
284 284
 		$to_json = array();
285
-		foreach(self::$app_register as $app => $data)
285
+		foreach (self::$app_register as $app => $data)
286 286
 		{
287 287
 			if (isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
288 288
 				isset($data['app']) && isset($GLOBALS['egw_info']['user']['apps'][$data['app']]))
289 289
 			{
290 290
 				$to_json[$app] = array_intersect_key($data, array_flip(array(
291
-					'view','view_id','view_popup',
292
-					'add','add_app','add_id','add_popup',
293
-					'edit','edit_id','edit_popup',
294
-					'list','list_popup',
295
-					'name','icon','query',
296
-					'mime','entry','entries',
291
+					'view', 'view_id', 'view_popup',
292
+					'add', 'add_app', 'add_id', 'add_popup',
293
+					'edit', 'edit_id', 'edit_popup',
294
+					'list', 'list_popup',
295
+					'name', 'icon', 'query',
296
+					'mime', 'entry', 'entries',
297 297
 				)));
298 298
 			}
299 299
 		}
@@ -348,11 +348,11 @@  discard block
 block discarded – undo
348 348
 	 * @param int $no_notify =0 &1 dont notify $app1, &2 dont notify $app2
349 349
 	 * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
350 350
 	 */
351
-	static function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0,$no_notify=0 )
351
+	static function link($app1, &$id1, $app2, $id2 = '', $remark = '', $owner = 0, $lastmod = 0, $no_notify = 0)
352 352
 	{
353 353
 		if (self::DEBUG)
354 354
 		{
355
-			echo "<p>Link::link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)</p>\n";
355
+			echo "<p>Link::link('$app1',$id1,'".print_r($app2, true)."',".print_r($id2, true).",'$remark',$owner,$lastmod)</p>\n";
356 356
 		}
357 357
 		if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2)
358 358
 		{
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 				}
372 372
 				if (is_array($id1) || !$id1)		// create link only in $id1 array
373 373
 				{
374
-					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
374
+					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'], $link['owner'], $link['lastmod']);
375 375
 					continue;
376 376
 				}
377 377
 				switch ($link['app'])
@@ -384,19 +384,19 @@  discard block
 block discarded – undo
384 384
 						}
385 385
 						// fall through
386 386
 					case self::VFS_APPNAME:
387
-						$link_id = self::attach_file($app1,$id1,$link['id'],$link['remark']);
387
+						$link_id = self::attach_file($app1, $id1, $link['id'], $link['remark']);
388 388
 						break;
389 389
 
390 390
 					case self::VFS_LINK:
391
-						$link_id = self::link_file($app1,$id1, $link['id'],$link['remark']);
391
+						$link_id = self::link_file($app1, $id1, $link['id'], $link['remark']);
392 392
 						break;
393 393
 
394 394
 					default:
395
-						$link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'],
396
-							$link['remark'],$link['owner'],$link['lastmod']);
395
+						$link_id = Link\Storage::link($app1, $id1, $link['app'], $link['id'],
396
+							$link['remark'], $link['owner'], $link['lastmod']);
397 397
 						// notify both sides
398
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
399
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
398
+						if (!($no_notify&2)) self::notify('link', $link['app'], $link['id'], $app1, $id1, $link_id);
399
+						if (!($no_notify&1)) self::notify('link', $app1, $id1, $link['app'], $link['id'], $link_id);
400 400
 						break;
401 401
 				}
402 402
 			}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 			{
409 409
 				$id1 = array( );
410 410
 			}
411
-			$link_id = self::temp_link_id($app2,$id2);
411
+			$link_id = self::temp_link_id($app2, $id2);
412 412
 
413 413
 			$id1[$link_id] = array(
414 414
 				'app' => $app2,
@@ -426,24 +426,24 @@  discard block
 block discarded – undo
426 426
 		}
427 427
 		if ($app1 == self::VFS_LINK)
428 428
 		{
429
-			return self::link_file($app2,$id2,$id1,$remark);
429
+			return self::link_file($app2, $id2, $id1, $remark);
430 430
 		}
431 431
 		elseif ($app2 == self::VFS_LINK)
432 432
 		{
433
-			return self::link_file($app1,$id1,$id2,$remark);
433
+			return self::link_file($app1, $id1, $id2, $remark);
434 434
 		}
435 435
 		if ($app1 == self::VFS_APPNAME)
436 436
 		{
437
-			return self::attach_file($app2,$id2,$id1,$remark);
437
+			return self::attach_file($app2, $id2, $id1, $remark);
438 438
 		}
439 439
 		elseif ($app2 == self::VFS_APPNAME)
440 440
 		{
441
-			return self::attach_file($app1,$id1,$id2,$remark);
441
+			return self::attach_file($app1, $id1, $id2, $remark);
442 442
 		}
443
-		$link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner);
443
+		$link_id = Link\Storage::link($app1, $id1, $app2, $id2, $remark, $owner);
444 444
 
445
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
446
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
445
+		if (!($no_notify&2)) self::notify('link', $app2, $id2, $app1, $id1, $link_id);
446
+		if (!($no_notify&1)) self::notify('link', $app1, $id1, $app2, $id2, $link_id);
447 447
 
448 448
 		return $link_id;
449 449
 	}
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 	 * @param mixed $id
456 456
 	 * @return string
457 457
 	 */
458
-	static function temp_link_id($app,$id)
458
+	static function temp_link_id($app, $id)
459 459
 	{
460
-		return $app.':'.(!in_array($app, array(self::VFS_APPNAME,self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
460
+		return $app.':'.(!in_array($app, array(self::VFS_APPNAME, self::VFS_LINK, self::DATA_APPNAME)) ? $id : $id['name']);
461 461
 	}
462 462
 
463 463
 	/**
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * @param int $limit =null number of entries to return, only affects links, attachments are allways reported!
474 474
 	 * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found
475 475
 	 */
476
-	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
476
+	static function get_links($app, $id, $only_app = '', $order = 'link_lastmod DESC', $cache_titles = false, $deleted = false, $limit = null)
477 477
 	{
478 478
 		if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
479 479
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 			{
485 485
 				if (($not_only = $only_app[0] == '!'))
486 486
 				{
487
-					$only_app = substr(1,$only_app);
487
+					$only_app = substr(1, $only_app);
488 488
 				}
489 489
 				foreach (array_reverse($id) as $link)
490 490
 				{
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
502 502
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
503 503
 		{
504
-			if (($vfs_ids = self::list_attached($app,$id)))
504
+			if (($vfs_ids = self::list_attached($app, $id)))
505 505
 			{
506 506
 				$ids += $vfs_ids;
507 507
 			}
@@ -511,18 +511,18 @@  discard block
 block discarded – undo
511 511
 		{
512 512
 			// agregate links by app
513 513
 			$app_ids = array();
514
-			foreach($ids as $link)
514
+			foreach ($ids as $link)
515 515
 			{
516 516
 				$app_ids[$link['app']][] = $link['id'];
517 517
 			}
518
-			foreach($app_ids as $appname => $a_ids)
518
+			foreach ($app_ids as $appname => $a_ids)
519 519
 			{
520
-				self::titles($appname,array_unique($a_ids));
520
+				self::titles($appname, array_unique($a_ids));
521 521
 			}
522 522
 			// remove links, current user has no access, from result
523
-			foreach($ids as $key => $link)
523
+			foreach ($ids as $key => $link)
524 524
 			{
525
-				if (!self::title($link['app'],$link['id']))
525
+				if (!self::title($link['app'], $link['id']))
526 526
 				{
527 527
 					unset($ids[$key]);
528 528
 				}
@@ -544,27 +544,27 @@  discard block
 block discarded – undo
544 544
 	 * @param boolean $deleted =false Include links that have been flagged as deleted, waiting for purge of linked record.
545 545
 	 * @return array of $id => array($links) pairs
546 546
 	 */
547
-	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
547
+	static function get_links_multiple($app, array $ids, $cache_titles = true, $only_app = '', $order = 'link_lastmod DESC', $deleted = false)
548 548
 	{
549
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
549
+		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids, true).",$cache_titles,'$only_app','$order')</p>\n";
550 550
 
551 551
 		if (!$ids)
552 552
 		{
553
-			return array();		// no ids are linked to nothing
553
+			return array(); // no ids are linked to nothing
554 554
 		}
555
-		$links = Link\Storage::get_links($app,$ids,$only_app,$order,$deleted);
555
+		$links = Link\Storage::get_links($app, $ids, $only_app, $order, $deleted);
556 556
 
557 557
 		if (empty($only_app) || $only_app == self::VFS_APPNAME ||
558 558
 		    ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
559 559
 		{
560 560
 			// todo do that in a single query, eg. directory listing, too
561
-			foreach($ids as $id)
561
+			foreach ($ids as $id)
562 562
 			{
563 563
 				if (!isset($links[$id]))
564 564
 				{
565 565
 					$links[$id] = array();
566 566
 				}
567
-				if (($vfs_ids = self::list_attached($app,$id)))
567
+				if (($vfs_ids = self::list_attached($app, $id)))
568 568
 				{
569 569
 					$links[$id] += $vfs_ids;
570 570
 				}
@@ -574,16 +574,16 @@  discard block
 block discarded – undo
574 574
 		{
575 575
 			// agregate links by app
576 576
 			$app_ids = array();
577
-			foreach($links as &$targets)
577
+			foreach ($links as &$targets)
578 578
 			{
579
-				foreach($targets as $link)
579
+				foreach ($targets as $link)
580 580
 				{
581 581
 					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
582 582
 				}
583 583
 			}
584
-			foreach($app_ids as $app => $a_ids)
584
+			foreach ($app_ids as $app => $a_ids)
585 585
 			{
586
-				self::titles($app,array_unique($a_ids));
586
+				self::titles($app, array_unique($a_ids));
587 587
 			}
588 588
 		}
589 589
 		return $links;
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 	 * @param string $id2 ='' id in $app2
601 601
 	 * @return array with link-data or False
602 602
 	 */
603
-	static function get_link($app_link_id,$id='',$app2='',$id2='')
603
+	static function get_link($app_link_id, $id = '', $app2 = '', $id2 = '')
604 604
 	{
605 605
 		if (self::DEBUG)
606 606
 		{
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 		}
609 609
 		if (is_array($id))
610 610
 		{
611
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
611
+			if (strpos($app_link_id, ':') === false) $app_link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
612 612
 
613 613
 			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
614 614
 			{
@@ -624,11 +624,11 @@  discard block
 block discarded – undo
624 624
 			}
625 625
 			if ($app_link_id == self::VFS_APPNAME)
626 626
 			{
627
-				return self::info_attached($app2,$id2,$id);
627
+				return self::info_attached($app2, $id2, $id);
628 628
 			}
629
-			return self::info_attached($app_link_id,$id,$id2);
629
+			return self::info_attached($app_link_id, $id, $id2);
630 630
 		}
631
-		return Link\Storage::get_link($app_link_id,$id,$app2,$id2);
631
+		return Link\Storage::get_link($app_link_id, $id, $app2, $id2);
632 632
 	}
633 633
 
634 634
 	/**
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
647 647
 	 * @return the number of links deleted
648 648
 	 */
649
-	static function unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='',$hold_for_purge=false)
649
+	static function unlink($link_id, $app = '', $id = '', $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
650 650
 	{
651
-		return self::unlink2($link_id,$app,$id,$owner,$app2,$id2,$hold_for_purge);
651
+		return self::unlink2($link_id, $app, $id, $owner, $app2, $id2, $hold_for_purge);
652 652
 	}
653 653
 
654 654
 	/**
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	 * @param boolean $hold_for_purge Don't really delete the link, just mark it as deleted and wait for final delete
664 664
 	 * @return the number of links deleted
665 665
 	 */
666
-	static function unlink2($link_id,$app,&$id,$owner=0,$app2='',$id2='',$hold_for_purge=false)
666
+	static function unlink2($link_id, $app, &$id, $owner = 0, $app2 = '', $id2 = '', $hold_for_purge = false)
667 667
 	{
668 668
 		if (self::DEBUG)
669 669
 		{
@@ -675,22 +675,22 @@  discard block
 block discarded – undo
675 675
 		}
676 676
 		elseif ($app == self::VFS_APPNAME)
677 677
 		{
678
-			return self::delete_attached($app2,$id2,$id);
678
+			return self::delete_attached($app2, $id2, $id);
679 679
 		}
680 680
 		elseif ($app2 == self::VFS_APPNAME)
681 681
 		{
682
-			return self::delete_attached($app,$id,$id2);
682
+			return self::delete_attached($app, $id, $id2);
683 683
 		}
684 684
 		if (!is_array($id))
685 685
 		{
686 686
 			if (!$link_id && !$app2 && !$id2 && $app2 != '!'.self::VFS_APPNAME)
687 687
 			{
688
-				self::delete_attached($app,$id);	// deleting all attachments
689
-				self::delete_cache($app,$id);
688
+				self::delete_attached($app, $id); // deleting all attachments
689
+				self::delete_cache($app, $id);
690 690
 			}
691 691
 
692 692
 			// Log in history
693
-			if($link_id && (!$app || !$app2))
693
+			if ($link_id && (!$app || !$app2))
694 694
 			{
695 695
 				// Need to load it first
696 696
 				$link = self::get_link($link_id);
@@ -701,21 +701,21 @@  discard block
 block discarded – undo
701 701
 			}
702 702
 			if ($app && $app2)
703 703
 			{
704
-				Storage\History::static_add($app,$id,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app2.':'.$id2);
705
-				Storage\History::static_add($app2,$id2,$GLOBALS['egw_info']['user']['account_id'],'~link~','',$app.':'.$id);
704
+				Storage\History::static_add($app, $id, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app2.':'.$id2);
705
+				Storage\History::static_add($app2, $id2, $GLOBALS['egw_info']['user']['account_id'], '~link~', '', $app.':'.$id);
706 706
 			}
707
-			$deleted = Link\Storage::unlink($link_id,$app,$id,$owner,$app2 != '!'.self::VFS_APPNAME ? $app2 : '',$id2,$hold_for_purge);
707
+			$deleted = Link\Storage::unlink($link_id, $app, $id, $owner, $app2 != '!'.self::VFS_APPNAME ? $app2 : '', $id2, $hold_for_purge);
708 708
 
709 709
 			// only notify on real links, not the one cached for writing or fileattachments
710 710
 			self::notify_unlink($deleted);
711 711
 
712 712
 			return count($deleted);
713 713
 		}
714
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
714
+		if (!$link_id) $link_id = self::temp_link_id($app2, $id2); // create link_id of temporary link, if not given
715 715
 
716 716
 		if (isset($id[$link_id]))
717 717
 		{
718
-			$id[$link_id] = False;	// set the unlink marker
718
+			$id[$link_id] = False; // set the unlink marker
719 719
 
720 720
 			if (self::DEBUG)
721 721
 			{
@@ -732,10 +732,10 @@  discard block
 block discarded – undo
732 732
 	 * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps
733 733
 	 * @return array with app => title pairs
734 734
 	 */
735
-	static function app_list($must_support='')
735
+	static function app_list($must_support = '')
736 736
 	{
737 737
 		$apps = array();
738
-		foreach(self::$app_register as $type => $reg)
738
+		foreach (self::$app_register as $type => $reg)
739 739
 		{
740 740
 			if ($must_support && !isset($reg[$must_support])) continue;
741 741
 
@@ -792,11 +792,11 @@  discard block
 block discarded – undo
792 792
 	 * @param array $link =null link-data for file-attachments
793 793
 	 * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it
794 794
 	 */
795
-	static function title($app,$id,$link=null)
795
+	static function title($app, $id, $link = null)
796 796
 	{
797 797
 		if (!$id) return '';
798 798
 
799
-		$title =& self::get_cache($app,$id);
799
+		$title = & self::get_cache($app, $id);
800 800
 		if (isset($title) && !empty($title) && !is_array($id))
801 801
 		{
802 802
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
839 839
 			{
840 840
 				$unlinking[$app][$id] = true;
841
-				self::unlink(0,$app,$id);
841
+				self::unlink(0, $app, $id);
842 842
 				unset($unlinking[$app][$id]);
843 843
 			}
844 844
 			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
@@ -863,36 +863,36 @@  discard block
 block discarded – undo
863 863
 	 * @param string $app
864 864
 	 * @param array $ids
865 865
 	 */
866
-	static function titles($app,array $ids)
866
+	static function titles($app, array $ids)
867 867
 	{
868 868
 		if (self::DEBUG)
869 869
 		{
870
-			echo "<p>".__METHOD__."($app,".implode(',',$ids).")</p>\n";
870
+			echo "<p>".__METHOD__."($app,".implode(',', $ids).")</p>\n";
871 871
 		}
872 872
 		$titles = $ids_to_query = array();
873
-		foreach($ids as $id)
873
+		foreach ($ids as $id)
874 874
 		{
875
-			$title =& self::get_cache($app,$id);
875
+			$title = & self::get_cache($app, $id);
876 876
 			if (!isset($title))
877 877
 			{
878 878
 				if (isset(self::$app_register[$app]['titles']))
879 879
 				{
880
-					$ids_to_query[] = $id;	// titles method --> collect links to query at once
880
+					$ids_to_query[] = $id; // titles method --> collect links to query at once
881 881
 				}
882 882
 				else
883 883
 				{
884
-					$title = self::title($app,$id);	// no titles method --> fallback to query each link separate
884
+					$title = self::title($app, $id); // no titles method --> fallback to query each link separate
885 885
 				}
886 886
 			}
887 887
 			$titles[$id] = $title;
888 888
 		}
889 889
 		if ($ids_to_query)
890 890
 		{
891
-			for ($n = 0; ($ids = array_slice($ids_to_query,$n*self::MAX_TITLES_QUERY,self::MAX_TITLES_QUERY)); ++$n)
891
+			for ($n = 0; ($ids = array_slice($ids_to_query, $n * self::MAX_TITLES_QUERY, self::MAX_TITLES_QUERY)); ++$n)
892 892
 			{
893
-				foreach(self::exec(self::$app_register[$app]['titles'], array($ids)) as $id => $t)
893
+				foreach (self::exec(self::$app_register[$app]['titles'], array($ids)) as $id => $t)
894 894
 				{
895
-					$title =& self::get_cache($app,$id);
895
+					$title = & self::get_cache($app, $id);
896 896
 					$titles[$id] = $title = $t;
897 897
 				}
898 898
 			}
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
 	 * @param string $to_id =''id in $to_app
909 909
 	 * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported
910 910
 	 */
911
-	static function add($app,$to_app='',$to_id='')
911
+	static function add($app, $to_app = '', $to_id = '')
912 912
 	{
913 913
 		//echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
914 914
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['add']))
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
 	 * @param string &$popup=null on return popup size eg. '600x400' or null
934 934
 	 * @return array|boolean with name-value pairs for link to edit-methode of $app or false if edit not supported
935 935
 	 */
936
-	static function edit($app,$id,&$popup=null)
936
+	static function edit($app, $id, &$popup = null)
937 937
 	{
938 938
 		//echo "<p>Link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]);
939 939
 		if (empty($app) || empty($id) || !is_array($reg = self::$app_register[$app]) || !isset($reg['edit']))
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
 			if ($reg && isset($reg['view']))
942 942
 			{
943 943
 				$popup = $reg['view_popup'];
944
-				return self::view($app,$id);	// fallback to view
944
+				return self::view($app, $id); // fallback to view
945 945
 			}
946 946
 			return false;
947 947
 		}
@@ -961,12 +961,12 @@  discard block
 block discarded – undo
961 961
 	 * @param array $link =null link-data for file-attachments
962 962
 	 * @return array with name-value pairs for link to view-methode of $app to view $id
963 963
 	 */
964
-	static function view($app,$id,$link=null)
964
+	static function view($app, $id, $link = null)
965 965
 	{
966 966
 		if ($app == self::VFS_APPNAME && !empty($id) && is_array($link))
967 967
 		{
968 968
 			//return Vfs::download_url(self::vfs_path($link['app2'],$link['id2'],$link['id'],true));
969
-			return self::mime_open(self::vfs_path($link['app2'],$link['id2'],$link['id'],true), $link['type']);
969
+			return self::mime_open(self::vfs_path($link['app2'], $link['id2'], $link['id'], true), $link['type']);
970 970
 		}
971 971
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id']))
972 972
 		{
@@ -974,11 +974,11 @@  discard block
 block discarded – undo
974 974
 		}
975 975
 		$view = $reg['view'];
976 976
 
977
-		$names = explode(':',$reg['view_id']);
977
+		$names = explode(':', $reg['view_id']);
978 978
 		if (count($names) > 1)
979 979
 		{
980
-			$id = explode(':',$id);
981
-			while (list($n,$name) = each($names))
980
+			$id = explode(':', $id);
981
+			while (list($n, $name) = each($names))
982 982
 			{
983 983
 				$view[$name] = $id[$n];
984 984
 			}
@@ -1002,13 +1002,13 @@  discard block
 block discarded – undo
1002 1002
 	 */
1003 1003
 	static function get_mime_info($type)
1004 1004
 	{
1005
-		foreach(self::$app_register as $app => $registry)
1005
+		foreach (self::$app_register as $app => $registry)
1006 1006
 		{
1007 1007
 			if (isset($registry['mime']) &&
1008 1008
 				(isset($GLOBALS['egw_info']['user']['apps'][$app]) ||
1009 1009
 				isset($registry['app']) && isset($GLOBALS['egw_info']['user']['apps'][$registry['app']])))
1010 1010
 			{
1011
-				foreach($registry['mime'] as $mime => $data)
1011
+				foreach ($registry['mime'] as $mime => $data)
1012 1012
 				{
1013 1013
 					if ($mime == $type) return $data;
1014 1014
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 	 * @param string &$popup=null on return popup size or null
1030 1030
 	 * @return string|array string with EGw relative link, array with get-parameters for '/index.php' or null (directory and not filemanager access)
1031 1031
 	 */
1032
-	static function mime_open($path, $type=null, &$popup=null)
1032
+	static function mime_open($path, $type = null, &$popup = null)
1033 1033
 	{
1034 1034
 		if (is_null($type)) $type = Vfs::mime_content_type($path);
1035 1035
 
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 				$data[$data['mime_id']] = $path;
1046 1046
 				unset($data['mime_id']);
1047 1047
 			}
1048
-			elseif(isset($data['mime_popup']))
1048
+			elseif (isset($data['mime_popup']))
1049 1049
 			{
1050 1050
 				$popup = $data['mime_popup'];
1051 1051
 			}
@@ -1070,9 +1070,9 @@  discard block
 block discarded – undo
1070 1070
 	 * @param array $link =null link-data for file-attachments
1071 1071
 	 * @return boolean|string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400)
1072 1072
 	 */
1073
-	static function is_popup($app, $action='view', $link=null)
1073
+	static function is_popup($app, $action = 'view', $link = null)
1074 1074
 	{
1075
-		$popup = self::get_registry($app,$action.'_popup');
1075
+		$popup = self::get_registry($app, $action.'_popup');
1076 1076
 
1077 1077
 		// for files/attachments check mime-registry
1078 1078
 		if ($app == self::VFS_APPNAME && is_array($link) && !empty($link['type']))
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 	 * @param string $name name / key in the registry, eg. 'view'
1096 1096
 	 * @return boolean|string false if $app is not registered, otherwise string with the value for $name
1097 1097
 	 */
1098
-	static function get_registry($app,$name)
1098
+	static function get_registry($app, $name)
1099 1099
 	{
1100 1100
 		$reg = self::$app_register[$app];
1101 1101
 
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
 
1104 1104
 		if (!isset($reg[$name]))	// some defaults
1105 1105
 		{
1106
-			switch($name)
1106
+			switch ($name)
1107 1107
 			{
1108 1108
 				case 'name':
1109 1109
 					$reg[$name] = $app;
@@ -1139,16 +1139,16 @@  discard block
 block discarded – undo
1139 1139
 	 * @param boolean $just_the_path =false return url or just the vfs path
1140 1140
 	 * @return string/array path or array with path and relatives, depending on $relatives
1141 1141
 	 */
1142
-	static function vfs_path($app,$id='',$file='',$just_the_path=false)
1142
+	static function vfs_path($app, $id = '', $file = '', $just_the_path = false)
1143 1143
 	{
1144 1144
 		$path = self::VFS_BASEURL;
1145 1145
 
1146 1146
 		if ($app)
1147 1147
 		{
1148
-			if( isset(self::$app_register[$app]) ) {
1148
+			if (isset(self::$app_register[$app])) {
1149 1149
 				$reg = self::$app_register[$app];
1150 1150
 
1151
-				if( isset($reg['file_dir']) ) {
1151
+				if (isset($reg['file_dir'])) {
1152 1152
 					$app = $reg['file_dir'];
1153 1153
 				}
1154 1154
 			}
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
 		}
1168 1168
 		if ($just_the_path)
1169 1169
 		{
1170
-			$path = parse_url($path,PHP_URL_PATH);
1170
+			$path = parse_url($path, PHP_URL_PATH);
1171 1171
 		}
1172 1172
 		else
1173 1173
 		{
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 	 * @param string $comment ='' comment to add to the link
1192 1192
 	 * @return int negative id of egw_sqlfs table as negative link-id's are for vfs attachments
1193 1193
 	 */
1194
-	static function attach_file($app,$id,$file,$comment='')
1194
+	static function attach_file($app, $id, $file, $comment = '')
1195 1195
 	{
1196 1196
 		// check if $file['name'] specifies a subdirectory, in which case use and, if necessary, create it
1197 1197
 		if (is_array($file) && strpos($file['name'], '/') && strpos($file['name'], '..') === false)
@@ -1201,15 +1201,15 @@  discard block
 block discarded – undo
1201 1201
 		}
1202 1202
 		else
1203 1203
 		{
1204
-			$entry_dir = self::vfs_path($app,$id);
1204
+			$entry_dir = self::vfs_path($app, $id);
1205 1205
 		}
1206 1206
 		if (self::DEBUG)
1207 1207
 		{
1208 1208
 			echo "<p>attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment', entry_dir='$entry_dir'</p>\n";
1209 1209
 		}
1210
-		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1210
+		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir, 0, true)))
1211 1211
 		{
1212
-			$Ok = Vfs::copy_uploaded($file, $p=Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false);	// no is_uploaded_file() check!
1212
+			$Ok = Vfs::copy_uploaded($file, $p = Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false); // no is_uploaded_file() check!
1213 1213
 			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1214 1214
 		}
1215 1215
 		else
@@ -1227,14 +1227,14 @@  discard block
 block discarded – undo
1227 1227
 	 * @param string $file VFS path to link to
1228 1228
 	 * @return boolean true on success, false on failure
1229 1229
 	 */
1230
-	static function link_file($app,$id,$file)
1230
+	static function link_file($app, $id, $file)
1231 1231
 	{
1232 1232
 		// Don't try to link into app dir if there is no id
1233
-		if(!$id) return;
1233
+		if (!$id) return;
1234 1234
 
1235 1235
 		if (!Vfs::stat($file))
1236 1236
 		{
1237
-			error_log(__METHOD__. ' (Link target ' . Vfs::decodePath($file) . ' not found!');
1237
+			error_log(__METHOD__.' (Link target '.Vfs::decodePath($file).' not found!');
1238 1238
 			return false;
1239 1239
 		}
1240 1240
 
@@ -1255,7 +1255,7 @@  discard block
 block discarded – undo
1255 1255
 	 * @param string $fname ='' filename
1256 1256
 	 * @return boolean|array false on error ($app or $id not found), array with path as key and boolean result of delete
1257 1257
 	 */
1258
-	static function delete_attached($app,$id='',$fname='')
1258
+	static function delete_attached($app, $id = '', $fname = '')
1259 1259
 	{
1260 1260
 		if ((int)$app > 0)	// is file_id
1261 1261
 		{
@@ -1265,9 +1265,9 @@  discard block
 block discarded – undo
1265 1265
 		{
1266 1266
 			if (empty($app) || empty($id))
1267 1267
 			{
1268
-				return False;	// dont delete more than all attachments of an entry
1268
+				return False; // dont delete more than all attachments of an entry
1269 1269
 			}
1270
-			$url = self::vfs_path($app,$id,$fname);
1270
+			$url = self::vfs_path($app, $id, $fname);
1271 1271
 
1272 1272
 			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1273 1273
 			{
@@ -1280,15 +1280,15 @@  discard block
 block discarded – undo
1280 1280
 			echo '<p>'.__METHOD__."('$app','$id','$fname') url=$url</p>\n";
1281 1281
 		}
1282 1282
 		// Log in history - Need to load it first
1283
-		if((int)$app > 0)
1283
+		if ((int)$app > 0)
1284 1284
 		{
1285 1285
 			$link = self::get_link(-$app);
1286
-			if($link['app2'] && $link['id2'])
1286
+			if ($link['app2'] && $link['id2'])
1287 1287
 			{
1288
-				Storage\History::static_add($link['app2'],$link['id2'],$GLOBALS['egw_info']['user']['account_id'],'~file~','', basename($url));
1288
+				Storage\History::static_add($link['app2'], $link['id2'], $GLOBALS['egw_info']['user']['account_id'], '~file~', '', basename($url));
1289 1289
 			}
1290 1290
 		}
1291
-		if (($Ok = !file_exists($url) || Vfs::remove($url,true)) && ((int)$app > 0 || $fname))
1291
+		if (($Ok = !file_exists($url) || Vfs::remove($url, true)) && ((int)$app > 0 || $fname))
1292 1292
 		{
1293 1293
 			// try removing the dir, in case it's empty
1294 1294
 			if (($dir = Vfs::dirname($url))) @Vfs::rmdir($dir);
@@ -1308,14 +1308,14 @@  discard block
 block discarded – undo
1308 1308
 	 * @param string $filename filename
1309 1309
 	 * @return array 'kind' of link-array
1310 1310
 	 */
1311
-	static function info_attached($app,$id,$filename)
1311
+	static function info_attached($app, $id, $filename)
1312 1312
 	{
1313
-		$path = self::vfs_path($app,$id,$filename,true);
1314
-		if (!($stat = Vfs::stat($path,STREAM_URL_STAT_QUIET)))
1313
+		$path = self::vfs_path($app, $id, $filename, true);
1314
+		if (!($stat = Vfs::stat($path, STREAM_URL_STAT_QUIET)))
1315 1315
 		{
1316 1316
 			return false;
1317 1317
 		}
1318
-		return self::fileinfo2link($stat,$path);
1318
+		return self::fileinfo2link($stat, $path);
1319 1319
 	}
1320 1320
 
1321 1321
 	/**
@@ -1324,36 +1324,36 @@  discard block
 block discarded – undo
1324 1324
 	 * @param array|int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls static function) or a file_id of that table
1325 1325
 	 * @return array a 'kind' of link-array
1326 1326
 	 */
1327
-	static function fileinfo2link($fileinfo,$url=null)
1327
+	static function fileinfo2link($fileinfo, $url = null)
1328 1328
 	{
1329 1329
 		if (!is_array($fileinfo))
1330 1330
 		{
1331 1331
 			$url = Vfs\Sqlfs\StreamWrapper::id2path($fileinfo);
1332
-			if (!($fileinfo = Vfs::stat($url,STREAM_URL_STAT_QUIET)))
1332
+			if (!($fileinfo = Vfs::stat($url, STREAM_URL_STAT_QUIET)))
1333 1333
 			{
1334 1334
 				return false;
1335 1335
 			}
1336 1336
 		}
1337 1337
 
1338
-		$up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH));	// /apps/$app/$id
1338
+		$up = explode('/', $url[0] == '/' ? $url : parse_url($url, PHP_URL_PATH)); // /apps/$app/$id
1339 1339
 		$app = null;
1340 1340
 
1341
-		foreach( self::$app_register as $tapp => $reg ) {
1342
-			if( isset($reg['file_dir']) ) {
1341
+		foreach (self::$app_register as $tapp => $reg) {
1342
+			if (isset($reg['file_dir'])) {
1343 1343
 				$lup = $up;
1344 1344
 
1345 1345
 				unset($lup[0]);
1346 1346
 				unset($lup[1]);
1347 1347
 				reset($lup);
1348 1348
 
1349
-				$fdp = explode('/',$reg['file_dir'][0] == '/' ?
1350
-					$reg['file_dir'] : parse_url($reg['file_dir'],PHP_URL_PATH));
1349
+				$fdp = explode('/', $reg['file_dir'][0] == '/' ?
1350
+					$reg['file_dir'] : parse_url($reg['file_dir'], PHP_URL_PATH));
1351 1351
 
1352 1352
 				$found = true;
1353 1353
 
1354
-				foreach( $fdp as $part ) {
1355
-					if( current($lup) == $part ) {
1356
-						if( next($lup) === false ) {
1354
+				foreach ($fdp as $part) {
1355
+					if (current($lup) == $part) {
1356
+						if (next($lup) === false) {
1357 1357
 							$found = false;
1358 1358
 							break;
1359 1359
 						}
@@ -1364,16 +1364,16 @@  discard block
 block discarded – undo
1364 1364
 					}
1365 1365
 				}
1366 1366
 
1367
-				if( $found ) {
1368
-					$id	= current($lup);
1367
+				if ($found) {
1368
+					$id = current($lup);
1369 1369
 					$app = $tapp;
1370 1370
 					break;
1371 1371
 				}
1372 1372
 			}
1373 1373
 		}
1374 1374
 
1375
-		if( $app === null ) {
1376
-			list(,,$app,$id) = $up;
1375
+		if ($app === null) {
1376
+			list(,, $app, $id) = $up;
1377 1377
 		}
1378 1378
 
1379 1379
 		return array(
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
 			'id'        => $fileinfo['name'],
1382 1382
 			'app2'      => $app,
1383 1383
 			'id2'       => $id,
1384
-			'remark'    => '',					// only list_attached currently sets the remark
1384
+			'remark'    => '', // only list_attached currently sets the remark
1385 1385
 			'owner'     => $fileinfo['uid'],
1386 1386
 			'link_id'   => -$fileinfo['ino'],
1387 1387
 			'lastmod'   => $fileinfo['mtime'],
@@ -1397,26 +1397,26 @@  discard block
 block discarded – undo
1397 1397
 	 * @param string $id id in app
1398 1398
 	 * @return array with link_id => 'kind' of link-array pairs
1399 1399
 	 */
1400
-	static function list_attached($app,$id)
1400
+	static function list_attached($app, $id)
1401 1401
 	{
1402
-		$path = self::vfs_path($app,$id);
1402
+		$path = self::vfs_path($app, $id);
1403 1403
 		//error_log(__METHOD__."($app,$id) url=$url");
1404 1404
 
1405
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1405
+		if (!($extra = self::get_registry($app, 'find_extra'))) $extra = array();
1406 1406
 
1407 1407
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1408
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1408
+		if (substr($path, 0, 13) == 'stylite.links') $path = substr($path, 8);
1409 1409
 
1410 1410
 		$attached = array();
1411
-		if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
1411
+		if (($url2stats = Vfs::find($path, array('need_mime'=>true, 'type'=>'F', 'url'=>true) + $extra, true)))
1412 1412
 		{
1413
-			$props = Vfs::propfind(array_keys($url2stats));	// get the comments
1414
-			foreach($url2stats as $url => &$fileinfo)
1413
+			$props = Vfs::propfind(array_keys($url2stats)); // get the comments
1414
+			foreach ($url2stats as $url => &$fileinfo)
1415 1415
 			{
1416
-				$link = self::fileinfo2link($fileinfo,$url);
1416
+				$link = self::fileinfo2link($fileinfo, $url);
1417 1417
 				if ($props && isset($props[$url]))
1418 1418
 				{
1419
-					foreach($props[$url] as $prop)
1419
+					foreach ($props[$url] as $prop)
1420 1420
 					{
1421 1421
 						if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'] == 'comment')
1422 1422
 						{
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
 	 */
1439 1439
 	static private function decode_htmlspecialchars($str)
1440 1440
 	{
1441
-		return str_replace(array('&amp;','&quot;','&lt;','&gt;'),array('&','"','<','>'),$str);
1441
+		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $str);
1442 1442
 	}
1443 1443
 
1444 1444
 	/**
@@ -1456,18 +1456,18 @@  discard block
 block discarded – undo
1456 1456
 	 * @param string $id id in $app of the updated entry
1457 1457
 	 * @param array $data =null updated data of changed entry, as the read-method of the BO-layer would supply it
1458 1458
 	 */
1459
-	static function notify_update($app,$id,$data=null)
1459
+	static function notify_update($app, $id, $data = null)
1460 1460
 	{
1461
-		self::delete_cache($app,$id);
1461
+		self::delete_cache($app, $id);
1462 1462
 		//error_log(__METHOD__."('$app', $id, $data)");
1463
-		foreach(self::get_links($app,$id,'!'.self::VFS_APPNAME) as $link_id => $link)
1463
+		foreach (self::get_links($app, $id, '!'.self::VFS_APPNAME) as $link_id => $link)
1464 1464
 		{
1465
-			self::notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data);
1465
+			self::notify('update', $link['app'], $link['id'], $app, $id, $link_id, $data);
1466 1466
 		}
1467
-		if($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse())
1467
+		if ($data[Link::OLD_LINK_TITLE] && Json\Response::isJSONResponse())
1468 1468
 		{
1469 1469
 			// Update client side with new title
1470
-			Json\Response::get()->apply('egw.link_title_callback',array(array($app => array($id => self::title($app, $id)))));
1470
+			Json\Response::get()->apply('egw.link_title_callback', array(array($app => array($id => self::title($app, $id)))));
1471 1471
 		}
1472 1472
 	}
1473 1473
 
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
 	 * @param string $target_id id in $target_app
1492 1492
 	 * @param array $data =null data of entry in app2 (optional)
1493 1493
 	 */
1494
-	static private function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null)
1494
+	static private function notify($type, $notify_app, $notify_id, $target_app, $target_id, $link_id, $data = null)
1495 1495
 	{
1496 1496
 		//error_log(__METHOD__."('$type', '$notify_app', $notify_id, '$target_app', $target_id, $link_id, $data)");
1497 1497
 		if ($link_id && isset(self::$app_register[$notify_app]) && isset(self::$app_register[$notify_app]['notify']))
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
 	static public function run_notifies()
1519 1519
 	{
1520 1520
 		//error_log(__METHOD__."() count(self::\$notifies)=".count(self::$notifies));
1521
-		while(self::$notifies)
1521
+		while (self::$notifies)
1522 1522
 		{
1523 1523
 			$args = array_shift(self::$notifies);
1524 1524
 			$method = $args['method'];
@@ -1536,11 +1536,11 @@  discard block
 block discarded – undo
1536 1536
 	 */
1537 1537
 	static private function notify_unlink(&$links)
1538 1538
 	{
1539
-		foreach($links as $link)
1539
+		foreach ($links as $link)
1540 1540
 		{
1541 1541
 			// we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink
1542
-			self::notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']);
1543
-			self::notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']);
1542
+			self::notify('unlink', $link['link_app1'], $link['link_id1'], $link['link_app2'], $link['link_id2'], $link['link_id']);
1543
+			self::notify('unlink', $link['link_app2'], $link['link_id2'], $link['link_app1'], $link['link_id1'], $link['link_id']);
1544 1544
 		}
1545 1545
 	}
1546 1546
 
@@ -1552,14 +1552,14 @@  discard block
 block discarded – undo
1552 1552
 	 * @param string $type ='title' 'title' or 'file_access'
1553 1553
 	 * @return int|string can be null, if cache not yet set
1554 1554
 	 */
1555
-	private static function &get_cache($app,$id,$type = 'title')
1555
+	private static function &get_cache($app, $id, $type = 'title')
1556 1556
 	{
1557
-		switch($type)
1557
+		switch ($type)
1558 1558
 		{
1559 1559
 			case 'title':
1560 1560
 				if ($app == self::VFS_APPNAME)
1561 1561
 				{
1562
-					return null;	// do not cache file titles, they are just the names
1562
+					return null; // do not cache file titles, they are just the names
1563 1563
 				}
1564 1564
 				return self::$title_cache[$app.':'.$id];
1565 1565
 			case 'file_access':
@@ -1581,7 +1581,7 @@  discard block
 block discarded – undo
1581 1581
 	 * @param string $title title string or null
1582 1582
 	 * @param int $file_access =null Acl::READ, Acl::EDIT or both or'ed together
1583 1583
 	 */
1584
-	public static function set_cache($app,$id,$title,$file_access=null)
1584
+	public static function set_cache($app, $id, $title, $file_access = null)
1585 1585
 	{
1586 1586
 		//error_log(__METHOD__."($app,$id,$title,$file_access)");
1587 1587
 		// do not cache file titles, they are just the names
@@ -1601,7 +1601,7 @@  discard block
 block discarded – undo
1601 1601
 	 * @param string $app app-name or null to delete the whole cache
1602 1602
 	 * @param int|string $id id or null to delete only file_access cache of given app (keeps title cache, if app implements file_access!)
1603 1603
 	 */
1604
-	private static function delete_cache($app,$id)
1604
+	private static function delete_cache($app, $id)
1605 1605
 	{
1606 1606
 		unset(self::$title_cache[$app.':'.$id]);
1607 1607
 		unset(self::$file_access_cache[$app.':'.$id]);
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
 	 * @param boolean $ignore_mime =false true: return id, even if nothing registered for given mime-type
1617 1617
 	 * @return string|null md5 hash of stored data of server-side supported mime-type or null otherwise
1618 1618
 	 */
1619
-	public static function set_data($mime_type, $method, array $params, $ignore_mime=false)
1619
+	public static function set_data($mime_type, $method, array $params, $ignore_mime = false)
1620 1620
 	{
1621 1621
 		if (!$ignore_mime && (!($info = self::get_mime_info($mime_type)) || empty($info['mime_data'])))
1622 1622
 		{
@@ -1637,7 +1637,7 @@  discard block
 block discarded – undo
1637 1637
 	 * @return mixed null if id is not found or invalid
1638 1638
 	 * @throws Exception\WrongParameter
1639 1639
 	 */
1640
-	public static function get_data($id, $return_resource=false)
1640
+	public static function get_data($id, $return_resource = false)
1641 1641
 	{
1642 1642
 		$data = Cache::getSession(__CLASS__, $id);
1643 1643
 
@@ -1662,7 +1662,7 @@  discard block
 block discarded – undo
1662 1662
 			{
1663 1663
 				$fp = $ret;
1664 1664
 				$ret = '';
1665
-				while(!feof($fp))
1665
+				while (!feof($fp))
1666 1666
 				{
1667 1667
 					$ret .= fread($fp, 8192);
1668 1668
 				}
@@ -1687,13 +1687,13 @@  discard block
 block discarded – undo
1687 1687
 	 * @param int $user =null default null = current user
1688 1688
 	 * @return boolean true if access granted, false otherwise
1689 1689
 	 */
1690
-	static function file_access($app,$id,$required=Acl::READ,$rel_path=null,$user=null)
1690
+	static function file_access($app, $id, $required = Acl::READ, $rel_path = null, $user = null)
1691 1691
 	{
1692 1692
 		// are we called for an other user
1693 1693
 		if ($user && $user != $GLOBALS['egw_info']['user']['account_id'])
1694 1694
 		{
1695 1695
 			// check if app supports file_access WITH 4th $user parameter --> return false if not
1696
-			if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access')))
1696
+			if (!self::get_registry($app, 'file_access_user') || !($method = self::get_registry($app, 'file_access')))
1697 1697
 			{
1698 1698
 				$ret = false;
1699 1699
 				$err = "(no file_access_user)";
@@ -1707,22 +1707,22 @@  discard block
 block discarded – undo
1707 1707
 			return $ret;
1708 1708
 		}
1709 1709
 
1710
-		$cache =& self::get_cache($app,$id,'file_access');
1710
+		$cache = & self::get_cache($app, $id, 'file_access');
1711 1711
 
1712
-		if (!isset($cache) || $required == Acl::EDIT && !($cache & $required))
1712
+		if (!isset($cache) || $required == Acl::EDIT && !($cache&$required))
1713 1713
 		{
1714
-			if(($method = self::get_registry($app,'file_access')))
1714
+			if (($method = self::get_registry($app, 'file_access')))
1715 1715
 			{
1716 1716
 				$cache |= self::exec($method, array($id, $required, $rel_path)) ? $required|Acl::READ : 0;
1717 1717
 			}
1718 1718
 			else
1719 1719
 			{
1720
-				$cache |= self::title($app,$id) ? Acl::READ|Acl::EDIT : 0;
1720
+				$cache |= self::title($app, $id) ? Acl::READ|Acl::EDIT : 0;
1721 1721
 			}
1722 1722
 			//error_log(__METHOD__."($app,$id,$required,$rel_path) got $cache --> ".($cache & $required ? 'true' : 'false'));
1723 1723
 		}
1724 1724
 		//else error_log(__METHOD__."($app,$id,$required,$rel_path) using cached value $cache --> ".($cache & $required ? 'true' : 'false'));
1725
-		return !!($cache & $required);
1725
+		return !!($cache&$required);
1726 1726
 	}
1727 1727
 
1728 1728
 	/**
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
 	 * @param array $params array with arguments incl. references
1736 1736
 	 * @return mixed
1737 1737
 	 */
1738
-	protected static function exec($method, array $params=array())
1738
+	protected static function exec($method, array $params = array())
1739 1739
 	{
1740 1740
 		static $objs = array();
1741 1741
 
Please login to merge, or discard this patch.
Braces   +174 added lines, -48 removed lines patch added patch discarded remove patch
@@ -307,13 +307,16 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	static function save_session_cache()
309 309
 	{
310
-		if (isset($GLOBALS['egw']->session))	// eg. cron-jobs use it too, without any session
310
+		if (isset($GLOBALS['egw']->session))
311
+		{
312
+			// eg. cron-jobs use it too, without any session
311 313
 		{
312 314
 			//error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache));
313 315
 
314 316
 			if (count(self::$title_cache > self::TITLE_CACHE_SIZE))
315 317
 			{
316 318
 				self::$title_cache = array_slice(self::$title_cache, -self::TITLE_CACHE_SIZE);
319
+		}
317 320
 			}
318 321
 			Cache::setSession(__CLASS__, 'link_title_cache', self::$title_cache);
319 322
 
@@ -364,14 +367,20 @@  discard block
 block discarded – undo
364 367
 			$link_id = True;
365 368
 			while ($link_id && list(,$link) = each($app2))
366 369
 			{
367
-				if (!is_array($link))	// check for unlink-marker
370
+				if (!is_array($link))
371
+				{
372
+					// check for unlink-marker
368 373
 				{
369 374
 					//echo "<b>link='$link' is no array</b><br>\n";
370 375
 					continue;
371 376
 				}
372
-				if (is_array($id1) || !$id1)		// create link only in $id1 array
377
+				}
378
+				if (is_array($id1) || !$id1)
379
+				{
380
+					// create link only in $id1 array
373 381
 				{
374 382
 					self::link($app1, $id1, $link['app'], $link['id'], $link['remark'],$link['owner'],$link['lastmod']);
383
+				}
375 384
 					continue;
376 385
 				}
377 386
 				switch ($link['app'])
@@ -395,18 +404,27 @@  discard block
 block discarded – undo
395 404
 						$link_id = Link\Storage::link($app1,$id1,$link['app'],$link['id'],
396 405
 							$link['remark'],$link['owner'],$link['lastmod']);
397 406
 						// notify both sides
398
-						if (!($no_notify&2)) self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
399
-						if (!($no_notify&1)) self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
407
+						if (!($no_notify&2))
408
+						{
409
+							self::notify('link',$link['app'],$link['id'],$app1,$id1,$link_id);
410
+						}
411
+						if (!($no_notify&1))
412
+						{
413
+							self::notify('link',$app1,$id1,$link['app'],$link['id'],$link_id);
414
+						}
400 415
 						break;
401 416
 				}
402 417
 			}
403 418
 			return $link_id;
404 419
 		}
405
-		if (is_array($id1) || !$id1)		// create link only in $id1 array
420
+		if (is_array($id1) || !$id1)
421
+		{
422
+			// create link only in $id1 array
406 423
 		{
407 424
 			if (!is_array($id1))
408 425
 			{
409 426
 				$id1 = array( );
427
+		}
410 428
 			}
411 429
 			$link_id = self::temp_link_id($app2,$id2);
412 430
 
@@ -442,8 +460,14 @@  discard block
 block discarded – undo
442 460
 		}
443 461
 		$link_id = Link\Storage::link($app1,$id1,$app2,$id2,$remark,$owner);
444 462
 
445
-		if (!($no_notify&2)) self::notify('link',$app2,$id2,$app1,$id1,$link_id);
446
-		if (!($no_notify&1)) self::notify('link',$app1,$id1,$app2,$id2,$link_id);
463
+		if (!($no_notify&2))
464
+		{
465
+			self::notify('link',$app2,$id2,$app1,$id1,$link_id);
466
+		}
467
+		if (!($no_notify&1))
468
+		{
469
+			self::notify('link',$app1,$id1,$app2,$id2,$link_id);
470
+		}
447 471
 
448 472
 		return $link_id;
449 473
 	}
@@ -475,7 +499,10 @@  discard block
 block discarded – undo
475 499
 	 */
476 500
 	static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$cache_titles=false, $deleted=false, $limit=null)
477 501
 	{
478
-		if (self::DEBUG) echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
502
+		if (self::DEBUG)
503
+		{
504
+			echo "<p>Link::get_links(app='$app',id='$id',only_app='$only_app',order='$order',deleted='$deleted')</p>\n";
505
+		}
479 506
 
480 507
 		if (is_array($id) || !$id)
481 508
 		{
@@ -546,7 +573,10 @@  discard block
 block discarded – undo
546 573
 	 */
547 574
 	static function get_links_multiple($app,array $ids,$cache_titles=true,$only_app='',$order='link_lastmod DESC', $deleted=false )
548 575
 	{
549
-		if (self::DEBUG) echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
576
+		if (self::DEBUG)
577
+		{
578
+			echo "<p>".__METHOD__."('$app',".print_r($ids,true).",$cache_titles,'$only_app','$order')</p>\n";
579
+		}
550 580
 
551 581
 		if (!$ids)
552 582
 		{
@@ -578,7 +608,10 @@  discard block
 block discarded – undo
578 608
 			{
579 609
 				foreach($targets as $link)
580 610
 				{
581
-					if (is_array($link)) $app_ids[$link['app']][] = $link['id'];
611
+					if (is_array($link))
612
+					{
613
+						$app_ids[$link['app']][] = $link['id'];
614
+					}
582 615
 				}
583 616
 			}
584 617
 			foreach($app_ids as $app => $a_ids)
@@ -608,20 +641,30 @@  discard block
 block discarded – undo
608 641
 		}
609 642
 		if (is_array($id))
610 643
 		{
611
-			if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
644
+			if (strpos($app_link_id,':') === false)
645
+			{
646
+				$app_link_id = self::temp_link_id($app2,$id2);
647
+			}
648
+			// create link_id of temporary link, if not given
612 649
 
613
-			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))	// check for unlinked-marker
650
+			if (isset($id[$app_link_id]) && is_array($id[$app_link_id]))
651
+			{
652
+				// check for unlinked-marker
614 653
 			{
615 654
 				return $id[$app_link_id];
616 655
 			}
656
+			}
617 657
 			return False;
618 658
 		}
619 659
 		if ((int)$app_link_id < 0 || $app_link_id == self::VFS_APPNAME || $app2 == self::VFS_APPNAME)
620 660
 		{
621
-			if ((int)$app_link_id < 0)	// vfs link_id ?
661
+			if ((int)$app_link_id < 0)
662
+			{
663
+				// vfs link_id ?
622 664
 			{
623 665
 				return self::fileinfo2link(-$app_link_id);
624 666
 			}
667
+			}
625 668
 			if ($app_link_id == self::VFS_APPNAME)
626 669
 			{
627 670
 				return self::info_attached($app2,$id2,$id);
@@ -669,10 +712,13 @@  discard block
 block discarded – undo
669 712
 		{
670 713
 			echo "<p>Link::unlink('$link_id','$app',".array2string($id).",'$owner','$app2','$id2', $hold_for_purge)</p>\n";
671 714
 		}
672
-		if ($link_id < 0)	// vfs-link?
715
+		if ($link_id < 0)
716
+		{
717
+			// vfs-link?
673 718
 		{
674 719
 			return self::delete_attached(-$link_id);
675 720
 		}
721
+		}
676 722
 		elseif ($app == self::VFS_APPNAME)
677 723
 		{
678 724
 			return self::delete_attached($app2,$id2,$id);
@@ -711,7 +757,11 @@  discard block
 block discarded – undo
711 757
 
712 758
 			return count($deleted);
713 759
 		}
714
-		if (!$link_id) $link_id = self::temp_link_id($app2,$id2);	// create link_id of temporary link, if not given
760
+		if (!$link_id)
761
+		{
762
+			$link_id = self::temp_link_id($app2,$id2);
763
+		}
764
+		// create link_id of temporary link, if not given
715 765
 
716 766
 		if (isset($id[$link_id]))
717 767
 		{
@@ -737,7 +787,10 @@  discard block
 block discarded – undo
737 787
 		$apps = array();
738 788
 		foreach(self::$app_register as $type => $reg)
739 789
 		{
740
-			if ($must_support && !isset($reg[$must_support])) continue;
790
+			if ($must_support && !isset($reg[$must_support]))
791
+			{
792
+				continue;
793
+			}
741 794
 
742 795
 			list($app) = explode('-', $type);
743 796
 			if ($GLOBALS['egw_info']['user']['apps'][$app])
@@ -794,12 +847,18 @@  discard block
 block discarded – undo
794 847
 	 */
795 848
 	static function title($app,$id,$link=null)
796 849
 	{
797
-		if (!$id) return '';
850
+		if (!$id)
851
+		{
852
+			return '';
853
+		}
798 854
 
799 855
 		$title =& self::get_cache($app,$id);
800 856
 		if (isset($title) && !empty($title) && !is_array($id))
801 857
 		{
802
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
858
+			if (self::DEBUG)
859
+			{
860
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (from cache)</p>\n";
861
+			}
803 862
 			return $title;
804 863
 		}
805 864
 		if ($app == self::VFS_APPNAME)
@@ -819,21 +878,33 @@  discard block
 block discarded – undo
819 878
 			{
820 879
 				$title .= ': '.$link['type'] . ' '.Vfs::hsize($link['size']);
821 880
 			}*/
822
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
881
+			if (self::DEBUG)
882
+			{
883
+				echo '<p>'.__METHOD__."('$app','$id')='$title' (file)</p>\n";
884
+			}
823 885
 			return $title;
824 886
 		}
825 887
 		if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title']))
826 888
 		{
827
-			if (self::DEBUG) echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
889
+			if (self::DEBUG)
890
+			{
891
+				echo "<p>".__METHOD__."('$app','$id') something is wrong!!!</p>\n";
892
+			}
828 893
 			return false; //array(); // not sure why it should return an array on failure, as the description states boolean/string
829 894
 		}
830 895
 		$method = $reg['title'];
831 896
 
832
-		if (true) $title = self::exec($method, array($id));
897
+		if (true)
898
+		{
899
+			$title = self::exec($method, array($id));
900
+		}
833 901
 
834
-		if ($id && is_null($title))	// $app,$id has been deleted ==> unlink all links to it
902
+		if ($id && is_null($title))
903
+		{
904
+			// $app,$id has been deleted ==> unlink all links to it
835 905
 		{
836 906
 			static $unlinking = array();
907
+		}
837 908
 			// check if we are already trying to unlink the entry, to avoid an infinit recursion
838 909
 			if (!isset($unlinking[$app]) || !isset($unlinking[$app][$id]))
839 910
 			{
@@ -841,10 +912,16 @@  discard block
 block discarded – undo
841 912
 				self::unlink(0,$app,$id);
842 913
 				unset($unlinking[$app][$id]);
843 914
 			}
844
-			if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
915
+			if (self::DEBUG)
916
+			{
917
+				echo '<p>'.__METHOD__."('$app','$id') unlinked, as $method returned null</p>\n";
918
+			}
845 919
 			return False;
846 920
 		}
847
-		if (self::DEBUG) echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
921
+		if (self::DEBUG)
922
+		{
923
+			echo '<p>'.__METHOD__."('$app','$id')='$title' (from $method)</p>\n";
924
+		}
848 925
 
849 926
 		return $title;
850 927
 	}
@@ -1010,7 +1087,10 @@  discard block
 block discarded – undo
1010 1087
 			{
1011 1088
 				foreach($registry['mime'] as $mime => $data)
1012 1089
 				{
1013
-					if ($mime == $type) return $data;
1090
+					if ($mime == $type)
1091
+					{
1092
+						return $data;
1093
+					}
1014 1094
 					if ($mime[0] == '/' && preg_match($mime.'i', $type))
1015 1095
 					{
1016 1096
 						$wildcard_mime = $data;
@@ -1031,7 +1111,10 @@  discard block
 block discarded – undo
1031 1111
 	 */
1032 1112
 	static function mime_open($path, $type=null, &$popup=null)
1033 1113
 	{
1034
-		if (is_null($type)) $type = Vfs::mime_content_type($path);
1114
+		if (is_null($type))
1115
+		{
1116
+			$type = Vfs::mime_content_type($path);
1117
+		}
1035 1118
 
1036 1119
 		if (($data = self::get_mime_info($type)))
1037 1120
 		{
@@ -1099,14 +1182,20 @@  discard block
 block discarded – undo
1099 1182
 	{
1100 1183
 		$reg = self::$app_register[$app];
1101 1184
 
1102
-		if (!isset($reg)) return false;
1185
+		if (!isset($reg))
1186
+		{
1187
+			return false;
1188
+		}
1103 1189
 
1104
-		if (!isset($reg[$name]))	// some defaults
1190
+		if (!isset($reg[$name]))
1191
+		{
1192
+			// some defaults
1105 1193
 		{
1106 1194
 			switch($name)
1107 1195
 			{
1108 1196
 				case 'name':
1109 1197
 					$reg[$name] = $app;
1198
+		}
1110 1199
 					break;
1111 1200
 				case 'entry':
1112 1201
 					$reg[$name] = $app;
@@ -1145,10 +1234,12 @@  discard block
 block discarded – undo
1145 1234
 
1146 1235
 		if ($app)
1147 1236
 		{
1148
-			if( isset(self::$app_register[$app]) ) {
1237
+			if( isset(self::$app_register[$app]) )
1238
+			{
1149 1239
 				$reg = self::$app_register[$app];
1150 1240
 
1151
-				if( isset($reg['file_dir']) ) {
1241
+				if( isset($reg['file_dir']) )
1242
+				{
1152 1243
 					$app = $reg['file_dir'];
1153 1244
 				}
1154 1245
 			}
@@ -1210,7 +1301,10 @@  discard block
 block discarded – undo
1210 1301
 		if (file_exists($entry_dir) || ($Ok = mkdir($entry_dir,0,true)))
1211 1302
 		{
1212 1303
 			$Ok = Vfs::copy_uploaded($file, $p=Vfs::parse_url($entry_dir, PHP_URL_PATH), $comment, false);	// no is_uploaded_file() check!
1213
-			if (!$Ok) error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1304
+			if (!$Ok)
1305
+			{
1306
+				error_log(__METHOD__."('$app', '$id', ".array2string($file).", '$comment') called Vfs::copy_uploaded('$file[tmp_name]', '$p', '$comment', false)=".array2string($Ok));
1307
+			}
1214 1308
 		}
1215 1309
 		else
1216 1310
 		{
@@ -1230,7 +1324,10 @@  discard block
 block discarded – undo
1230 1324
 	static function link_file($app,$id,$file)
1231 1325
 	{
1232 1326
 		// Don't try to link into app dir if there is no id
1233
-		if(!$id) return;
1327
+		if(!$id)
1328
+		{
1329
+			return;
1330
+		}
1234 1331
 
1235 1332
 		if (!Vfs::stat($file))
1236 1333
 		{
@@ -1257,10 +1354,13 @@  discard block
 block discarded – undo
1257 1354
 	 */
1258 1355
 	static function delete_attached($app,$id='',$fname='')
1259 1356
 	{
1260
-		if ((int)$app > 0)	// is file_id
1357
+		if ((int)$app > 0)
1358
+		{
1359
+			// is file_id
1261 1360
 		{
1262 1361
 			$url = Vfs::resolve_url(Vfs\Sqlfs\StreamWrapper::id2path($app));
1263 1362
 		}
1363
+		}
1264 1364
 		else
1265 1365
 		{
1266 1366
 			if (empty($app) || empty($id))
@@ -1269,9 +1369,12 @@  discard block
 block discarded – undo
1269 1369
 			}
1270 1370
 			$url = self::vfs_path($app,$id,$fname);
1271 1371
 
1272
-			if (!$fname || !$id)	// we delete the whole entry (or all entries), which probably not exist anymore
1372
+			if (!$fname || !$id)
1373
+			{
1374
+				// we delete the whole entry (or all entries), which probably not exist anymore
1273 1375
 			{
1274 1376
 				$current_is_root = Vfs::$is_root;
1377
+			}
1275 1378
 				Vfs::$is_root = true;
1276 1379
 			}
1277 1380
 		}
@@ -1291,7 +1394,10 @@  discard block
 block discarded – undo
1291 1394
 		if (($Ok = !file_exists($url) || Vfs::remove($url,true)) && ((int)$app > 0 || $fname))
1292 1395
 		{
1293 1396
 			// try removing the dir, in case it's empty
1294
-			if (($dir = Vfs::dirname($url))) @Vfs::rmdir($dir);
1397
+			if (($dir = Vfs::dirname($url)))
1398
+			{
1399
+				@Vfs::rmdir($dir);
1400
+			}
1295 1401
 		}
1296 1402
 		if (!is_null($current_is_root))
1297 1403
 		{
@@ -1338,8 +1444,10 @@  discard block
 block discarded – undo
1338 1444
 		$up = explode('/',$url[0] == '/' ? $url : parse_url($url,PHP_URL_PATH));	// /apps/$app/$id
1339 1445
 		$app = null;
1340 1446
 
1341
-		foreach( self::$app_register as $tapp => $reg ) {
1342
-			if( isset($reg['file_dir']) ) {
1447
+		foreach( self::$app_register as $tapp => $reg )
1448
+		{
1449
+			if( isset($reg['file_dir']) )
1450
+			{
1343 1451
 				$lup = $up;
1344 1452
 
1345 1453
 				unset($lup[0]);
@@ -1351,20 +1459,25 @@  discard block
 block discarded – undo
1351 1459
 
1352 1460
 				$found = true;
1353 1461
 
1354
-				foreach( $fdp as $part ) {
1355
-					if( current($lup) == $part ) {
1356
-						if( next($lup) === false ) {
1462
+				foreach( $fdp as $part )
1463
+				{
1464
+					if( current($lup) == $part )
1465
+					{
1466
+						if( next($lup) === false )
1467
+						{
1357 1468
 							$found = false;
1358 1469
 							break;
1359 1470
 						}
1360 1471
 					}
1361
-					else {
1472
+					else
1473
+					{
1362 1474
 						$found = false;
1363 1475
 						break;
1364 1476
 					}
1365 1477
 				}
1366 1478
 
1367
-				if( $found ) {
1479
+				if( $found )
1480
+				{
1368 1481
 					$id	= current($lup);
1369 1482
 					$app = $tapp;
1370 1483
 					break;
@@ -1372,7 +1485,8 @@  discard block
 block discarded – undo
1372 1485
 			}
1373 1486
 		}
1374 1487
 
1375
-		if( $app === null ) {
1488
+		if( $app === null )
1489
+		{
1376 1490
 			list(,,$app,$id) = $up;
1377 1491
 		}
1378 1492
 
@@ -1402,10 +1516,16 @@  discard block
 block discarded – undo
1402 1516
 		$path = self::vfs_path($app,$id);
1403 1517
 		//error_log(__METHOD__."($app,$id) url=$url");
1404 1518
 
1405
-		if (!($extra = self::get_registry($app,'find_extra'))) $extra = array();
1519
+		if (!($extra = self::get_registry($app,'find_extra')))
1520
+		{
1521
+			$extra = array();
1522
+		}
1406 1523
 
1407 1524
 		// always use regular links stream wrapper here: extended one is unnecessary (slow) for just listing attachments
1408
-		if (substr($path,0,13) == 'stylite.links') $path = substr($path,8);
1525
+		if (substr($path,0,13) == 'stylite.links')
1526
+		{
1527
+			$path = substr($path,8);
1528
+		}
1409 1529
 
1410 1530
 		$attached = array();
1411 1531
 		if (($url2stats = Vfs::find($path,array('need_mime'=>true,'type'=>'F','url'=>true)+$extra,true)))
@@ -1648,7 +1768,10 @@  discard block
 block discarded – undo
1648 1768
 		$method = array_shift($data);
1649 1769
 		$ret = self::exec($method, $data);
1650 1770
 
1651
-		if (is_resource($ret)) fseek($ret, 0);
1771
+		if (is_resource($ret))
1772
+		{
1773
+			fseek($ret, 0);
1774
+		}
1652 1775
 
1653 1776
 		if ($return_resource != is_resource($ret))
1654 1777
 		{
@@ -1746,7 +1869,10 @@  discard block
 block discarded – undo
1746 1869
 		}
1747 1870
 
1748 1871
 		list($app, $class, $m) = $parts = explode('.', $method);
1749
-		if (count($parts) != 3) throw Api\Exception\WrongParameter("Wrong dot-delimited method string '$method'!");
1872
+		if (count($parts) != 3)
1873
+		{
1874
+			throw Api\Exception\WrongParameter("Wrong dot-delimited method string '$method'!");
1875
+		}
1750 1876
 
1751 1877
 		if (!isset($objs[$class]))
1752 1878
 		{
Please login to merge, or discard this patch.
api/src/Contacts/Tracking.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -106,17 +106,17 @@  discard block
 block discarded – undo
106 106
 	 * @param array $old =null old/last state of the entry or null for a new entry
107 107
 	 * @return mixed
108 108
 	 */
109
-	function get_config($name,$data,$old=null)
109
+	function get_config($name, $data, $old = null)
110 110
 	{
111
-		unset($old);	// not used, but required by function signature
111
+		unset($old); // not used, but required by function signature
112 112
 
113
-		switch($name)
113
+		switch ($name)
114 114
 		{
115 115
 			case 'copy':
116 116
 				if ($data['is_contactform'])
117 117
 				{
118
-					$copy = preg_split('/, ?/',$data['email_contactform']);
119
-					if  ($data['email_copytoreceiver']) $copy[] = $data['email'];
118
+					$copy = preg_split('/, ?/', $data['email_contactform']);
119
+					if ($data['email_copytoreceiver']) $copy[] = $data['email'];
120 120
 					return $copy;
121 121
 				}
122 122
 				break;
@@ -144,27 +144,27 @@  discard block
 block discarded – undo
144 144
 	 * @param array $changed_fields =null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
145 145
 	 * @return int number of log-entries made
146 146
 	 */
147
-	protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
147
+	protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null)
148 148
 	{
149 149
 		if (is_null($changed_fields))
150 150
 		{
151
-			$changed_fields = self::changed_fields($data,$old);
151
+			$changed_fields = self::changed_fields($data, $old);
152 152
 		}
153 153
 		if (!$changed_fields) return 0;
154 154
 
155
-		foreach(array('adr_one_countryname' => 'adr_one_countrycode', 'adr_two_countryname' => 'adr_two_countrycode') as $name => $code)
155
+		foreach (array('adr_one_countryname' => 'adr_one_countrycode', 'adr_two_countryname' => 'adr_two_countrycode') as $name => $code)
156 156
 		{
157 157
 			// Only codes involved, but old text name is automatically added when loaded
158
-			if($old[$code] && $data[$code] && ($key = array_search($name, $changed_fields)) !== false)
158
+			if ($old[$code] && $data[$code] && ($key = array_search($name, $changed_fields)) !== false)
159 159
 			{
160 160
 				unset($changed_fields[$key]);
161 161
 				continue;
162 162
 			}
163 163
 
164 164
 			// Code and a text name
165
-			if(in_array($name, $changed_fields) && in_array($code, $changed_fields))
165
+			if (in_array($name, $changed_fields) && in_array($code, $changed_fields))
166 166
 			{
167
-				if($data[$code])
167
+				if ($data[$code])
168 168
 				{
169 169
 					$data[$name] = Api\Country::get_full_name($data[$code], true);
170 170
 				}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			}
173 173
 		}
174 174
 		//error_log(__METHOD__.__LINE__.' ChangedFields:'.array2string($changed_fields));
175
-		return parent::save_history($data,$old,$deleted,$changed_fields);
175
+		return parent::save_history($data, $old, $deleted, $changed_fields);
176 176
 	}
177 177
 
178 178
 	/**
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 	 * @param int|string $receiver nummeric account_id or email address
184 184
 	 * @return string
185 185
 	 */
186
-	protected function get_message($data,$old,$receiver=null)
186
+	protected function get_message($data, $old, $receiver = null)
187 187
 	{
188
-		unset($receiver);	// not used, but required by function signature
188
+		unset($receiver); // not used, but required by function signature
189 189
 
190 190
 		if (!$data['modified'] || !$old)
191 191
 		{
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 	 * @param int|string $receiver nummeric account_id or email address
208 208
 	 * @return string
209 209
 	 */
210
-	protected function get_subject($data,$old,$deleted=null,$receiver=null)
210
+	protected function get_subject($data, $old, $deleted = null, $receiver = null)
211 211
 	{
212
-		unset($old, $deleted, $receiver);	// not used, but required by function signature
212
+		unset($old, $deleted, $receiver); // not used, but required by function signature
213 213
 
214 214
 		if ($data['is_contactform'])
215 215
 		{
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
 	 * @param int|string $receiver nummeric account_id or email address
226 226
 	 * @return array of details as array with values for keys 'label','value','type'
227 227
 	 */
228
-	function get_details($data,$receiver=null)
228
+	function get_details($data, $receiver = null)
229 229
 	{
230
-		unset($receiver);	// not used, but required by function signature
230
+		unset($receiver); // not used, but required by function signature
231 231
 
232
-		foreach($this->contacts->contact_fields as $name => $label)
232
+		foreach ($this->contacts->contact_fields as $name => $label)
233 233
 		{
234 234
 			if (!$data[$name] && $name != 'owner') continue;
235 235
 
236
-			switch($name)
236
+			switch ($name)
237 237
 			{
238 238
 				case 'n_prefix': case 'n_given': case 'n_middle': case 'n_family': case 'n_suffix':	// already in n_fn
239 239
 				case 'n_fileas': case 'id': case 'tid':
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
 					if ($data[$name])
264 264
 					{
265 265
 						$cats = array();
266
-						foreach(is_array($data[$name]) ? $data[$name] : explode(',',$data[$name]) as $cat_id)
266
+						foreach (is_array($data[$name]) ? $data[$name] : explode(',', $data[$name]) as $cat_id)
267 267
 						{
268 268
 							$cats[] = $GLOBALS['egw']->cats->id2name($cat_id);
269 269
 						}
270 270
 						$details[$name] = array(
271 271
 							'label' => $label,
272
-							'value' => explode(', ',$cats),
272
+							'value' => explode(', ', $cats),
273 273
 						);
274 274
 					}
275 275
 				case 'note':
Please login to merge, or discard this patch.
Braces   +12 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,7 +116,10 @@  discard block
 block discarded – undo
116 116
 				if ($data['is_contactform'])
117 117
 				{
118 118
 					$copy = preg_split('/, ?/',$data['email_contactform']);
119
-					if  ($data['email_copytoreceiver']) $copy[] = $data['email'];
119
+					if  ($data['email_copytoreceiver'])
120
+					{
121
+						$copy[] = $data['email'];
122
+					}
120 123
 					return $copy;
121 124
 				}
122 125
 				break;
@@ -150,7 +153,10 @@  discard block
 block discarded – undo
150 153
 		{
151 154
 			$changed_fields = self::changed_fields($data,$old);
152 155
 		}
153
-		if (!$changed_fields) return 0;
156
+		if (!$changed_fields)
157
+		{
158
+			return 0;
159
+		}
154 160
 
155 161
 		foreach(array('adr_one_countryname' => 'adr_one_countrycode', 'adr_two_countryname' => 'adr_two_countrycode') as $name => $code)
156 162
 		{
@@ -231,7 +237,10 @@  discard block
 block discarded – undo
231 237
 
232 238
 		foreach($this->contacts->contact_fields as $name => $label)
233 239
 		{
234
-			if (!$data[$name] && $name != 'owner') continue;
240
+			if (!$data[$name] && $name != 'owner')
241
+			{
242
+				continue;
243
+			}
235 244
 
236 245
 			switch($name)
237 246
 			{
Please login to merge, or discard this patch.
api/src/Contacts/Univention.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
 	 * @param array $keys if given $keys are copied to data before saveing => allows a save as
36 36
 	 * @return int 0 on success and errno != 0 else
37 37
 	 */
38
-	function save($keys=null)
38
+	function save($keys = null)
39 39
 	{
40 40
 		// UCS lowercases email when storing
41 41
 		$keys['email'] = strtolower(!empty($keys['email']) ? $keys['email'] : $this->data['email']);
Please login to merge, or discard this patch.
api/src/Vfs/Sqlfs/StreamWrapper.php 4 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -447,10 +447,10 @@  discard block
 block discarded – undo
447 447
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
448 448
  	 *
449 449
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
450
-  	 * {
450
+ 	 * {
451 451
  	 * 		$eof = !$eof;
452 452
  	 * }
453
-  	 *
453
+ 	 *
454 454
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
455 455
  	 */
456 456
 	function stream_eof ( )
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
  	 * See fseek() for more information about these parameters.
486 486
  	 *
487 487
  	 * @param integer $offset
488
-  	 * @param integer $whence	SEEK_SET - 0 - Set position equal to offset bytes
488
+ 	 * @param integer $whence	SEEK_SET - 0 - Set position equal to offset bytes
489 489
  	 * 							SEEK_CUR - 1 - Set position to current location plus offset.
490 490
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
491 491
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 		$maxdepth=10;
682 682
 		$depth2propagate = (int)$depth + 1;
683 683
 		if ($depth2propagate > $maxdepth) return is_dir($pathname);
684
-    	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
685
-    	return is_dir($pathname) || @mkdir($pathname, $mode);
684
+		is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
685
+		return is_dir($pathname) || @mkdir($pathname, $mode);
686 686
 	}
687 687
 
688 688
 	/**
Please login to merge, or discard this patch.
Braces   +423 added lines, -106 removed lines patch added patch discarded remove patch
@@ -189,7 +189,10 @@  discard block
 block discarded – undo
189 189
 	 */
190 190
 	function stream_open ( $url, $mode, $options, &$opened_path, array $overwrite_new=null )
191 191
 	{
192
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
192
+		if (self::LOG_LEVEL > 1)
193
+		{
194
+			error_log(__METHOD__."($url,$mode,$options)");
195
+		}
193 196
 
194 197
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
195 198
 		$this->operation = self::url2operation($url);
@@ -201,7 +204,9 @@  discard block
 block discarded – undo
201 204
 
202 205
 		parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params);
203 206
 
204
-		if (!is_null($overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
207
+		if (!is_null($overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')
208
+		{
209
+			// file not found or file should NOT exist
205 210
 		{
206 211
 			if (!$dir || $mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
207 212
 				$mode[0] == 'x' && $stat ||	// or file should not exist, but does
@@ -209,7 +214,11 @@  discard block
 block discarded – undo
209 214
 				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat))	// or we are not allowed to 																																			create it
210 215
 			{
211 216
 				self::_remove_password($url);
212
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
217
+		}
218
+				if (self::LOG_LEVEL)
219
+				{
220
+					error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
221
+				}
213 222
 				if (($options & STREAM_REPORT_ERRORS))
214 223
 				{
215 224
 					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
@@ -221,7 +230,10 @@  discard block
 block discarded – undo
221 230
 			$new_file = true;
222 231
 			$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_active'.
223 232
 				') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_active)';
224
-			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
233
+			if (self::LOG_LEVEL > 2)
234
+			{
235
+				$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
236
+			}
225 237
 			$stmt = self::$pdo->prepare($query);
226 238
 			$values = array(
227 239
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
@@ -239,11 +251,17 @@  discard block
 block discarded – undo
239 251
 				'fs_size'     => 0,
240 252
 				'fs_active'   => self::_pdo_boolean(true),
241 253
 			);
242
-			if ($overwrite_new) $values = array_merge($values,$overwrite_new);
254
+			if ($overwrite_new)
255
+			{
256
+				$values = array_merge($values,$overwrite_new);
257
+			}
243 258
 			if (!$stmt->execute($values) || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq')))
244 259
 			{
245 260
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
246
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo());
261
+				if (self::LOG_LEVEL)
262
+				{
263
+					error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo());
264
+				}
247 265
 				return false;
248 266
 			}
249 267
 			if ($this->operation == self::STORE2DB)
@@ -255,14 +273,20 @@  discard block
 block discarded – undo
255 273
 			elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id))))
256 274
 			{
257 275
 				$umaskbefore = umask();
258
-				if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
276
+				if (self::LOG_LEVEL > 1)
277
+				{
278
+					error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
279
+				}
259 280
 				self::mkdir_recursive($fs_dir,0700,true);
260 281
 			}
261 282
 		}
262 283
 		// check if opend file is a directory
263 284
 		elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR)
264 285
 		{
265
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!");
286
+				if (self::LOG_LEVEL)
287
+				{
288
+					error_log(__METHOD__."($url,$mode,$options) Is a directory!");
289
+				}
266 290
 				if (($options & STREAM_REPORT_ERRORS))
267 291
 				{
268 292
 					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING);
@@ -273,11 +297,17 @@  discard block
 block discarded – undo
273 297
 		else
274 298
 		{
275 299
 			if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read
276
-				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// or edit it
300
+				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))
301
+			{
302
+				// or edit it
277 303
 			{
278 304
 				self::_remove_password($url);
305
+			}
279 306
 				$op = $mode == 'r' ? 'read' : 'edited';
280
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
307
+				if (self::LOG_LEVEL)
308
+				{
309
+					error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
310
+				}
281 311
 				if (($options & STREAM_REPORT_ERRORS))
282 312
 				{
283 313
 					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING);
@@ -309,7 +339,10 @@  discard block
 block discarded – undo
309 339
 		// do we operate directly on the filesystem --> open file from there
310 340
 		if ($this->operation == self::STORE2FS)
311 341
 		{
312
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
342
+			if (self::LOG_LEVEL > 1)
343
+			{
344
+				error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
345
+			}
313 346
 			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file)
314 347
 			{
315 348
 				// delete db entry again, if we are not able to open a new(!) file
@@ -318,11 +351,17 @@  discard block
 block discarded – undo
318 351
 				$stmt->execute(array('fs_id' => $this->opened_fs_id));
319 352
 			}
320 353
 		}
321
-		if ($mode[0] == 'a')	// append modes: a, a+
354
+		if ($mode[0] == 'a')
355
+		{
356
+			// append modes: a, a+
322 357
 		{
323 358
 			$this->stream_seek(0,SEEK_END);
324 359
 		}
325
-		if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
360
+		}
361
+		if (!is_resource($this->opened_stream))
362
+		{
363
+			error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
364
+		}
326 365
 
327 366
 		return is_resource($this->opened_stream);
328 367
 	}
@@ -334,7 +373,10 @@  discard block
 block discarded – undo
334 373
 	 */
335 374
 	function stream_close ( )
336 375
 	{
337
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
376
+		if (self::LOG_LEVEL > 1)
377
+		{
378
+			error_log(__METHOD__."()");
379
+		}
338 380
 
339 381
 		if (is_null($this->opened_path) || !is_resource($this->opened_stream) || !$this->opened_fs_id)
340 382
 		{
@@ -404,7 +446,10 @@  discard block
 block discarded – undo
404 446
 	 */
405 447
 	function stream_read ( $count )
406 448
 	{
407
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos");
449
+		if (self::LOG_LEVEL > 1)
450
+		{
451
+			error_log(__METHOD__."($count) pos=$this->opened_pos");
452
+		}
408 453
 
409 454
 		if (is_resource($this->opened_stream))
410 455
 		{
@@ -426,7 +471,10 @@  discard block
 block discarded – undo
426 471
 	 */
427 472
 	function stream_write ( $data )
428 473
 	{
429
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)");
474
+		if (self::LOG_LEVEL > 1)
475
+		{
476
+			error_log(__METHOD__."($data)");
477
+		}
430 478
 
431 479
 		if (is_resource($this->opened_stream))
432 480
 		{
@@ -463,7 +511,10 @@  discard block
 block discarded – undo
463 511
 	 */
464 512
  	function stream_tell ( )
465 513
  	{
466
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
514
+		if (self::LOG_LEVEL > 1)
515
+		{
516
+			error_log(__METHOD__."()");
517
+		}
467 518
 
468 519
 		if (is_resource($this->opened_stream))
469 520
 		{
@@ -486,7 +537,10 @@  discard block
 block discarded – undo
486 537
  	 */
487 538
 	function stream_seek ( $offset, $whence )
488 539
 	{
489
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)");
540
+		if (self::LOG_LEVEL > 1)
541
+		{
542
+			error_log(__METHOD__."($offset,$whence)");
543
+		}
490 544
 
491 545
 		if (is_resource($this->opened_stream))
492 546
 		{
@@ -504,7 +558,10 @@  discard block
 block discarded – undo
504 558
 	 */
505 559
 	function stream_flush ( )
506 560
 	{
507
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
561
+		if (self::LOG_LEVEL > 1)
562
+		{
563
+			error_log(__METHOD__."()");
564
+		}
508 565
 
509 566
 		if (is_resource($this->opened_stream))
510 567
 		{
@@ -529,7 +586,10 @@  discard block
 block discarded – undo
529 586
 	 */
530 587
 	function stream_stat ( )
531 588
 	{
532
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)");
589
+		if (self::LOG_LEVEL > 1)
590
+		{
591
+			error_log(__METHOD__."($this->opened_path)");
592
+		}
533 593
 
534 594
 		return $this->url_stat($this->opened_path,0);
535 595
 	}
@@ -545,7 +605,10 @@  discard block
 block discarded – undo
545 605
 	 */
546 606
 	function unlink ( $url, $parent_stat=null )
547 607
 	{
548
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
608
+		if (self::LOG_LEVEL > 1)
609
+		{
610
+			error_log(__METHOD__."($url)");
611
+		}
549 612
 
550 613
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
551 614
 
@@ -560,13 +623,19 @@  discard block
 block discarded – undo
560 623
 			!$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat))
561 624
 		{
562 625
 			self::_remove_password($url);
563
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
626
+			if (self::LOG_LEVEL)
627
+			{
628
+				error_log(__METHOD__."($url) permission denied!");
629
+			}
564 630
 			return false;	// no permission or file does not exist
565 631
 		}
566 632
 		if ($stat['mime'] == self::DIR_MIME_TYPE)
567 633
 		{
568 634
 			self::_remove_password($url);
569
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!");
635
+			if (self::LOG_LEVEL)
636
+			{
637
+				error_log(__METHOD__."($url) is NO file!");
638
+			}
570 639
 			return false;	// no permission or file does not exist
571 640
 		}
572 641
 		$stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
@@ -601,7 +670,10 @@  discard block
 block discarded – undo
601 670
 	 */
602 671
 	function rename ( $url_from, $url_to)
603 672
 	{
604
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)");
673
+		if (self::LOG_LEVEL > 1)
674
+		{
675
+			error_log(__METHOD__."($url_from,$url_to)");
676
+		}
605 677
 
606 678
 		$path_from = Vfs::parse_url($url_from,PHP_URL_PATH);
607 679
 		$from_dir = Vfs::dirname($path_from);
@@ -614,14 +686,20 @@  discard block
 block discarded – undo
614 686
 		{
615 687
 			self::_remove_password($url_from);
616 688
 			self::_remove_password($url_to);
617
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
689
+			if (self::LOG_LEVEL)
690
+			{
691
+				error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
692
+			}
618 693
 			return false;	// no permission or file does not exist
619 694
 		}
620 695
 		if (!$to_dir || !Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = $this->url_stat($to_dir, 0)))
621 696
 		{
622 697
 			self::_remove_password($url_from);
623 698
 			self::_remove_password($url_to);
624
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
699
+			if (self::LOG_LEVEL)
700
+			{
701
+				error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
702
+			}
625 703
 			return false;	// no permission or parent-dir does not exist
626 704
 		}
627 705
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
@@ -632,14 +710,20 @@  discard block
 block discarded – undo
632 710
 			self::_remove_password($url_from);
633 711
 			self::_remove_password($url_to);
634 712
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
635
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
713
+			if (self::LOG_LEVEL)
714
+			{
715
+				error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
716
+			}
636 717
 			return false;	// no permission or file does not exist
637 718
 		}
638 719
 		// if destination file already exists, delete it
639 720
 		if ($to_stat && !static::unlink($url_to,$operation))
640 721
 		{
641 722
 			self::_remove_password($url_to);
642
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
723
+			if (self::LOG_LEVEL)
724
+			{
725
+				error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
726
+			}
643 727
 			return false;
644 728
 		}
645 729
 		unset(self::$stat_cache[$path_from]);
@@ -677,7 +761,10 @@  discard block
 block discarded – undo
677 761
 	{
678 762
 		$maxdepth=10;
679 763
 		$depth2propagate = (int)$depth + 1;
680
-		if ($depth2propagate > $maxdepth) return is_dir($pathname);
764
+		if ($depth2propagate > $maxdepth)
765
+		{
766
+			return is_dir($pathname);
767
+		}
681 768
     	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
682 769
     	return is_dir($pathname) || @mkdir($pathname, $mode);
683 770
 	}
@@ -695,14 +782,23 @@  discard block
 block discarded – undo
695 782
 	 */
696 783
 	function mkdir ( $url, $mode, $options )
697 784
 	{
698
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
699
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace());
785
+		if (self::LOG_LEVEL > 1)
786
+		{
787
+			error_log(__METHOD__."($url,$mode,$options)");
788
+		}
789
+		if (self::LOG_LEVEL > 1)
790
+		{
791
+			error_log(__METHOD__." called from:".function_backtrace());
792
+		}
700 793
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
701 794
 
702 795
 		if ($this->url_stat($path,STREAM_URL_STAT_QUIET))
703 796
 		{
704 797
 			self::_remove_password($url);
705
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!");
798
+			if (self::LOG_LEVEL)
799
+			{
800
+				error_log(__METHOD__."('$url',$mode,$options) already exist!");
801
+			}
706 802
 			if (!($options & STREAM_REPORT_ERRORS))
707 803
 			{
708 804
 				trigger_error(__METHOD__."('$url',$mode,$options) already exist!",E_USER_WARNING);
@@ -712,21 +808,30 @@  discard block
 block discarded – undo
712 808
 		if (!($parent_path = Vfs::dirname($path)))
713 809
 		{
714 810
 			self::_remove_password($url);
715
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!");
811
+			if (self::LOG_LEVEL)
812
+			{
813
+				error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!");
814
+			}
716 815
 			if (!($options & STREAM_REPORT_ERRORS))
717 816
 			{
718 817
 				trigger_error(__METHOD__."('$url',$mode,$options) dirname('$path')===false!", E_USER_WARNING);
719 818
 			}
720 819
 			return false;
721 820
 		}
722
-		if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query;
821
+		if (($query = Vfs::parse_url($url,PHP_URL_QUERY)))
822
+		{
823
+			$parent_path .= '?'.$query;
824
+		}
723 825
 		$parent = $this->url_stat($parent_path,STREAM_URL_STAT_QUIET);
724 826
 
725 827
 		// check if we should also create all non-existing path components and our parent does not exist,
726 828
 		// if yes call ourself recursive with the parent directory
727 829
 		if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
728 830
 		{
729
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode");
831
+			if (self::LOG_LEVEL > 1)
832
+			{
833
+				error_log(__METHOD__." creating parents: $parent_path, $mode");
834
+			}
730 835
 			if (!$this->mkdir($parent_path,$mode,$options))
731 836
 			{
732 837
 				return false;
@@ -736,7 +841,10 @@  discard block
 block discarded – undo
736 841
 		if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent))
737 842
 		{
738 843
 			self::_remove_password($url);
739
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!");
844
+			if (self::LOG_LEVEL)
845
+			{
846
+				error_log(__METHOD__."('$url',$mode,$options) permission denied!");
847
+			}
740 848
 			if (!($options & STREAM_REPORT_ERRORS))
741 849
 			{
742 850
 				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING);
@@ -770,10 +878,13 @@  discard block
 block discarded – undo
770 878
 				'fs_dir'  => $parent['ino'],
771 879
 				'fs_active' => self::_pdo_boolean(true),
772 880
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
773
-			)) && $stmt->fetchColumn() > 1)	// if there's more then one --> remove our new dir
881
+			)) && $stmt->fetchColumn() > 1)
882
+			{
883
+				// if there's more then one --> remove our new dir
774 884
 			{
775 885
 				self::$pdo->query('DELETE FROM '.self::TABLE.' WHERE fs_id='.$new_fs_id);
776 886
 			}
887
+			}
777 888
 		}
778 889
 		return $ok;
779 890
 	}
@@ -790,7 +901,10 @@  discard block
 block discarded – undo
790 901
 	 */
791 902
 	function rmdir ( $url, $options )
792 903
 	{
793
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
904
+		if (self::LOG_LEVEL > 1)
905
+		{
906
+			error_log(__METHOD__."($url)");
907
+		}
794 908
 
795 909
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
796 910
 
@@ -801,7 +915,10 @@  discard block
 block discarded – undo
801 915
 			self::_remove_password($url);
802 916
 			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' :
803 917
 				($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
804
-			if (self::LOG_LEVEL) error_log($err_msg);
918
+			if (self::LOG_LEVEL)
919
+			{
920
+				error_log($err_msg);
921
+			}
805 922
 			if (!($options & STREAM_REPORT_ERRORS))
806 923
 			{
807 924
 				trigger_error($err_msg,E_USER_WARNING);
@@ -813,7 +930,10 @@  discard block
 block discarded – undo
813 930
 		if ($stmt->fetchColumn())
814 931
 		{
815 932
 			self::_remove_password($url);
816
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!");
933
+			if (self::LOG_LEVEL)
934
+			{
935
+				error_log(__METHOD__."($url,$options) dir is not empty!");
936
+			}
817 937
 			if (!($options & STREAM_REPORT_ERRORS))
818 938
 			{
819 939
 				trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING);
@@ -851,7 +971,10 @@  discard block
 block discarded – undo
851 971
 	 */
852 972
 	function stream_metadata($path, $option, $value)
853 973
 	{
854
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path, $option, ".array2string($value).")");
974
+		if (self::LOG_LEVEL > 1)
975
+		{
976
+			error_log(__METHOD__."($path, $option, ".array2string($value).")");
977
+		}
855 978
 
856 979
 		switch($option)
857 980
 		{
@@ -863,14 +986,18 @@  discard block
 block discarded – undo
863 986
 
864 987
 			case STREAM_META_OWNER_NAME:
865 988
 				if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'u')) === false)
866
-					return false;
989
+				{
990
+									return false;
991
+				}
867 992
 				// fall through
868 993
 			case STREAM_META_OWNER:
869 994
 				return $this->chown($path, $value);
870 995
 
871 996
 			case STREAM_META_GROUP_NAME:
872 997
 				if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'g')) === false)
873
-					return false;
998
+				{
999
+									return false;
1000
+				}
874 1001
 				// fall through
875 1002
 			case STREAM_META_GROUP:
876 1003
 				return $this->chgrp($path, $value);
@@ -888,7 +1015,10 @@  discard block
 block discarded – undo
888 1015
 	protected function touch($url,$time=null,$atime=null)
889 1016
 	{
890 1017
 		unset($atime);	// not used
891
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)");
1018
+		if (self::LOG_LEVEL > 1)
1019
+		{
1020
+			error_log(__METHOD__."($url, $time)");
1021
+		}
892 1022
 
893 1023
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
894 1024
 
@@ -925,26 +1055,38 @@  discard block
 block discarded – undo
925 1055
 	 */
926 1056
 	protected function chown($url,$owner)
927 1057
 	{
928
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
1058
+		if (self::LOG_LEVEL > 1)
1059
+		{
1060
+			error_log(__METHOD__."($url,$owner)");
1061
+		}
929 1062
 
930 1063
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
931 1064
 
932 1065
 		$vfs = new self();
933 1066
 		if (!($stat = $vfs->url_stat($path,0)))
934 1067
 		{
935
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
1068
+			if (self::LOG_LEVEL)
1069
+			{
1070
+				error_log(__METHOD__."($url,$owner) no such file or directory!");
1071
+			}
936 1072
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
937 1073
 			return false;
938 1074
 		}
939 1075
 		if (!Vfs::$is_root)
940 1076
 		{
941
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!");
1077
+			if (self::LOG_LEVEL)
1078
+			{
1079
+				error_log(__METHOD__."($url,$owner) only root can do that!");
1080
+			}
942 1081
 			trigger_error("Only root can do that!",E_USER_WARNING);
943 1082
 			return false;
944 1083
 		}
945
-		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))	// not a user (0 == root)
1084
+		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))
1085
+		{
1086
+			// not a user (0 == root)
946 1087
 		{
947 1088
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!");
1089
+		}
948 1090
 			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING);
949 1091
 			//throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!");
950 1092
 			return false;
@@ -952,7 +1094,10 @@  discard block
 block discarded – undo
952 1094
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id');
953 1095
 
954 1096
 		// update stat-cache
955
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1097
+		if ($path != '/' && substr($path,-1) == '/')
1098
+		{
1099
+			$path = substr($path, 0, -1);
1100
+		}
956 1101
 		self::$stat_cache[$path]['fs_uid'] = $owner;
957 1102
 
958 1103
 		return $stmt->execute(array(
@@ -970,35 +1115,54 @@  discard block
 block discarded – undo
970 1115
 	 */
971 1116
 	protected function chgrp($url,$owner)
972 1117
 	{
973
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
1118
+		if (self::LOG_LEVEL > 1)
1119
+		{
1120
+			error_log(__METHOD__."($url,$owner)");
1121
+		}
974 1122
 
975 1123
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
976 1124
 
977 1125
 		$vfs = new self();
978 1126
 		if (!($stat = $vfs->url_stat($path,0)))
979 1127
 		{
980
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
1128
+			if (self::LOG_LEVEL)
1129
+			{
1130
+				error_log(__METHOD__."($url,$owner) no such file or directory!");
1131
+			}
981 1132
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
982 1133
 			return false;
983 1134
 		}
984 1135
 		if (!Vfs::has_owner_rights($path,$stat))
985 1136
 		{
986
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!");
1137
+			if (self::LOG_LEVEL)
1138
+			{
1139
+				error_log(__METHOD__."($url,$owner) only owner or root can do that!");
1140
+			}
987 1141
 			trigger_error("Only owner or root can do that!",E_USER_WARNING);
988 1142
 			return false;
989 1143
 		}
990
-		if ($owner < 0) $owner = -$owner;	// sqlfs uses a positiv group id's!
1144
+		if ($owner < 0)
1145
+		{
1146
+			$owner = -$owner;
1147
+		}
1148
+		// sqlfs uses a positiv group id's!
991 1149
 
992
-		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))	// not a group
1150
+		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))
1151
+		{
1152
+			// not a group
993 1153
 		{
994 1154
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!");
1155
+		}
995 1156
 			trigger_error("Unknown (numeric) group id!",E_USER_WARNING);
996 1157
 			return false;
997 1158
 		}
998 1159
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id');
999 1160
 
1000 1161
 		// update stat-cache
1001
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1162
+		if ($path != '/' && substr($path,-1) == '/')
1163
+		{
1164
+			$path = substr($path, 0, -1);
1165
+		}
1002 1166
 		self::$stat_cache[$path]['fs_gid'] = $owner;
1003 1167
 
1004 1168
 		return $stmt->execute(array(
@@ -1016,33 +1180,48 @@  discard block
 block discarded – undo
1016 1180
 	 */
1017 1181
 	protected function chmod($url,$mode)
1018 1182
 	{
1019
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)");
1183
+		if (self::LOG_LEVEL > 1)
1184
+		{
1185
+			error_log(__METHOD__."($url, $mode)");
1186
+		}
1020 1187
 
1021 1188
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
1022 1189
 
1023 1190
 		$vfs = new self();
1024 1191
 		if (!($stat = $vfs->url_stat($path,0)))
1025 1192
 		{
1026
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!");
1193
+			if (self::LOG_LEVEL)
1194
+			{
1195
+				error_log(__METHOD__."($url, $mode) no such file or directory!");
1196
+			}
1027 1197
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
1028 1198
 			return false;
1029 1199
 		}
1030 1200
 		if (!Vfs::has_owner_rights($path,$stat))
1031 1201
 		{
1032
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!");
1202
+			if (self::LOG_LEVEL)
1203
+			{
1204
+				error_log(__METHOD__."($url, $mode) only owner or root can do that!");
1205
+			}
1033 1206
 			trigger_error("Only owner or root can do that!",E_USER_WARNING);
1034 1207
 			return false;
1035 1208
 		}
1036
-		if (!is_numeric($mode))	// not a mode
1209
+		if (!is_numeric($mode))
1210
+		{
1211
+			// not a mode
1037 1212
 		{
1038 1213
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!");
1214
+		}
1039 1215
 			trigger_error("No (numeric) mode!",E_USER_WARNING);
1040 1216
 			return false;
1041 1217
 		}
1042 1218
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id');
1043 1219
 
1044 1220
 		// update stat cache
1045
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1221
+		if ($path != '/' && substr($path,-1) == '/')
1222
+		{
1223
+			$path = substr($path, 0, -1);
1224
+		}
1046 1225
 		self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777;
1047 1226
 
1048 1227
 		return $stmt->execute(array(
@@ -1067,12 +1246,18 @@  discard block
 block discarded – undo
1067 1246
 
1068 1247
 		if (!($stat = $this->url_stat($url,0)) || 		// dir not found
1069 1248
 			!($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ||		// no dir
1070
-			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))	// no access
1249
+			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))
1250
+		{
1251
+			// no access
1071 1252
 		{
1072 1253
 			self::_remove_password($url);
1254
+		}
1073 1255
 			$msg = !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ?
1074 1256
 				"$url is no directory" : 'permission denied';
1075
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $msg!");
1257
+			if (self::LOG_LEVEL)
1258
+			{
1259
+				error_log(__METHOD__."('$url',$options) $msg!");
1260
+			}
1076 1261
 			$this->opened_dir = null;
1077 1262
 			return false;
1078 1263
 		}
@@ -1081,7 +1266,10 @@  discard block
 block discarded – undo
1081 1266
 			' FROM '.self::TABLE.' WHERE fs_dir=? AND fs_active='.self::_pdo_boolean(true).
1082 1267
 			" ORDER BY fs_mime='httpd/unix-directory' DESC, fs_name ASC";
1083 1268
 		//if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1084
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$options)".' */ '.$query;
1269
+		if (self::LOG_LEVEL > 2)
1270
+		{
1271
+			$query = '/* '.__METHOD__."($url,$options)".' */ '.$query;
1272
+		}
1085 1273
 
1086 1274
 		$stmt = self::$pdo->prepare($query);
1087 1275
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
@@ -1093,7 +1281,10 @@  discard block
 block discarded – undo
1093 1281
 				self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file;
1094 1282
 			}
1095 1283
 		}
1096
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1284
+		if (self::LOG_LEVEL > 1)
1285
+		{
1286
+			error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1287
+		}
1097 1288
 		reset($this->opened_dir);
1098 1289
 
1099 1290
 		return true;
@@ -1132,9 +1323,16 @@  discard block
 block discarded – undo
1132 1323
 		if (is_null($max_subquery_depth))
1133 1324
 		{
1134 1325
 			$max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth'];
1135
-			if (!$max_subquery_depth) $max_subquery_depth = 7;	// setting current default of 7, if nothing set
1326
+			if (!$max_subquery_depth)
1327
+			{
1328
+				$max_subquery_depth = 7;
1329
+			}
1330
+			// setting current default of 7, if nothing set
1331
+		}
1332
+		if (self::LOG_LEVEL > 1)
1333
+		{
1334
+			error_log(__METHOD__."('$url',$flags,$eacl_access)");
1136 1335
 		}
1137
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags,$eacl_access)");
1138 1336
 
1139 1337
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
1140 1338
 
@@ -1200,7 +1398,10 @@  discard block
 block discarded – undo
1200 1398
 						if (!Vfs::$user)
1201 1399
 						{
1202 1400
 							self::_remove_password($url);
1203
-							if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!");
1401
+							if (self::LOG_LEVEL > 1)
1402
+							{
1403
+								error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!");
1404
+							}
1204 1405
 							return false;
1205 1406
 						}
1206 1407
 						$query .= ' AND '.self::_sql_readable();
@@ -1211,7 +1412,10 @@  discard block
 block discarded – undo
1211 1412
 					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')';
1212 1413
 				}
1213 1414
 			}
1214
-			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
1415
+			if (self::LOG_LEVEL > 2)
1416
+			{
1417
+				$query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
1418
+			}
1215 1419
 			//if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1216 1420
 
1217 1421
 			if (!($result = self::$pdo->query($query)) || !($info = $result->fetch(\PDO::FETCH_ASSOC)))
@@ -1234,12 +1438,18 @@  discard block
 block discarded – undo
1234 1438
 			$GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth;
1235 1439
 			error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth");
1236 1440
 			Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi');
1237
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1441
+			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
1442
+			{
1443
+				$GLOBALS['egw']->invalidate_session_cache();
1444
+			}
1238 1445
 			return $this->url_stat($url, $flags, $eacl_access);
1239 1446
 		}
1240 1447
 		self::$stat_cache[$path] = $info;
1241 1448
 
1242
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags)=".array2string($info));
1449
+		if (self::LOG_LEVEL > 1)
1450
+		{
1451
+			error_log(__METHOD__."($url,$flags)=".array2string($info));
1452
+		}
1243 1453
 		return self::_vfsinfo2stat($info);
1244 1454
 	}
1245 1455
 
@@ -1276,9 +1486,15 @@  discard block
 block discarded – undo
1276 1486
 	 */
1277 1487
 	function dir_readdir ( )
1278 1488
 	{
1279
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1489
+		if (self::LOG_LEVEL > 1)
1490
+		{
1491
+			error_log(__METHOD__."( )");
1492
+		}
1280 1493
 
1281
-		if (!is_array($this->opened_dir)) return false;
1494
+		if (!is_array($this->opened_dir))
1495
+		{
1496
+			return false;
1497
+		}
1282 1498
 
1283 1499
 		$file = current($this->opened_dir); next($this->opened_dir);
1284 1500
 
@@ -1295,9 +1511,15 @@  discard block
 block discarded – undo
1295 1511
 	 */
1296 1512
 	function dir_rewinddir ( )
1297 1513
 	{
1298
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1514
+		if (self::LOG_LEVEL > 1)
1515
+		{
1516
+			error_log(__METHOD__."( )");
1517
+		}
1299 1518
 
1300
-		if (!is_array($this->opened_dir)) return false;
1519
+		if (!is_array($this->opened_dir))
1520
+		{
1521
+			return false;
1522
+		}
1301 1523
 
1302 1524
 		reset($this->opened_dir);
1303 1525
 
@@ -1313,9 +1535,15 @@  discard block
 block discarded – undo
1313 1535
 	 */
1314 1536
 	function dir_closedir ( )
1315 1537
 	{
1316
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1538
+		if (self::LOG_LEVEL > 1)
1539
+		{
1540
+			error_log(__METHOD__."( )");
1541
+		}
1317 1542
 
1318
-		if (!is_array($this->opened_dir)) return false;
1543
+		if (!is_array($this->opened_dir))
1544
+		{
1545
+			return false;
1546
+		}
1319 1547
 
1320 1548
 		$this->opened_dir = null;
1321 1549
 
@@ -1335,7 +1563,10 @@  discard block
 block discarded – undo
1335 1563
 		$vfs = new self();
1336 1564
 		$link = !($lstat = $vfs->url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1337 1565
 
1338
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link");
1566
+		if (self::LOG_LEVEL > 1)
1567
+		{
1568
+			error_log(__METHOD__."('$path') = $link");
1569
+		}
1339 1570
 
1340 1571
 		return $link;
1341 1572
 	}
@@ -1349,23 +1580,35 @@  discard block
 block discarded – undo
1349 1580
 	 */
1350 1581
 	static function symlink($target,$link)
1351 1582
 	{
1352
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')");
1583
+		if (self::LOG_LEVEL > 1)
1584
+		{
1585
+			error_log(__METHOD__."('$target','$link')");
1586
+		}
1353 1587
 
1354 1588
 		$inst = new static();
1355 1589
 		if ($inst->url_stat($link,0))
1356 1590
 		{
1357
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1591
+			if (self::LOG_LEVEL > 0)
1592
+			{
1593
+				error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1594
+			}
1358 1595
 			return false;	// $link already exists
1359 1596
 		}
1360 1597
 		if (!($dir = Vfs::dirname($link)) ||
1361 1598
 			!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$inst->url_stat($dir,0)))
1362 1599
 		{
1363
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1600
+			if (self::LOG_LEVEL > 0)
1601
+			{
1602
+				error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1603
+			}
1364 1604
 			return false;	// parent dir does not exist or is not writable
1365 1605
 		}
1366 1606
 		$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'.
1367 1607
 			') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)';
1368
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1608
+		if (self::LOG_LEVEL > 2)
1609
+		{
1610
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1611
+		}
1369 1612
 		$stmt = self::$pdo->prepare($query);
1370 1613
 		unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]);
1371 1614
 
@@ -1413,7 +1656,10 @@  discard block
 block discarded – undo
1413 1656
 				break;
1414 1657
 			}
1415 1658
 		}
1416
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1659
+		if (self::LOG_LEVEL > 1)
1660
+		{
1661
+			error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1662
+		}
1417 1663
 		return $access;
1418 1664
 	}
1419 1665
 
@@ -1441,11 +1687,15 @@  discard block
 block discarded – undo
1441 1687
 			}
1442 1688
 		}
1443 1689
 		// sort by length descending, to allow more specific pathes to have precedence
1444
-		uksort(self::$extended_acl, function($a,$b) {
1690
+		uksort(self::$extended_acl, function($a,$b)
1691
+		{
1445 1692
 			return strlen($b)-strlen($a);
1446 1693
 		});
1447 1694
 		Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1448
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl));
1695
+		if (self::LOG_LEVEL > 1)
1696
+		{
1697
+			error_log(__METHOD__.'() '.array2string(self::$extended_acl));
1698
+		}
1449 1699
 	}
1450 1700
 
1451 1701
 	/**
@@ -1475,12 +1725,18 @@  discard block
 block discarded – undo
1475 1725
 			$vfs = new self();
1476 1726
 			if (!($stat = $vfs->url_stat($path,0)))
1477 1727
 			{
1478
-				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1728
+				if (self::LOG_LEVEL)
1729
+				{
1730
+					error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1731
+				}
1479 1732
 				return false;	// $path not found
1480 1733
 			}
1481
-			if (!Vfs::has_owner_rights($path,$stat))		// not group dir and user is eGW admin
1734
+			if (!Vfs::has_owner_rights($path,$stat))
1735
+			{
1736
+				// not group dir and user is eGW admin
1482 1737
 			{
1483 1738
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!");
1739
+			}
1484 1740
 				return false;	// permission denied
1485 1741
 			}
1486 1742
 			$fs_id = $stat['ino'];
@@ -1513,7 +1769,10 @@  discard block
 block discarded – undo
1513 1769
 		{
1514 1770
 			Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1515 1771
 		}
1516
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret);
1772
+		if (self::LOG_LEVEL > 1)
1773
+		{
1774
+			error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret);
1775
+		}
1517 1776
 		return $ret;
1518 1777
 	}
1519 1778
 
@@ -1548,7 +1807,8 @@  discard block
 block discarded – undo
1548 1807
 			$eacls = array_merge((array)self::get_eacl($path),$eacls);
1549 1808
 		}
1550 1809
 		// sort by length descending, to show precedence
1551
-		usort($eacls, function($a, $b) {
1810
+		usort($eacls, function($a, $b)
1811
+		{
1552 1812
 			return strlen($b['path']) - strlen($a['path']);
1553 1813
 		});
1554 1814
 		//error_log(__METHOD__."('$_path') returning ".array2string($eacls));
@@ -1572,7 +1832,10 @@  discard block
 block discarded – undo
1572 1832
 	 */
1573 1833
 	static function id2path($fs_ids, $recursion_count=0)
1574 1834
 	{
1575
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')');
1835
+		if (self::LOG_LEVEL > 1)
1836
+		{
1837
+			error_log(__METHOD__.'('.array2string($fs_ids).')');
1838
+		}
1576 1839
 		if ($recursion_count > self::MAX_ID2PATH_RECURSION)
1577 1840
 		{
1578 1841
 			error_log(__METHOD__."(".array2string($fs_ids).", $recursion_count) max recursion depth reached, probably broken filesystem!");
@@ -1589,16 +1852,26 @@  discard block
 block discarded – undo
1589 1852
 				unset($ids[$key]);
1590 1853
 				if (!$ids)
1591 1854
 				{
1592
-					if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*');
1855
+					if (self::LOG_LEVEL > 1)
1856
+					{
1857
+						error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*');
1858
+					}
1593 1859
 					return is_array($fs_ids) ? $pathes : array_shift($pathes);
1594 1860
 				}
1595 1861
 			}
1596 1862
 		}
1597 1863
 		// now search via the database
1598
-		if (count($ids) > 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1864
+		if (count($ids) > 1)
1865
+		{
1866
+			array_map(function(&$v) { $v = (int)$v;
1867
+		}
1868
+		},$ids);
1599 1869
 		$query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'.
1600 1870
 			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')');
1601
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1871
+		if (self::LOG_LEVEL > 2)
1872
+		{
1873
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1874
+		}
1602 1875
 
1603 1876
 		if (!is_object(self::$pdo))
1604 1877
 		{
@@ -1625,14 +1898,20 @@  discard block
 block discarded – undo
1625 1898
 		{
1626 1899
 			return false;	// parent not found, should never happen ...
1627 1900
 		}
1628
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1901
+		if (self::LOG_LEVEL > 1)
1902
+		{
1903
+			error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1904
+		}
1629 1905
 		foreach((array)$rows as $fs_id => $row)
1630 1906
 		{
1631 1907
 			$parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : '';
1632 1908
 
1633 1909
 			$pathes[$fs_id] = $parent . '/' . $row['fs_name'];
1634 1910
 		}
1635
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1911
+		if (self::LOG_LEVEL > 1)
1912
+		{
1913
+			error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1914
+		}
1636 1915
 		return is_array($fs_ids) ? $pathes : array_shift($pathes);
1637 1916
 	}
1638 1917
 
@@ -1688,7 +1967,10 @@  discard block
 block discarded – undo
1688 1967
 			'mime'  => $info['fs_mime'],
1689 1968
 			'readlink' => $info['fs_link'],
1690 1969
 		);
1691
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($info[name]) = ".array2string($stat));
1970
+		if (self::LOG_LEVEL > 1)
1971
+		{
1972
+			error_log(__METHOD__."($info[name]) = ".array2string($stat));
1973
+		}
1692 1974
 		return $stat;
1693 1975
 	}
1694 1976
 
@@ -1720,13 +2002,16 @@  discard block
 block discarded – undo
1720 2002
 		}
1721 2003
 		if (!isset($GLOBALS['egw_info']['server']['files_dir']))
1722 2004
 		{
1723
-			if (is_object($GLOBALS['egw_setup']->db))	// if we run under setup, query the db for the files dir
2005
+			if (is_object($GLOBALS['egw_setup']->db))
2006
+			{
2007
+				// if we run under setup, query the db for the files dir
1724 2008
 			{
1725 2009
 				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array(
1726 2010
 					'config_name' => 'files_dir',
1727 2011
 					'config_app' => 'phpgwapi',
1728 2012
 				),__LINE__,__FILE__)->fetchColumn();
1729 2013
 			}
2014
+			}
1730 2015
 		}
1731 2016
 		if (!$GLOBALS['egw_info']['server']['files_dir'])
1732 2017
 		{
@@ -1738,7 +2023,11 @@  discard block
 block discarded – undo
1738 2023
 		{
1739 2024
 			$hash[] = sprintf('%02d',$n % self::HASH_MAX);
1740 2025
 		}
1741
-		if (!$hash) $hash[] = '00';		// we need at least one directory, to not conflict with the dir-names
2026
+		if (!$hash)
2027
+		{
2028
+			$hash[] = '00';
2029
+		}
2030
+		// we need at least one directory, to not conflict with the dir-names
1742 2031
 		array_unshift($hash,$id);
1743 2032
 
1744 2033
 		$path = '/sqlfs/'.implode('/',array_reverse($hash));
@@ -1801,10 +2090,16 @@  discard block
 block discarded – undo
1801 2090
 	static function proppatch($path,array $props)
1802 2091
 	{
1803 2092
 		static $inst = null;
1804
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props));
2093
+		if (self::LOG_LEVEL > 1)
2094
+		{
2095
+			error_log(__METHOD__."(".array2string($path).','.array2string($props));
2096
+		}
1805 2097
 		if (!is_numeric($path))
1806 2098
 		{
1807
-			if (!isset($inst)) $inst = new self();
2099
+			if (!isset($inst))
2100
+			{
2101
+				$inst = new self();
2102
+			}
1808 2103
 			if (!($stat = $inst->url_stat($path,0)))
1809 2104
 			{
1810 2105
 				return false;
@@ -1822,13 +2117,19 @@  discard block
 block discarded – undo
1822 2117
 		$ins_stmt = $del_stmt = null;
1823 2118
 		foreach($props as &$prop)
1824 2119
 		{
1825
-			if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
2120
+			if (!isset($prop['ns']))
2121
+			{
2122
+				$prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
2123
+			}
1826 2124
 
1827
-			if (!isset($prop['val']) || self::$pdo_type != 'mysql')	// for non mysql, we have to delete the prop anyway, as there's no REPLACE!
2125
+			if (!isset($prop['val']) || self::$pdo_type != 'mysql')
2126
+			{
2127
+				// for non mysql, we have to delete the prop anyway, as there's no REPLACE!
1828 2128
 			{
1829 2129
 				if (!isset($del_stmt))
1830 2130
 				{
1831 2131
 					$del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=:fs_id AND prop_namespace=:prop_namespace AND prop_name=:prop_name');
2132
+			}
1832 2133
 				}
1833 2134
 				$del_stmt->execute(array(
1834 2135
 					'fs_id'          => $id,
@@ -1874,20 +2175,33 @@  discard block
 block discarded – undo
1874 2175
 		{
1875 2176
 			if (!is_numeric($id))
1876 2177
 			{
1877
-				if (!isset($inst)) $inst = new self();
2178
+				if (!isset($inst))
2179
+				{
2180
+					$inst = new self();
2181
+				}
1878 2182
 				if (!($stat = $inst->url_stat($id,0)))
1879 2183
 				{
1880
-					if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
2184
+					if (self::LOG_LEVEL)
2185
+					{
2186
+						error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
2187
+					}
1881 2188
 					return false;
1882 2189
 				}
1883 2190
 				$id = $stat['ino'];
1884 2191
 			}
1885 2192
 		}
1886
-		if (count($ids) >= 1) array_map(function(&$v) { $v = (int)$v; },$ids);
2193
+		if (count($ids) >= 1)
2194
+		{
2195
+			array_map(function(&$v) { $v = (int)$v;
2196
+		}
2197
+		},$ids);
1887 2198
 		$query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'.
1888 2199
 			(count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'.
1889 2200
 			(!is_null($ns) ? ' AND prop_namespace=?' : '');
1890
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
2201
+		if (self::LOG_LEVEL > 2)
2202
+		{
2203
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
2204
+		}
1891 2205
 
1892 2206
 		$stmt = self::$pdo->prepare($query);
1893 2207
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
@@ -1906,11 +2220,14 @@  discard block
 block discarded – undo
1906 2220
 		{
1907 2221
 			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array();	// return empty array for no props
1908 2222
 		}
1909
-		elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props))))	// need to map fs_id's to pathes
2223
+		elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props))))
2224
+		{
2225
+			// need to map fs_id's to pathes
1910 2226
 		{
1911 2227
 			foreach($id2path as $id => $path)
1912 2228
 			{
1913 2229
 				$props[$path] =& $props[$id];
2230
+		}
1914 2231
 				unset($props[$id]);
1915 2232
 			}
1916 2233
 		}
Please login to merge, or discard this patch.
Doc Comments   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	 *
501 501
 	 * If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
502 502
 	 *
503
-	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
503
+	 * @return boolean TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
504 504
 	 */
505 505
 	function stream_flush ( )
506 506
 	{
@@ -541,6 +541,7 @@  discard block
 block discarded – undo
541 541
 	 * In order for the appropriate error message to be returned, do not define this method if your wrapper does not support unlinking!
542 542
 	 *
543 543
 	 * @param string $url
544
+	 * @param integer $parent_stat
544 545
 	 * @return boolean TRUE on success or FALSE on failure
545 546
 	 */
546 547
 	function unlink ( $url, $parent_stat=null )
@@ -672,6 +673,8 @@  discard block
 block discarded – undo
672 673
 
673 674
 	/**
674 675
 	 * due to problems with recursive directory creation, we have our own here
676
+	 * @param false|string $pathname
677
+	 * @param integer $mode
675 678
 	 */
676 679
 	protected static function mkdir_recursive($pathname, $mode, $depth=0)
677 680
 	{
@@ -1057,7 +1060,7 @@  discard block
 block discarded – undo
1057 1060
 	 *
1058 1061
 	 * @param string $url URL that was passed to opendir() and that this object is expected to explore.
1059 1062
 	 * @param int $options
1060
-	 * @return booelan
1063
+	 * @return boolean
1061 1064
 	 */
1062 1065
 	function dir_opendir ( $url, $options )
1063 1066
 	{
@@ -1460,7 +1463,7 @@  discard block
 block discarded – undo
1460 1463
 	 *
1461 1464
 	 * @param string $path string with path
1462 1465
 	 * @param int $rights =null rights to set, or null to delete the entry
1463
-	 * @param int|boolean $owner =null owner for whom to set the rights, null for the current user, or false to delete all rights for $path
1466
+	 * @param boolean $owner =null owner for whom to set the rights, null for the current user, or false to delete all rights for $path
1464 1467
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
1465 1468
 	 * @return boolean true if acl is set/deleted, false on error
1466 1469
 	 */
@@ -1750,6 +1753,7 @@  discard block
 block discarded – undo
1750 1753
 	 * Replace the password of an url with '...' for error messages
1751 1754
 	 *
1752 1755
 	 * @param string &$url
1756
+	 * @param string $url
1753 1757
 	 */
1754 1758
 	static protected function _remove_password(&$url)
1755 1759
 	{
@@ -1765,7 +1769,7 @@  discard block
 block discarded – undo
1765 1769
 	/**
1766 1770
 	 * Get storage mode from url (get parameter 'storage', eg. ?storage=db)
1767 1771
 	 *
1768
-	 * @param string|array $url complete url or array of url-parts from parse_url
1772
+	 * @param string $url complete url or array of url-parts from parse_url
1769 1773
 	 * @return int self::STORE2FS or self::STORE2DB
1770 1774
 	 */
1771 1775
 	static function url2operation($url)
Please login to merge, or discard this patch.
Spacing   +229 added lines, -231 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	/**
68 68
 	 * mode-bits, which have to be set for directories
69 69
 	 */
70
-	const MODE_DIR =   040000;
70
+	const MODE_DIR = 040000;
71 71
 	/**
72 72
 	 * mode-bits, which have to be set for links
73 73
 	 */
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @param string $path ='/'
166 166
 	 */
167
-	public static function clearstatcache($path='/')
167
+	public static function clearstatcache($path = '/')
168 168
 	{
169 169
 		//error_log(__METHOD__."('$path')");
170
-		unset($path);	// not used
170
+		unset($path); // not used
171 171
 
172 172
 		self::$stat_cache = array();
173 173
 
@@ -187,32 +187,32 @@  discard block
 block discarded – undo
187 187
 	 * @param array $overwrite_new =null if set create new file with values overwriten by the given ones
188 188
 	 * @return boolean true if the ressource was opened successful, otherwise false
189 189
 	 */
190
-	function stream_open ( $url, $mode, $options, &$opened_path, array $overwrite_new=null )
190
+	function stream_open($url, $mode, $options, &$opened_path, array $overwrite_new = null)
191 191
 	{
192 192
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
193 193
 
194
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
194
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
195 195
 		$this->operation = self::url2operation($url);
196 196
 		$dir = Vfs::dirname($url);
197 197
 
198 198
 		$this->opened_path = $opened_path = $path;
199
-		$this->opened_mode = $mode = str_replace('b','',$mode);	// we are always binary, like every Linux system
199
+		$this->opened_mode = $mode = str_replace('b', '', $mode); // we are always binary, like every Linux system
200 200
 		$this->opened_stream = null;
201 201
 
202 202
 		parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params);
203 203
 
204
-		if (!is_null($overwrite_new) || !($stat = $this->url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
204
+		if (!is_null($overwrite_new) || !($stat = $this->url_stat($path, STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
205 205
 		{
206
-			if (!$dir || $mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
207
-				$mode[0] == 'x' && $stat ||	// or file should not exist, but does
208
-				!($dir_stat=$this->url_stat($dir,STREAM_URL_STAT_QUIET)) ||	// or parent dir does not exist																																			create it
209
-				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat))	// or we are not allowed to 																																			create it
206
+			if (!$dir || $mode[0] == 'r' || // does $mode require the file to exist (r,r+)
207
+				$mode[0] == 'x' && $stat || // or file should not exist, but does
208
+				!($dir_stat = $this->url_stat($dir, STREAM_URL_STAT_QUIET)) || // or parent dir does not exist																																			create it
209
+				!Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat))	// or we are not allowed to 																																			create it
210 210
 			{
211 211
 				self::_remove_password($url);
212 212
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
213
-				if (($options & STREAM_REPORT_ERRORS))
213
+				if (($options&STREAM_REPORT_ERRORS))
214 214
 				{
215
-					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
215
+					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!", E_USER_WARNING);
216 216
 				}
217 217
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
218 218
 				return false;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
228 228
 				'fs_dir'  => $dir_stat['ino'],
229 229
 				// we use the mode of the dir, so files in group dirs stay accessible by all members
230
-				'fs_mode' => $dir_stat['mode'] & 0666,
230
+				'fs_mode' => $dir_stat['mode']&0666,
231 231
 				// for the uid we use the uid of the dir if not 0=root or the current user otherwise
232 232
 				'fs_uid'  => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user,
233 233
 				// we allways use the group of the dir
@@ -235,11 +235,11 @@  discard block
 block discarded – undo
235 235
 				'fs_created'  => self::_pdo_timestamp(time()),
236 236
 				'fs_modified' => self::_pdo_timestamp(time()),
237 237
 				'fs_creator'  => Vfs::$user,
238
-				'fs_mime'     => 'application/octet-stream',	// required NOT NULL!
238
+				'fs_mime'     => 'application/octet-stream', // required NOT NULL!
239 239
 				'fs_size'     => 0,
240 240
 				'fs_active'   => self::_pdo_boolean(true),
241 241
 			);
242
-			if ($overwrite_new) $values = array_merge($values,$overwrite_new);
242
+			if ($overwrite_new) $values = array_merge($values, $overwrite_new);
243 243
 			if (!$stmt->execute($values) || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq')))
244 244
 			{
245 245
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
@@ -252,35 +252,35 @@  discard block
 block discarded – undo
252 252
 				$this->opened_stream = tmpfile();
253 253
 			}
254 254
 			// create the hash-dirs, if they not yet exist
255
-			elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id))))
255
+			elseif (!file_exists($fs_dir = Vfs::dirname(self::_fs_path($this->opened_fs_id))))
256 256
 			{
257 257
 				$umaskbefore = umask();
258 258
 				if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
259
-				self::mkdir_recursive($fs_dir,0700,true);
259
+				self::mkdir_recursive($fs_dir, 0700, true);
260 260
 			}
261 261
 		}
262 262
 		// check if opend file is a directory
263
-		elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR)
263
+		elseif ($stat && ($stat['mode']&self::MODE_DIR) == self::MODE_DIR)
264 264
 		{
265 265
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!");
266
-				if (($options & STREAM_REPORT_ERRORS))
266
+				if (($options&STREAM_REPORT_ERRORS))
267 267
 				{
268
-					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING);
268
+					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!", E_USER_WARNING);
269 269
 				}
270 270
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
271 271
 				return false;
272 272
 		}
273 273
 		else
274 274
 		{
275
-			if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read
276
-				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// or edit it
275
+			if ($mode == 'r' && !Vfs::check_access($url, Vfs::READABLE, $stat) || // we are not allowed to read
276
+				$mode != 'r' && !Vfs::check_access($url, Vfs::WRITABLE, $stat))	// or edit it
277 277
 			{
278 278
 				self::_remove_password($url);
279 279
 				$op = $mode == 'r' ? 'read' : 'edited';
280 280
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
281
-				if (($options & STREAM_REPORT_ERRORS))
281
+				if (($options&STREAM_REPORT_ERRORS))
282 282
 				{
283
-					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING);
283
+					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!", E_USER_WARNING);
284 284
 				}
285 285
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
286 286
 				return false;
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
 
290 290
 			if ($this->operation == self::STORE2DB)
291 291
 			{
292
-				$stmt = self::$pdo->prepare($sql='SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?');
292
+				$stmt = self::$pdo->prepare($sql = 'SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?');
293 293
 				$stmt->execute(array($stat['ino']));
294
-				$stmt->bindColumn(1,$this->opened_stream,\PDO::PARAM_LOB);
294
+				$stmt->bindColumn(1, $this->opened_stream, \PDO::PARAM_LOB);
295 295
 				$stmt->fetch(\PDO::FETCH_BOUND);
296 296
 				// hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913)
297 297
 				// PDOStatement::bindColumn(,,\PDO::PARAM_LOB) is not working for MySQL, content is returned as string :-(
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 		if ($this->operation == self::STORE2FS)
311 311
 		{
312 312
 			if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
313
-			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file)
313
+			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id), $mode)) && $new_file)
314 314
 			{
315 315
 				// delete db entry again, if we are not able to open a new(!) file
316 316
 				unset($stmt);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		}
321 321
 		if ($mode[0] == 'a')	// append modes: a, a+
322 322
 		{
323
-			$this->stream_seek(0,SEEK_END);
323
+			$this->stream_seek(0, SEEK_END);
324 324
 		}
325 325
 		if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
326 326
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 *
333 333
 	 * You must release any resources that were locked or allocated by the stream.
334 334
 	 */
335
-	function stream_close ( )
335
+	function stream_close( )
336 336
 	{
337 337
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
338 338
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
 		if ($this->opened_mode != 'r')
345 345
 		{
346
-			$this->stream_seek(0,SEEK_END);
346
+			$this->stream_seek(0, SEEK_END);
347 347
 
348 348
 			// we need to update the mime-type, size and content (if STORE2DB)
349 349
 			$values = array(
@@ -366,10 +366,10 @@  discard block
 block discarded – undo
366 366
 			else
367 367
 			{
368 368
 				$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_size=:fs_size,fs_mime=:fs_mime,fs_modifier=:fs_modifier,fs_modified=:fs_modified,fs_content=:fs_content WHERE fs_id=:fs_id');
369
-				$this->stream_seek(0,SEEK_SET);	// rewind to the start
370
-				foreach($values as $name => &$value)
369
+				$this->stream_seek(0, SEEK_SET); // rewind to the start
370
+				foreach ($values as $name => &$value)
371 371
 				{
372
-					$stmt->bindParam($name,$value);
372
+					$stmt->bindParam($name, $value);
373 373
 				}
374 374
 				$stmt->bindParam('fs_content', $this->opened_stream, \PDO::PARAM_LOB);
375 375
 				if (!($ret = $stmt->execute()))
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
 	 * @param int $count
403 403
 	 * @return string/false up to count bytes read or false on EOF
404 404
 	 */
405
-	function stream_read ( $count )
405
+	function stream_read($count)
406 406
 	{
407 407
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos");
408 408
 
409 409
 		if (is_resource($this->opened_stream))
410 410
 		{
411
-			return fread($this->opened_stream,$count);
411
+			return fread($this->opened_stream, $count);
412 412
 		}
413 413
 		return false;
414 414
 	}
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
 	 * @param string $data
425 425
 	 * @return integer
426 426
 	 */
427
-	function stream_write ( $data )
427
+	function stream_write($data)
428 428
 	{
429 429
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)");
430 430
 
431 431
 		if (is_resource($this->opened_stream))
432 432
 		{
433
-			return fwrite($this->opened_stream,$data);
433
+			return fwrite($this->opened_stream, $data);
434 434
 		}
435 435
 		return false;
436 436
 	}
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
   	 *
448 448
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
449 449
  	 */
450
-	function stream_eof ( )
450
+	function stream_eof( )
451 451
 	{
452 452
 		if (is_resource($this->opened_stream))
453 453
 		{
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 *
462 462
 	 * @return integer current read/write position of the stream
463 463
 	 */
464
- 	function stream_tell ( )
464
+ 	function stream_tell( )
465 465
  	{
466 466
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
467 467
 
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
485 485
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
486 486
  	 */
487
-	function stream_seek ( $offset, $whence )
487
+	function stream_seek($offset, $whence)
488 488
 	{
489 489
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)");
490 490
 
491 491
 		if (is_resource($this->opened_stream))
492 492
 		{
493
-			return !fseek($this->opened_stream,$offset,$whence);	// fseek returns 0 on success and -1 on failure
493
+			return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure
494 494
 		}
495 495
 		return false;
496 496
 	}
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 	 *
503 503
 	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
504 504
 	 */
505
-	function stream_flush ( )
505
+	function stream_flush( )
506 506
 	{
507 507
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
508 508
 
@@ -527,11 +527,11 @@  discard block
 block discarded – undo
527 527
 	 *
528 528
 	 * @return array containing the same values as appropriate for the stream.
529 529
 	 */
530
-	function stream_stat ( )
530
+	function stream_stat( )
531 531
 	{
532 532
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)");
533 533
 
534
-		return $this->url_stat($this->opened_path,0);
534
+		return $this->url_stat($this->opened_path, 0);
535 535
 	}
536 536
 
537 537
 	/**
@@ -543,11 +543,11 @@  discard block
 block discarded – undo
543 543
 	 * @param string $url
544 544
 	 * @return boolean TRUE on success or FALSE on failure
545 545
 	 */
546
-	function unlink ( $url, $parent_stat=null )
546
+	function unlink($url, $parent_stat = null)
547 547
 	{
548 548
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
549 549
 
550
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
550
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
551 551
 
552 552
 		// need to get parent stat from Sqlfs, not Vfs
553 553
 		if (!isset($parent_stat))
@@ -556,18 +556,18 @@  discard block
 block discarded – undo
556 556
 				$this->url_stat($dir, STREAM_URL_STAT_LINK);
557 557
 		}
558 558
 
559
-		if (!$parent_stat || !($stat = $this->url_stat($path,STREAM_URL_STAT_LINK)) ||
559
+		if (!$parent_stat || !($stat = $this->url_stat($path, STREAM_URL_STAT_LINK)) ||
560 560
 			!$dir || !Vfs::check_access($dir, Vfs::WRITABLE, $parent_stat))
561 561
 		{
562 562
 			self::_remove_password($url);
563 563
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
564
-			return false;	// no permission or file does not exist
564
+			return false; // no permission or file does not exist
565 565
 		}
566 566
 		if ($stat['mime'] == self::DIR_MIME_TYPE)
567 567
 		{
568 568
 			self::_remove_password($url);
569 569
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!");
570
-			return false;	// no permission or file does not exist
570
+			return false; // no permission or file does not exist
571 571
 		}
572 572
 		$stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
573 573
 		unset(self::$stat_cache[$path]);
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 		if (($ret = $stmt->execute(array('fs_id' => $stat['ino']))))
576 576
 		{
577 577
 			if (self::url2operation($url) == self::STORE2FS &&
578
-				($stat['mode'] & self::MODE_LINK) != self::MODE_LINK)
578
+				($stat['mode']&self::MODE_LINK) != self::MODE_LINK)
579 579
 			{
580 580
 				unlink(self::_fs_path($stat['ino']));
581 581
 			}
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
 	 * @param string $url_to
600 600
 	 * @return boolean TRUE on success or FALSE on failure
601 601
 	 */
602
-	function rename ( $url_from, $url_to)
602
+	function rename($url_from, $url_to)
603 603
 	{
604 604
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)");
605 605
 
606
-		$path_from = Vfs::parse_url($url_from,PHP_URL_PATH);
606
+		$path_from = Vfs::parse_url($url_from, PHP_URL_PATH);
607 607
 		$from_dir = Vfs::dirname($path_from);
608
-		$path_to = Vfs::parse_url($url_to,PHP_URL_PATH);
608
+		$path_to = Vfs::parse_url($url_to, PHP_URL_PATH);
609 609
 		$to_dir = Vfs::dirname($path_to);
610 610
 		$operation = self::url2operation($url_from);
611 611
 
@@ -615,14 +615,14 @@  discard block
 block discarded – undo
615 615
 			self::_remove_password($url_from);
616 616
 			self::_remove_password($url_to);
617 617
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
618
-			return false;	// no permission or file does not exist
618
+			return false; // no permission or file does not exist
619 619
 		}
620 620
 		if (!$to_dir || !Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = $this->url_stat($to_dir, 0)))
621 621
 		{
622 622
 			self::_remove_password($url_from);
623 623
 			self::_remove_password($url_to);
624 624
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
625
-			return false;	// no permission or parent-dir does not exist
625
+			return false; // no permission or parent-dir does not exist
626 626
 		}
627 627
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
628 628
 		// for our vfs too, we abort here with an error, like the filesystem one does
@@ -633,10 +633,10 @@  discard block
 block discarded – undo
633 633
 			self::_remove_password($url_to);
634 634
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
635 635
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
636
-			return false;	// no permission or file does not exist
636
+			return false; // no permission or file does not exist
637 637
 		}
638 638
 		// if destination file already exists, delete it
639
-		if ($to_stat && !static::unlink($url_to,$operation))
639
+		if ($to_stat && !static::unlink($url_to, $operation))
640 640
 		{
641 641
 			self::_remove_password($url_to);
642 642
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 
658 658
 		// check if extension changed and update mime-type in that case (as we currently determine mime-type by it's extension!)
659 659
 		// fixes eg. problems with MsWord storing file with .tmp extension and then renaming to .doc
660
-		if ($ok && ($new_mime = Vfs::mime_content_type($url_to,true)) != Vfs::mime_content_type($url_to))
660
+		if ($ok && ($new_mime = Vfs::mime_content_type($url_to, true)) != Vfs::mime_content_type($url_to))
661 661
 		{
662 662
 			//echo "<p>Vfs::nime_content_type($url_to,true) = $new_mime</p>\n";
663 663
 			$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mime=:fs_mime WHERE fs_id=:fs_id');
@@ -673,9 +673,9 @@  discard block
 block discarded – undo
673 673
 	/**
674 674
 	 * due to problems with recursive directory creation, we have our own here
675 675
 	 */
676
-	protected static function mkdir_recursive($pathname, $mode, $depth=0)
676
+	protected static function mkdir_recursive($pathname, $mode, $depth = 0)
677 677
 	{
678
-		$maxdepth=10;
678
+		$maxdepth = 10;
679 679
 		$depth2propagate = (int)$depth + 1;
680 680
 		if ($depth2propagate > $maxdepth) return is_dir($pathname);
681 681
     	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
@@ -693,19 +693,19 @@  discard block
 block discarded – undo
693 693
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
694 694
 	 * @return boolean TRUE on success or FALSE on failure
695 695
 	 */
696
-	function mkdir ( $url, $mode, $options )
696
+	function mkdir($url, $mode, $options)
697 697
 	{
698 698
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
699 699
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace());
700
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
700
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
701 701
 
702
-		if ($this->url_stat($path,STREAM_URL_STAT_QUIET))
702
+		if ($this->url_stat($path, STREAM_URL_STAT_QUIET))
703 703
 		{
704 704
 			self::_remove_password($url);
705 705
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!");
706
-			if (!($options & STREAM_REPORT_ERRORS))
706
+			if (!($options&STREAM_REPORT_ERRORS))
707 707
 			{
708
-				trigger_error(__METHOD__."('$url',$mode,$options) already exist!",E_USER_WARNING);
708
+				trigger_error(__METHOD__."('$url',$mode,$options) already exist!", E_USER_WARNING);
709 709
 			}
710 710
 			return false;
711 711
 		}
@@ -713,35 +713,35 @@  discard block
 block discarded – undo
713 713
 		{
714 714
 			self::_remove_password($url);
715 715
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) dirname('$path')===false!");
716
-			if (!($options & STREAM_REPORT_ERRORS))
716
+			if (!($options&STREAM_REPORT_ERRORS))
717 717
 			{
718 718
 				trigger_error(__METHOD__."('$url',$mode,$options) dirname('$path')===false!", E_USER_WARNING);
719 719
 			}
720 720
 			return false;
721 721
 		}
722
-		if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query;
723
-		$parent = $this->url_stat($parent_path,STREAM_URL_STAT_QUIET);
722
+		if (($query = Vfs::parse_url($url, PHP_URL_QUERY))) $parent_path .= '?'.$query;
723
+		$parent = $this->url_stat($parent_path, STREAM_URL_STAT_QUIET);
724 724
 
725 725
 		// check if we should also create all non-existing path components and our parent does not exist,
726 726
 		// if yes call ourself recursive with the parent directory
727
-		if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
727
+		if (($options&STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
728 728
 		{
729 729
 			if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode");
730
-			if (!$this->mkdir($parent_path,$mode,$options))
730
+			if (!$this->mkdir($parent_path, $mode, $options))
731 731
 			{
732 732
 				return false;
733 733
 			}
734
-			$parent = $this->url_stat($parent_path,0);
734
+			$parent = $this->url_stat($parent_path, 0);
735 735
 		}
736
-		if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent))
736
+		if (!$parent || !Vfs::check_access($parent_path, Vfs::WRITABLE, $parent))
737 737
 		{
738 738
 			self::_remove_password($url);
739 739
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!");
740
-			if (!($options & STREAM_REPORT_ERRORS))
740
+			if (!($options&STREAM_REPORT_ERRORS))
741 741
 			{
742
-				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING);
742
+				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!", E_USER_WARNING);
743 743
 			}
744
-			return false;	// no permission or file does not exist
744
+			return false; // no permission or file does not exist
745 745
 		}
746 746
 		unset(self::$stat_cache[$path]);
747 747
 		$stmt = self::$pdo->prepare('INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified,fs_creator'.
@@ -762,9 +762,9 @@  discard block
 block discarded – undo
762 762
 			// check if some other process created the directory parallel to us (sqlfs would gives SQL errors later!)
763 763
 			$new_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq');
764 764
 
765
-			unset($stmt);	// free statement object, on some installs a new prepare fails otherwise!
765
+			unset($stmt); // free statement object, on some installs a new prepare fails otherwise!
766 766
 
767
-			$stmt = self::$pdo->prepare($q='SELECT COUNT(*) FROM '.self::TABLE.
767
+			$stmt = self::$pdo->prepare($q = 'SELECT COUNT(*) FROM '.self::TABLE.
768 768
 				' WHERE fs_dir=:fs_dir AND fs_active=:fs_active AND fs_name'.self::$case_sensitive_equal.':fs_name');
769 769
 			if ($stmt->execute(array(
770 770
 				'fs_dir'  => $parent['ino'],
@@ -788,25 +788,24 @@  discard block
 block discarded – undo
788 788
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
789 789
 	 * @return boolean TRUE on success or FALSE on failure.
790 790
 	 */
791
-	function rmdir ( $url, $options )
791
+	function rmdir($url, $options)
792 792
 	{
793 793
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
794 794
 
795
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
795
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
796 796
 
797 797
 		if (!($parent = Vfs::dirname($path)) ||
798 798
 			!($stat = $this->url_stat($path, 0)) || $stat['mime'] != self::DIR_MIME_TYPE ||
799
-			!Vfs::check_access($parent, Vfs::WRITABLE, $this->url_stat($parent,0)))
799
+			!Vfs::check_access($parent, Vfs::WRITABLE, $this->url_stat($parent, 0)))
800 800
 		{
801 801
 			self::_remove_password($url);
802
-			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' :
803
-				($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
802
+			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' : ($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
804 803
 			if (self::LOG_LEVEL) error_log($err_msg);
805
-			if (!($options & STREAM_REPORT_ERRORS))
804
+			if (!($options&STREAM_REPORT_ERRORS))
806 805
 			{
807
-				trigger_error($err_msg,E_USER_WARNING);
806
+				trigger_error($err_msg, E_USER_WARNING);
808 807
 			}
809
-			return false;	// no permission or file does not exist
808
+			return false; // no permission or file does not exist
810 809
 		}
811 810
 		$stmt = self::$pdo->prepare('SELECT COUNT(*) FROM '.self::TABLE.' WHERE fs_dir=?');
812 811
 		$stmt->execute(array($stat['ino']));
@@ -814,19 +813,19 @@  discard block
 block discarded – undo
814 813
 		{
815 814
 			self::_remove_password($url);
816 815
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!");
817
-			if (!($options & STREAM_REPORT_ERRORS))
816
+			if (!($options&STREAM_REPORT_ERRORS))
818 817
 			{
819
-				trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING);
818
+				trigger_error(__METHOD__."('$url',$options) dir is not empty!", E_USER_WARNING);
820 819
 			}
821 820
 			return false;
822 821
 		}
823 822
 		unset(self::$stat_cache[$path]);
824
-		unset($stmt);	// free statement object, on some installs a new prepare fails otherwise!
823
+		unset($stmt); // free statement object, on some installs a new prepare fails otherwise!
825 824
 
826 825
 		$del_stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=?');
827 826
 		if (($ret = $del_stmt->execute(array($stat['ino']))))
828 827
 		{
829
-			self::eacl($path,null,false,$stat['ino']);	// remove all (=false) evtl. existing extended acl for that dir
828
+			self::eacl($path, null, false, $stat['ino']); // remove all (=false) evtl. existing extended acl for that dir
830 829
 			// delete props
831 830
 			unset($del_stmt);
832 831
 			$del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=?');
@@ -853,10 +852,10 @@  discard block
 block discarded – undo
853 852
 	{
854 853
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path, $option, ".array2string($value).")");
855 854
 
856
-		switch($option)
855
+		switch ($option)
857 856
 		{
858 857
 			case STREAM_META_TOUCH:
859
-				return $this->touch($path, $value[0]);	// atime is not supported
858
+				return $this->touch($path, $value[0]); // atime is not supported
860 859
 
861 860
 			case STREAM_META_ACCESS:
862 861
 				return $this->chmod($path, $value);
@@ -885,26 +884,26 @@  discard block
 block discarded – undo
885 884
 	 * @param int $time =null modification time (unix timestamp), default null = current time
886 885
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
887 886
 	 */
888
-	protected function touch($url,$time=null,$atime=null)
887
+	protected function touch($url, $time = null, $atime = null)
889 888
 	{
890
-		unset($atime);	// not used
889
+		unset($atime); // not used
891 890
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)");
892 891
 
893
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
892
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
894 893
 
895 894
 		$vfs = new self();
896
-		if (!($stat = $vfs->url_stat($path,STREAM_URL_STAT_QUIET)))
895
+		if (!($stat = $vfs->url_stat($path, STREAM_URL_STAT_QUIET)))
897 896
 		{
898 897
 			// file does not exist --> create an empty one
899
-			if (!($f = fopen(self::SCHEME.'://default'.$path,'w')) || !fclose($f))
898
+			if (!($f = fopen(self::SCHEME.'://default'.$path, 'w')) || !fclose($f))
900 899
 			{
901 900
 				return false;
902 901
 			}
903 902
 			if (!$time)
904 903
 			{
905
-				return true;	// new (empty) file created with current mod time
904
+				return true; // new (empty) file created with current mod time
906 905
 			}
907
-			$stat = $vfs->url_stat($path,0);
906
+			$stat = $vfs->url_stat($path, 0);
908 907
 		}
909 908
 		unset(self::$stat_cache[$path]);
910 909
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_modified=:fs_modified,fs_modifier=:fs_modifier WHERE fs_id=:fs_id');
@@ -923,40 +922,40 @@  discard block
 block discarded – undo
923 922
 	 * @param int $owner
924 923
 	 * @return boolean
925 924
 	 */
926
-	protected function chown($url,$owner)
925
+	protected function chown($url, $owner)
927 926
 	{
928 927
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
929 928
 
930
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
929
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
931 930
 
932 931
 		$vfs = new self();
933
-		if (!($stat = $vfs->url_stat($path,0)))
932
+		if (!($stat = $vfs->url_stat($path, 0)))
934 933
 		{
935 934
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
936
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
935
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
937 936
 			return false;
938 937
 		}
939 938
 		if (!Vfs::$is_root)
940 939
 		{
941 940
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!");
942
-			trigger_error("Only root can do that!",E_USER_WARNING);
941
+			trigger_error("Only root can do that!", E_USER_WARNING);
943 942
 			return false;
944 943
 		}
945 944
 		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))	// not a user (0 == root)
946 945
 		{
947 946
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!");
948
-			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING);
947
+			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!", E_USER_WARNING);
949 948
 			//throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!");
950 949
 			return false;
951 950
 		}
952 951
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id');
953 952
 
954 953
 		// update stat-cache
955
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
954
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
956 955
 		self::$stat_cache[$path]['fs_uid'] = $owner;
957 956
 
958 957
 		return $stmt->execute(array(
959
-			'fs_uid' => (int) $owner,
958
+			'fs_uid' => (int)$owner,
960 959
 			'fs_id' => $stat['ino'],
961 960
 		));
962 961
 	}
@@ -968,37 +967,37 @@  discard block
 block discarded – undo
968 967
 	 * @param int $owner
969 968
 	 * @return boolean
970 969
 	 */
971
-	protected function chgrp($url,$owner)
970
+	protected function chgrp($url, $owner)
972 971
 	{
973 972
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
974 973
 
975
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
974
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
976 975
 
977 976
 		$vfs = new self();
978
-		if (!($stat = $vfs->url_stat($path,0)))
977
+		if (!($stat = $vfs->url_stat($path, 0)))
979 978
 		{
980 979
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
981
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
980
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
982 981
 			return false;
983 982
 		}
984
-		if (!Vfs::has_owner_rights($path,$stat))
983
+		if (!Vfs::has_owner_rights($path, $stat))
985 984
 		{
986 985
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!");
987
-			trigger_error("Only owner or root can do that!",E_USER_WARNING);
986
+			trigger_error("Only owner or root can do that!", E_USER_WARNING);
988 987
 			return false;
989 988
 		}
990
-		if ($owner < 0) $owner = -$owner;	// sqlfs uses a positiv group id's!
989
+		if ($owner < 0) $owner = -$owner; // sqlfs uses a positiv group id's!
991 990
 
992 991
 		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))	// not a group
993 992
 		{
994 993
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!");
995
-			trigger_error("Unknown (numeric) group id!",E_USER_WARNING);
994
+			trigger_error("Unknown (numeric) group id!", E_USER_WARNING);
996 995
 			return false;
997 996
 		}
998 997
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id');
999 998
 
1000 999
 		// update stat-cache
1001
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1000
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
1002 1001
 		self::$stat_cache[$path]['fs_gid'] = $owner;
1003 1002
 
1004 1003
 		return $stmt->execute(array(
@@ -1014,39 +1013,39 @@  discard block
 block discarded – undo
1014 1013
 	 * @param int $mode
1015 1014
 	 * @return boolean
1016 1015
 	 */
1017
-	protected function chmod($url,$mode)
1016
+	protected function chmod($url, $mode)
1018 1017
 	{
1019 1018
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)");
1020 1019
 
1021
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
1020
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
1022 1021
 
1023 1022
 		$vfs = new self();
1024
-		if (!($stat = $vfs->url_stat($path,0)))
1023
+		if (!($stat = $vfs->url_stat($path, 0)))
1025 1024
 		{
1026 1025
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!");
1027
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
1026
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
1028 1027
 			return false;
1029 1028
 		}
1030
-		if (!Vfs::has_owner_rights($path,$stat))
1029
+		if (!Vfs::has_owner_rights($path, $stat))
1031 1030
 		{
1032 1031
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!");
1033
-			trigger_error("Only owner or root can do that!",E_USER_WARNING);
1032
+			trigger_error("Only owner or root can do that!", E_USER_WARNING);
1034 1033
 			return false;
1035 1034
 		}
1036 1035
 		if (!is_numeric($mode))	// not a mode
1037 1036
 		{
1038 1037
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!");
1039
-			trigger_error("No (numeric) mode!",E_USER_WARNING);
1038
+			trigger_error("No (numeric) mode!", E_USER_WARNING);
1040 1039
 			return false;
1041 1040
 		}
1042 1041
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id');
1043 1042
 
1044 1043
 		// update stat cache
1045
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1046
-		self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777;
1044
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
1045
+		self::$stat_cache[$path]['fs_mode'] = ((int)$mode)&0777;
1047 1046
 
1048 1047
 		return $stmt->execute(array(
1049
-			'fs_mode' => ((int) $mode) & 0777,		// we dont store the file and dir bits, give int overflow!
1048
+			'fs_mode' => ((int)$mode)&0777, // we dont store the file and dir bits, give int overflow!
1050 1049
 			'fs_id' => $stat['ino'],
1051 1050
 		));
1052 1051
 	}
@@ -1059,18 +1058,18 @@  discard block
 block discarded – undo
1059 1058
 	 * @param int $options
1060 1059
 	 * @return booelan
1061 1060
 	 */
1062
-	function dir_opendir ( $url, $options )
1061
+	function dir_opendir($url, $options)
1063 1062
 	{
1064 1063
 		$this->opened_dir = null;
1065 1064
 
1066
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
1065
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
1067 1066
 
1068
-		if (!($stat = $this->url_stat($url,0)) || 		// dir not found
1069
-			!($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ||		// no dir
1070
-			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))	// no access
1067
+		if (!($stat = $this->url_stat($url, 0)) || // dir not found
1068
+			!($stat['mode']&self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE || // no dir
1069
+			!Vfs::check_access($url, Vfs::EXECUTABLE|Vfs::READABLE, $stat))	// no access
1071 1070
 		{
1072 1071
 			self::_remove_password($url);
1073
-			$msg = !($stat['mode'] & self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ?
1072
+			$msg = !($stat['mode']&self::MODE_DIR) && $stat['mime'] != self::DIR_MIME_TYPE ?
1074 1073
 				"$url is no directory" : 'permission denied';
1075 1074
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $msg!");
1076 1075
 			$this->opened_dir = null;
@@ -1087,13 +1086,13 @@  discard block
 block discarded – undo
1087 1086
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
1088 1087
 		if ($stmt->execute(array($stat['ino'])))
1089 1088
 		{
1090
-			foreach($stmt as $file)
1089
+			foreach ($stmt as $file)
1091 1090
 			{
1092 1091
 				$this->opened_dir[] = $file['fs_name'];
1093
-				self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file;
1092
+				self::$stat_cache[Vfs::concat($path, $file['fs_name'])] = $file;
1094 1093
 			}
1095 1094
 		}
1096
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1095
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ', $this->opened_dir));
1097 1096
 		reset($this->opened_dir);
1098 1097
 
1099 1098
 		return true;
@@ -1126,26 +1125,26 @@  discard block
 block discarded – undo
1126 1125
 	 * @param boolean $eacl_access =null allows extending classes to pass the value of their check_extended_acl() method (no lsb!)
1127 1126
 	 * @return array
1128 1127
 	 */
1129
-	function url_stat ( $url, $flags, $eacl_access=null )
1128
+	function url_stat($url, $flags, $eacl_access = null)
1130 1129
 	{
1131
-		static $max_subquery_depth=null;
1130
+		static $max_subquery_depth = null;
1132 1131
 		if (is_null($max_subquery_depth))
1133 1132
 		{
1134 1133
 			$max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth'];
1135
-			if (!$max_subquery_depth) $max_subquery_depth = 7;	// setting current default of 7, if nothing set
1134
+			if (!$max_subquery_depth) $max_subquery_depth = 7; // setting current default of 7, if nothing set
1136 1135
 		}
1137 1136
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags,$eacl_access)");
1138 1137
 
1139
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
1138
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
1140 1139
 
1141 1140
 		// webdav adds a trailing slash to dirs, which causes url_stat to NOT find the file otherwise
1142
-		if ($path != '/' && substr($path,-1) == '/')
1141
+		if ($path != '/' && substr($path, -1) == '/')
1143 1142
 		{
1144
-			$path = substr($path,0,-1);
1143
+			$path = substr($path, 0, -1);
1145 1144
 		}
1146 1145
 		if (empty($path))
1147 1146
 		{
1148
-			return false;	// is invalid and gives sql error
1147
+			return false; // is invalid and gives sql error
1149 1148
 		}
1150 1149
 		// check if we already have the info from the last dir_open call, as the old vfs reads it anyway from the db
1151 1150
 		if (self::$stat_cache && isset(self::$stat_cache[$path]) && (is_null($eacl_access) || self::$stat_cache[$path] !== false))
@@ -1160,28 +1159,28 @@  discard block
 block discarded – undo
1160 1159
 		$base_query = 'SELECT fs_id,fs_name,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified'.self::$extra_columns.
1161 1160
 			' FROM '.self::TABLE.' WHERE fs_active='.self::_pdo_boolean(true).
1162 1161
 			' AND fs_name'.self::$case_sensitive_equal.'? AND fs_dir=';
1163
-		$parts = explode('/',$path);
1162
+		$parts = explode('/', $path);
1164 1163
 
1165 1164
 		// if we have extendes acl access to the url, we dont need and can NOT include the sql for the readable check
1166 1165
 		if (is_null($eacl_access))
1167 1166
 		{
1168
-			$eacl_access = self::check_extended_acl($path,Vfs::READABLE);	// should be static::check_extended_acl, but no lsb!
1167
+			$eacl_access = self::check_extended_acl($path, Vfs::READABLE); // should be static::check_extended_acl, but no lsb!
1169 1168
 		}
1170 1169
 
1171 1170
 		try {
1172
-			foreach($parts as $n => $name)
1171
+			foreach ($parts as $n => $name)
1173 1172
 			{
1174 1173
 				if ($n == 0)
1175 1174
 				{
1176
-					$query = (int) ($path != '/');	// / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!)
1175
+					$query = (int)($path != '/'); // / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!)
1177 1176
 				}
1178
-				elseif ($n < count($parts)-1)
1177
+				elseif ($n < count($parts) - 1)
1179 1178
 				{
1180 1179
 					// MySQL 5.0 has a nesting limit for subqueries
1181 1180
 					// --> we replace the so far cumulated subqueries with their result
1182 1181
 					// no idea about the other DBMS, but this does NOT hurt ...
1183 1182
 					// --> depth limit of subqueries is now dynamicly decremented in catch
1184
-					if ($n > 1 && !(($n-1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn()))
1183
+					if ($n > 1 && !(($n - 1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn()))
1185 1184
 					{
1186 1185
 						if (self::LOG_LEVEL > 1)
1187 1186
 						{
@@ -1208,7 +1207,7 @@  discard block
 block discarded – undo
1208 1207
 				}
1209 1208
 				else
1210 1209
 				{
1211
-					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')';
1210
+					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?', 'fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name), $base_query).'('.$query.')';
1212 1211
 				}
1213 1212
 			}
1214 1213
 			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
@@ -1234,7 +1233,7 @@  discard block
 block discarded – undo
1234 1233
 			$GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth;
1235 1234
 			error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth");
1236 1235
 			Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi');
1237
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1236
+			if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1238 1237
 			return $this->url_stat($url, $flags, $eacl_access);
1239 1238
 		}
1240 1239
 		self::$stat_cache[$path] = $info;
@@ -1250,18 +1249,18 @@  discard block
 block discarded – undo
1250 1249
 	 */
1251 1250
 	protected static function _sql_readable()
1252 1251
 	{
1253
-		static $sql_read_acl=null;
1252
+		static $sql_read_acl = null;
1254 1253
 
1255 1254
 		if (is_null($sql_read_acl))
1256 1255
 		{
1257
-			foreach($GLOBALS['egw']->accounts->memberships(Vfs::$user,true) as $gid)
1256
+			foreach ($GLOBALS['egw']->accounts->memberships(Vfs::$user, true) as $gid)
1258 1257
 			{
1259
-				$memberships[] = abs($gid);	// sqlfs stores the gid's positiv
1258
+				$memberships[] = abs($gid); // sqlfs stores the gid's positiv
1260 1259
 			}
1261 1260
 			// using octal numbers with mysql leads to funny results (select 384 & 0400 --> 384 not 256=0400)
1262 1261
 			// 256 = 0400, 32 = 040
1263 1262
 			$sql_read_acl = '((fs_mode & 4)=4 OR (fs_mode & 256)=256 AND fs_uid='.(int)Vfs::$user.
1264
-				($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',',$memberships).')' : '').')';
1263
+				($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',', $memberships).')' : '').')';
1265 1264
 			//error_log(__METHOD__."() Vfs::\$user=".array2string(Vfs::$user).' --> memberships='.array2string($memberships).' --> '.$sql_read_acl.($memberships?'':': '.function_backtrace()));
1266 1265
 		}
1267 1266
 		return $sql_read_acl;
@@ -1274,7 +1273,7 @@  discard block
 block discarded – undo
1274 1273
 	 *
1275 1274
 	 * @return string
1276 1275
 	 */
1277
-	function dir_readdir ( )
1276
+	function dir_readdir( )
1278 1277
 	{
1279 1278
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1280 1279
 
@@ -1293,7 +1292,7 @@  discard block
 block discarded – undo
1293 1292
 	 *
1294 1293
 	 * @return boolean
1295 1294
 	 */
1296
-	function dir_rewinddir ( )
1295
+	function dir_rewinddir( )
1297 1296
 	{
1298 1297
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1299 1298
 
@@ -1311,7 +1310,7 @@  discard block
 block discarded – undo
1311 1310
 	 *
1312 1311
 	 * @return boolean
1313 1312
 	 */
1314
-	function dir_closedir ( )
1313
+	function dir_closedir( )
1315 1314
 	{
1316 1315
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1317 1316
 
@@ -1333,7 +1332,7 @@  discard block
 block discarded – undo
1333 1332
 	static function readlink($path)
1334 1333
 	{
1335 1334
 		$vfs = new self();
1336
-		$link = !($lstat = $vfs->url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1335
+		$link = !($lstat = $vfs->url_stat($path, STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1337 1336
 
1338 1337
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link");
1339 1338
 
@@ -1347,32 +1346,32 @@  discard block
 block discarded – undo
1347 1346
 	 * @param string $link
1348 1347
 	 * @return boolean true on success false on error
1349 1348
 	 */
1350
-	static function symlink($target,$link)
1349
+	static function symlink($target, $link)
1351 1350
 	{
1352 1351
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')");
1353 1352
 
1354 1353
 		$inst = new static();
1355
-		if ($inst->url_stat($link,0))
1354
+		if ($inst->url_stat($link, 0))
1356 1355
 		{
1357 1356
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1358
-			return false;	// $link already exists
1357
+			return false; // $link already exists
1359 1358
 		}
1360 1359
 		if (!($dir = Vfs::dirname($link)) ||
1361
-			!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=$inst->url_stat($dir,0)))
1360
+			!Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat = $inst->url_stat($dir, 0)))
1362 1361
 		{
1363 1362
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1364
-			return false;	// parent dir does not exist or is not writable
1363
+			return false; // parent dir does not exist or is not writable
1365 1364
 		}
1366 1365
 		$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'.
1367 1366
 			') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)';
1368 1367
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1369 1368
 		$stmt = self::$pdo->prepare($query);
1370
-		unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]);
1369
+		unset(self::$stat_cache[Vfs::parse_url($link, PHP_URL_PATH)]);
1371 1370
 
1372 1371
 		return !!$stmt->execute(array(
1373 1372
 			'fs_name' => self::limit_filename(Vfs::basename($link)),
1374 1373
 			'fs_dir'  => $dir_stat['ino'],
1375
-			'fs_mode' => ($dir_stat['mode'] & 0666),
1374
+			'fs_mode' => ($dir_stat['mode']&0666),
1376 1375
 			'fs_uid'  => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user,
1377 1376
 			'fs_gid'  => $dir_stat['gid'],
1378 1377
 			'fs_created'  => self::_pdo_timestamp(time()),
@@ -1396,24 +1395,24 @@  discard block
 block discarded – undo
1396 1395
 	 * @param int $check mode to check: one or more or'ed together of: 4 = read, 2 = write, 1 = executable
1397 1396
 	 * @return boolean
1398 1397
 	 */
1399
-	static function check_extended_acl($url,$check)
1398
+	static function check_extended_acl($url, $check)
1400 1399
 	{
1401
-		$url_path = Vfs::parse_url($url,PHP_URL_PATH);
1400
+		$url_path = Vfs::parse_url($url, PHP_URL_PATH);
1402 1401
 
1403 1402
 		if (is_null(self::$extended_acl))
1404 1403
 		{
1405 1404
 			self::_read_extended_acl();
1406 1405
 		}
1407 1406
 		$access = false;
1408
-		foreach(self::$extended_acl as $path => $rights)
1407
+		foreach (self::$extended_acl as $path => $rights)
1409 1408
 		{
1410
-			if ($path == $url_path || substr($url_path,0,strlen($path)+1) == $path.'/')
1409
+			if ($path == $url_path || substr($url_path, 0, strlen($path) + 1) == $path.'/')
1411 1410
 			{
1412
-				$access = ($rights & $check) == $check;
1411
+				$access = ($rights&$check) == $check;
1413 1412
 				break;
1414 1413
 			}
1415 1414
 		}
1416
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1415
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access ? "access granted by $path=$rights" : 'no access!!!'));
1417 1416
 		return $access;
1418 1417
 	}
1419 1418
 
@@ -1425,14 +1424,14 @@  discard block
 block discarded – undo
1425 1424
 	{
1426 1425
 		if ((self::$extended_acl = Api\Cache::getSession(self::EACL_APPNAME, 'extended_acl')))
1427 1426
 		{
1428
-			return;		// ext. ACL read from session.
1427
+			return; // ext. ACL read from session.
1429 1428
 		}
1430 1429
 		self::$extended_acl = array();
1431
-		if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user,self::EACL_APPNAME)))
1430
+		if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user, self::EACL_APPNAME)))
1432 1431
 		{
1433 1432
 			$pathes = self::id2path(array_keys($rights));
1434 1433
 		}
1435
-		foreach($rights as $fs_id => $right)
1434
+		foreach ($rights as $fs_id => $right)
1436 1435
 		{
1437 1436
 			$path = $pathes[$fs_id];
1438 1437
 			if (isset($path))
@@ -1441,8 +1440,8 @@  discard block
 block discarded – undo
1441 1440
 			}
1442 1441
 		}
1443 1442
 		// sort by length descending, to allow more specific pathes to have precedence
1444
-		uksort(self::$extended_acl, function($a,$b) {
1445
-			return strlen($b)-strlen($a);
1443
+		uksort(self::$extended_acl, function($a, $b) {
1444
+			return strlen($b) - strlen($a);
1446 1445
 		});
1447 1446
 		Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1448 1447
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl));
@@ -1464,24 +1463,24 @@  discard block
 block discarded – undo
1464 1463
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
1465 1464
 	 * @return boolean true if acl is set/deleted, false on error
1466 1465
 	 */
1467
-	static function eacl($path,$rights=null,$owner=null,$fs_id=null)
1466
+	static function eacl($path, $rights = null, $owner = null, $fs_id = null)
1468 1467
 	{
1469 1468
 		if ($path[0] != '/')
1470 1469
 		{
1471
-			$path = Vfs::parse_url($path,PHP_URL_PATH);
1470
+			$path = Vfs::parse_url($path, PHP_URL_PATH);
1472 1471
 		}
1473 1472
 		if (is_null($fs_id))
1474 1473
 		{
1475 1474
 			$vfs = new self();
1476
-			if (!($stat = $vfs->url_stat($path,0)))
1475
+			if (!($stat = $vfs->url_stat($path, 0)))
1477 1476
 			{
1478 1477
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1479
-				return false;	// $path not found
1478
+				return false; // $path not found
1480 1479
 			}
1481
-			if (!Vfs::has_owner_rights($path,$stat))		// not group dir and user is eGW admin
1480
+			if (!Vfs::has_owner_rights($path, $stat))		// not group dir and user is eGW admin
1482 1481
 			{
1483 1482
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!");
1484
-				return false;	// permission denied
1483
+				return false; // permission denied
1485 1484
 			}
1486 1485
 			$fs_id = $stat['ino'];
1487 1486
 		}
@@ -1493,21 +1492,21 @@  discard block
 block discarded – undo
1493 1492
 		{
1494 1493
 			// delete eacl
1495 1494
 			if (is_null($owner) || $owner == Vfs::$user ||
1496
-				$owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true)))
1495
+				$owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true)))
1497 1496
 			{
1498
-				self::$extended_acl = null;	// force new read of eACL, as there could be multiple eACL for that path
1497
+				self::$extended_acl = null; // force new read of eACL, as there could be multiple eACL for that path
1499 1498
 			}
1500
-			$ret = $GLOBALS['egw']->acl->delete_repository(self::EACL_APPNAME,$fs_id,(int)$owner);
1499
+			$ret = $GLOBALS['egw']->acl->delete_repository(self::EACL_APPNAME, $fs_id, (int)$owner);
1501 1500
 		}
1502 1501
 		else
1503 1502
 		{
1504 1503
 			if (isset(self::$extended_acl) && ($owner == Vfs::$user ||
1505
-				$owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true))))
1504
+				$owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true))))
1506 1505
 			{
1507 1506
 				// set rights for this class, if applicable
1508 1507
 				self::$extended_acl[$path] |= $rights;
1509 1508
 			}
1510
-			$ret = $GLOBALS['egw']->acl->add_repository(self::EACL_APPNAME,$fs_id,$owner,$rights);
1509
+			$ret = $GLOBALS['egw']->acl->add_repository(self::EACL_APPNAME, $fs_id, $owner, $rights);
1511 1510
 		}
1512 1511
 		if ($ret)
1513 1512
 		{
@@ -1531,10 +1530,10 @@  discard block
 block discarded – undo
1531 1530
 		if (!($stat = $inst->url_stat($path, STREAM_URL_STAT_QUIET)))
1532 1531
 		{
1533 1532
 			error_log(__METHOD__.__LINE__.' '.array2string($path).' not found!');
1534
-			return false;	// not found
1533
+			return false; // not found
1535 1534
 		}
1536 1535
 		$eacls = array();
1537
-		foreach($GLOBALS['egw']->acl->get_all_rights($stat['ino'],self::EACL_APPNAME) as $owner => $rights)
1536
+		foreach ($GLOBALS['egw']->acl->get_all_rights($stat['ino'], self::EACL_APPNAME) as $owner => $rights)
1538 1537
 		{
1539 1538
 			$eacls[] = array(
1540 1539
 				'path'   => $path,
@@ -1545,7 +1544,7 @@  discard block
 block discarded – undo
1545 1544
 		}
1546 1545
 		if (($path = Vfs::dirname($path)))
1547 1546
 		{
1548
-			$eacls = array_merge((array)self::get_eacl($path),$eacls);
1547
+			$eacls = array_merge((array)self::get_eacl($path), $eacls);
1549 1548
 		}
1550 1549
 		// sort by length descending, to show precedence
1551 1550
 		usort($eacls, function($a, $b) {
@@ -1570,7 +1569,7 @@  discard block
 block discarded – undo
1570 1569
 	 * @param int $recursion_count =0 internally used to break infinit recursions
1571 1570
 	 * @return false|string|array path or array or pathes indexed by fs_id, or false on error
1572 1571
 	 */
1573
-	static function id2path($fs_ids, $recursion_count=0)
1572
+	static function id2path($fs_ids, $recursion_count = 0)
1574 1573
 	{
1575 1574
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')');
1576 1575
 		if ($recursion_count > self::MAX_ID2PATH_RECURSION)
@@ -1581,9 +1580,9 @@  discard block
 block discarded – undo
1581 1580
 		$ids = (array)$fs_ids;
1582 1581
 		$pathes = array();
1583 1582
 		// first check our stat-cache for the ids
1584
-		foreach(self::$stat_cache as $path => $stat)
1583
+		foreach (self::$stat_cache as $path => $stat)
1585 1584
 		{
1586
-			if (($key = array_search($stat['fs_id'],$ids)) !== false)
1585
+			if (($key = array_search($stat['fs_id'], $ids)) !== false)
1587 1586
 			{
1588 1587
 				$pathes[$stat['fs_id']] = $path;
1589 1588
 				unset($ids[$key]);
@@ -1597,7 +1596,7 @@  discard block
 block discarded – undo
1597 1596
 		// now search via the database
1598 1597
 		if (count($ids) > 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1599 1598
 		$query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'.
1600
-			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')');
1599
+			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',', $ids).')');
1601 1600
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1602 1601
 
1603 1602
 		if (!is_object(self::$pdo))
@@ -1608,12 +1607,12 @@  discard block
 block discarded – undo
1608 1607
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
1609 1608
 		if (!$stmt->execute())
1610 1609
 		{
1611
-			return false;	// not found
1610
+			return false; // not found
1612 1611
 		}
1613 1612
 		$parents = array();
1614
-		foreach($stmt as $row)
1613
+		foreach ($stmt as $row)
1615 1614
 		{
1616
-			if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'],$parents))
1615
+			if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'], $parents))
1617 1616
 			{
1618 1617
 				$parents[] = $row['fs_dir'];
1619 1618
 			}
@@ -1621,16 +1620,16 @@  discard block
 block discarded – undo
1621 1620
 		}
1622 1621
 		unset($stmt);
1623 1622
 
1624
-		if ($parents && !($parents = self::id2path($parents, $recursion_count+1)))
1623
+		if ($parents && !($parents = self::id2path($parents, $recursion_count + 1)))
1625 1624
 		{
1626
-			return false;	// parent not found, should never happen ...
1625
+			return false; // parent not found, should never happen ...
1627 1626
 		}
1628
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1629
-		foreach((array)$rows as $fs_id => $row)
1627
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows, true)."#");
1628
+		foreach ((array)$rows as $fs_id => $row)
1630 1629
 		{
1631 1630
 			$parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : '';
1632 1631
 
1633
-			$pathes[$fs_id] = $parent . '/' . $row['fs_name'];
1632
+			$pathes[$fs_id] = $parent.'/'.$row['fs_name'];
1634 1633
 		}
1635 1634
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1636 1635
 		return is_array($fs_ids) ? $pathes : array_shift($pathes);
@@ -1654,7 +1653,7 @@  discard block
 block discarded – undo
1654 1653
 			$parts = explode('.', $name);
1655 1654
 			if ($parts > 1 && mb_strlen($extension = '.'.array_pop($parts)) <= $fs_name_precision)
1656 1655
 			{
1657
-				$name = mb_substr(implode('.', $parts), 0, $fs_name_precision-mb_strlen($extension)).$extension;
1656
+				$name = mb_substr(implode('.', $parts), 0, $fs_name_precision - mb_strlen($extension)).$extension;
1658 1657
 			}
1659 1658
 			else
1660 1659
 			{
@@ -1675,9 +1674,8 @@  discard block
 block discarded – undo
1675 1674
 		$stat = array(
1676 1675
 			'ino'   => $info['fs_id'],
1677 1676
 			'name'  => $info['fs_name'],
1678
-			'mode'  => $info['fs_mode'] |
1679
-				($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR :
1680
-				($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)),	// required by the stream wrapper
1677
+			'mode'  => $info['fs_mode']|
1678
+				($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR : ($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)), // required by the stream wrapper
1681 1679
 			'size'  => $info['fs_size'],
1682 1680
 			'uid'   => $info['fs_uid'],
1683 1681
 			'gid'   => $info['fs_gid'],
@@ -1722,10 +1720,10 @@  discard block
 block discarded – undo
1722 1720
 		{
1723 1721
 			if (is_object($GLOBALS['egw_setup']->db))	// if we run under setup, query the db for the files dir
1724 1722
 			{
1725
-				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array(
1723
+				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config', 'config_value', array(
1726 1724
 					'config_name' => 'files_dir',
1727 1725
 					'config_app' => 'phpgwapi',
1728
-				),__LINE__,__FILE__)->fetchColumn();
1726
+				), __LINE__, __FILE__)->fetchColumn();
1729 1727
 			}
1730 1728
 		}
1731 1729
 		if (!$GLOBALS['egw_info']['server']['files_dir'])
@@ -1734,14 +1732,14 @@  discard block
 block discarded – undo
1734 1732
 		}
1735 1733
 		$hash = array();
1736 1734
 		$n = $id;
1737
-		while(($n = (int) ($n / self::HASH_MAX)))
1735
+		while (($n = (int)($n / self::HASH_MAX)))
1738 1736
 		{
1739
-			$hash[] = sprintf('%02d',$n % self::HASH_MAX);
1737
+			$hash[] = sprintf('%02d', $n % self::HASH_MAX);
1740 1738
 		}
1741
-		if (!$hash) $hash[] = '00';		// we need at least one directory, to not conflict with the dir-names
1742
-		array_unshift($hash,$id);
1739
+		if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names
1740
+		array_unshift($hash, $id);
1743 1741
 
1744
-		$path = '/sqlfs/'.implode('/',array_reverse($hash));
1742
+		$path = '/sqlfs/'.implode('/', array_reverse($hash));
1745 1743
 		//error_log(__METHOD__."($id) = '$path'");
1746 1744
 		return $GLOBALS['egw_info']['server']['files_dir'].$path;
1747 1745
 	}
@@ -1757,7 +1755,7 @@  discard block
 block discarded – undo
1757 1755
 
1758 1756
 		if ($parts['pass'] || $parts['scheme'])
1759 1757
 		{
1760
-			$url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass']?':...':'').'@' : '').
1758
+			$url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass'] ? ':...' : '').'@' : '').
1761 1759
 				$parts['host'].$parts['path'];
1762 1760
 		}
1763 1761
 	}
@@ -1772,10 +1770,10 @@  discard block
 block discarded – undo
1772 1770
 	{
1773 1771
 		$operation = self::DEFAULT_OPERATION;
1774 1772
 
1775
-		if (strpos(is_array($url) ? $url['query'] : $url,'storage=') !== false)
1773
+		if (strpos(is_array($url) ? $url['query'] : $url, 'storage=') !== false)
1776 1774
 		{
1777 1775
 			$query = null;
1778
-			parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url,PHP_URL_QUERY), $query);
1776
+			parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url, PHP_URL_QUERY), $query);
1779 1777
 			switch ($query['storage'])
1780 1778
 			{
1781 1779
 				case 'db':
@@ -1798,29 +1796,29 @@  discard block
 block discarded – undo
1798 1796
 	 * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop)
1799 1797
 	 * @return boolean true if props are updated, false otherwise (eg. ressource not found)
1800 1798
 	 */
1801
-	static function proppatch($path,array $props)
1799
+	static function proppatch($path, array $props)
1802 1800
 	{
1803 1801
 		static $inst = null;
1804 1802
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props));
1805 1803
 		if (!is_numeric($path))
1806 1804
 		{
1807 1805
 			if (!isset($inst)) $inst = new self();
1808
-			if (!($stat = $inst->url_stat($path,0)))
1806
+			if (!($stat = $inst->url_stat($path, 0)))
1809 1807
 			{
1810 1808
 				return false;
1811 1809
 			}
1812 1810
 			$id = $stat['ino'];
1813 1811
 		}
1814
-		elseif(!($path = self::id2path($id=$path)))
1812
+		elseif (!($path = self::id2path($id = $path)))
1815 1813
 		{
1816 1814
 			return false;
1817 1815
 		}
1818
-		if (!Vfs::check_access($path,Api\Acl::EDIT,$stat))
1816
+		if (!Vfs::check_access($path, Api\Acl::EDIT, $stat))
1819 1817
 		{
1820
-			return false;	// permission denied
1818
+			return false; // permission denied
1821 1819
 		}
1822 1820
 		$ins_stmt = $del_stmt = null;
1823
-		foreach($props as &$prop)
1821
+		foreach ($props as &$prop)
1824 1822
 		{
1825 1823
 			if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
1826 1824
 
@@ -1865,17 +1863,17 @@  discard block
 block discarded – undo
1865 1863
 	 * @return array|boolean false on error ($path_ids does not exist), array with props (values for keys 'name', 'ns', 'value'), or
1866 1864
 	 * 	fs_id/path => array of props for $depth==1 or is_array($path_ids)
1867 1865
 	 */
1868
-	static function propfind($path_ids,$ns=Vfs::DEFAULT_PROP_NAMESPACE)
1866
+	static function propfind($path_ids, $ns = Vfs::DEFAULT_PROP_NAMESPACE)
1869 1867
 	{
1870 1868
 		static $inst = null;
1871 1869
 
1872 1870
 		$ids = is_array($path_ids) ? $path_ids : array($path_ids);
1873
-		foreach($ids as &$id)
1871
+		foreach ($ids as &$id)
1874 1872
 		{
1875 1873
 			if (!is_numeric($id))
1876 1874
 			{
1877 1875
 				if (!isset($inst)) $inst = new self();
1878
-				if (!($stat = $inst->url_stat($id,0)))
1876
+				if (!($stat = $inst->url_stat($id, 0)))
1879 1877
 				{
1880 1878
 					if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
1881 1879
 					return false;
@@ -1885,7 +1883,7 @@  discard block
 block discarded – undo
1885 1883
 		}
1886 1884
 		if (count($ids) >= 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1887 1885
 		$query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'.
1888
-			(count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'.
1886
+			(count($ids) == 1 ? '='.(int)implode('', $ids) : ' IN ('.implode(',', $ids).')').')'.
1889 1887
 			(!is_null($ns) ? ' AND prop_namespace=?' : '');
1890 1888
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1891 1889
 
@@ -1894,7 +1892,7 @@  discard block
 block discarded – undo
1894 1892
 		$stmt->execute(!is_null($ns) ? array($ns) : array());
1895 1893
 
1896 1894
 		$props = array();
1897
-		foreach($stmt as $row)
1895
+		foreach ($stmt as $row)
1898 1896
 		{
1899 1897
 			$props[$row['fs_id']][] = array(
1900 1898
 				'val'  => $row['prop_value'],
@@ -1904,19 +1902,19 @@  discard block
 block discarded – undo
1904 1902
 		}
1905 1903
 		if (!is_array($path_ids))
1906 1904
 		{
1907
-			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array();	// return empty array for no props
1905
+			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props
1908 1906
 		}
1909 1907
 		elseif ($props && isset($stat) && is_array($id2path = self::id2path(array_keys($props))))	// need to map fs_id's to pathes
1910 1908
 		{
1911
-			foreach($id2path as $id => $path)
1909
+			foreach ($id2path as $id => $path)
1912 1910
 			{
1913
-				$props[$path] =& $props[$id];
1911
+				$props[$path] = & $props[$id];
1914 1912
 				unset($props[$id]);
1915 1913
 			}
1916 1914
 		}
1917 1915
 		if (self::LOG_LEVEL > 1)
1918 1916
 		{
1919
-			foreach((array)$props as $k => $v)
1917
+			foreach ((array)$props as $k => $v)
1920 1918
 			{
1921 1919
 				error_log(__METHOD__."($path_ids,$ns) $k => ".array2string($v));
1922 1920
 			}
Please login to merge, or discard this patch.
api/src/Mail.php 4 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6730,14 +6730,14 @@
 block discarded – undo
6730 6730
 					{
6731 6731
 						if ($this->folderExists($_folder,true))
6732 6732
 						{
6733
-						    if($this->isSentFolder($_folder))
6733
+							if($this->isSentFolder($_folder))
6734 6734
 							{
6735
-						        $flags = '\\Seen';
6736
-						    } elseif($this->isDraftFolder($_folder)) {
6737
-						        $flags = '\\Draft';
6738
-						    } else {
6739
-						        $flags = '';
6740
-						    }
6735
+								$flags = '\\Seen';
6736
+							} elseif($this->isDraftFolder($_folder)) {
6737
+								$flags = '\\Draft';
6738
+							} else {
6739
+								$flags = '';
6740
+							}
6741 6741
 							$savefailed = false;
6742 6742
 							try
6743 6743
 							{
Please login to merge, or discard this patch.
Doc Comments   +16 added lines, -12 removed lines patch added patch discarded remove patch
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 	 * forceEAProfileLoad
437 437
 	 * used to force the load of a specific emailadmin profile; we assume administrative use only (as of now)
438 438
 	 * @param int $_profile_id
439
-	 * @return object instance of Mail (by reference)
439
+	 * @return Mail instance of Mail (by reference)
440 440
 	 */
441 441
 	public static function &forceEAProfileLoad($_profile_id)
442 442
 	{
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	/**
712 712
 	 * Get all identities of given mailaccount
713 713
 	 *
714
-	 * @param int|Mail\Account $account account-object or acc_id
714
+	 * @param integer $account account-object or acc_id
715 715
 	 * @return array - array(email=>realname)
716 716
 	 */
717 717
 	function getAccountIdentities($account)
@@ -1339,7 +1339,7 @@  discard block
 block discarded – undo
1339 1339
 	 * @param array $_filter filter to apply to getSortedList
1340 1340
 	 * @param mixed $_thisUIDOnly = null, if given fetch the headers of this uid only (either one, or array of uids)
1341 1341
 	 * @param boolean $_cacheResult = true try touse the cache of getSortedList
1342
-	 * @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
+	 * @param boolean $_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))
1343 1343
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1344 1344
 	 */
1345 1345
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
@@ -1939,6 +1939,7 @@  discard block
 block discarded – undo
1939 1939
 	 *
1940 1940
 	 * @param mixed _sort the integer sort order / or a valid and handeled SORTSTRING (right now: UID/ARRIVAL/INTERNALDATE (->ARRIVAL))
1941 1941
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1942
+	 * @param integer $_sort
1942 1943
 	 * @return the sort sequence for horde search
1943 1944
 	 */
1944 1945
 	function _getSortString($_sort, $_reverse=false)
@@ -3320,7 +3321,7 @@  discard block
 block discarded – undo
3320 3321
 	 * @param string $_mailbox
3321 3322
 	 * @param string $delimiter
3322 3323
 	 * @param string $prefix
3323
-	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3324
+	 * @param integer $reclevel 0, counter to keep track of the current recursionlevel
3324 3325
 	 * @return array of mailboxes
3325 3326
 	 */
3326 3327
 	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
@@ -3370,7 +3371,7 @@  discard block
 block discarded – undo
3370 3371
 	 * abstraction layer for getDraftFolder, getTemplateFolder, getTrashFolder and getSentFolder
3371 3372
 	 * @param string $_type the type to fetch (Drafts|Template|Trash|Sent)
3372 3373
 	 * @param boolean $_checkexistance trigger check for existance
3373
-	 * @param boolean& $created =null on return true: if folder was just created, false if not
3374
+	 * @param boolean $created =null on return true: if folder was just created, false if not
3374 3375
 	 * @return mixed string or false
3375 3376
 	 */
3376 3377
 	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
@@ -3502,7 +3503,7 @@  discard block
 block discarded – undo
3502 3503
 	/**
3503 3504
 	 * getTemplateFolder wrapper for _getSpecialUseFolder Type Template
3504 3505
 	 * @param boolean $_checkexistance trigger check for existance
3505
-	 * @return mixed string or false
3506
+	 * @return string string or false
3506 3507
 	 */
3507 3508
 	function getTemplateFolder($_checkexistance=TRUE)
3508 3509
 	{
@@ -3532,7 +3533,7 @@  discard block
 block discarded – undo
3532 3533
 	/**
3533 3534
 	 * getOutboxFolder wrapper for _getSpecialUseFolder Type Outbox
3534 3535
 	 * @param boolean $_checkexistance trigger check for existance
3535
-	 * @return mixed string or false
3536
+	 * @return string string or false
3536 3537
 	 */
3537 3538
 	function getOutboxFolder($_checkexistance=TRUE)
3538 3539
 	{
@@ -4421,7 +4422,7 @@  discard block
 block discarded – undo
4421 4422
 	/**
4422 4423
 	 * get part of the message, if its stucture is indicating its of multipart alternative style
4423 4424
 	 * a wrapper for multipartmixed
4424
-	 * @param string/int $_uid the messageuid,
4425
+	 * @param integer $_uid the messageuid,
4425 4426
 	 * @param Horde_Mime_Part $_structure structure for parsing
4426 4427
 	 * @param string $_htmlMode how to display a message, html, plain text, ...
4427 4428
 	 * @param boolean $_preserveSeen flag to preserve the seenflag by using body.peek
@@ -5077,6 +5078,9 @@  discard block
 block discarded – undo
5077 5078
 		return $message;
5078 5079
 	}
5079 5080
 
5081
+	/**
5082
+	 * @param integer $cols
5083
+	 */
5080 5084
 	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
5081 5085
 	{
5082 5086
 		$lines = explode("\n", $str);
@@ -5529,7 +5533,6 @@  discard block
 block discarded – undo
5529 5533
 	 * @param string $_partID = null
5530 5534
 	 * @param string $_folder = null
5531 5535
 	 * @param boolean $_preserveSeen = false flag to preserve the seenflag by using body.peek
5532
-	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5533 5536
 	 * @return Horde_Mime_Part
5534 5537
 	 */
5535 5538
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
@@ -6120,6 +6123,7 @@  discard block
 block discarded – undo
6120 6123
 	 * @param preserveHTML flag to pass through to getdisplayableBody
6121 6124
 	 * @param addHeaderSection flag to be able to supress headersection
6122 6125
 	 * @param includeAttachments flag to be able to supress possible attachments
6126
+	 * @param Mail $mailClass
6123 6127
 	 * @return array/bool with 'mailaddress'=>$mailaddress,
6124 6128
 	 *				'subject'=>$subject,
6125 6129
 	 *				'message'=>$message,
@@ -6573,7 +6577,7 @@  discard block
 block discarded – undo
6573 6577
 	 *
6574 6578
 	 * @param Mailer $_mailObject instance of the Mailer Object to be used
6575 6579
 	 * @param string $_html2parse the html to parse and to be altered, if conditions meet
6576
-	 * @param $mail_bo mail bo object
6580
+	 * @param Mail $mail_bo mail bo object
6577 6581
 	 * @return array|null return inline images stored as tmp file in vfs as array of attachments otherwise null
6578 6582
 	 */
6579 6583
 	static function processURL2InlineImages(Mailer $_mailObject, &$_html2parse, $mail_bo)
@@ -6696,7 +6700,7 @@  discard block
 block discarded – undo
6696 6700
 	 * @param Storage\Merge Storage\Merge bo_merge object
6697 6701
 	 * @param string $document the full filename
6698 6702
 	 * @param array $SendAndMergeTocontacts array of contact ids
6699
-	 * @param string& $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
6703
+	 * @param string|null $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
6700 6704
 	 *					folder is modified
6701 6705
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6702 6706
 	 * @return mixed array of messages with success and failed messages or exception
@@ -6940,7 +6944,7 @@  discard block
 block discarded – undo
6940 6944
 	/**
6941 6945
 	 * Parses a message/rfc mail from file to the mailobject
6942 6946
 	 *
6943
-	 * @param object $mailer instance of the SMTP Mailer Object
6947
+	 * @param Mailer $mailer instance of the SMTP Mailer Object
6944 6948
 	 * @param string $tmpFileName string that points/leads to the file to be imported
6945 6949
 	 * @throws Exception\NotFound if $fle is not found
6946 6950
 	 */
Please login to merge, or discard this patch.
Braces   +1831 added lines, -546 removed lines patch added patch discarded remove patch
@@ -200,7 +200,10 @@  discard block
 block discarded – undo
200 200
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
201 201
 	{
202 202
 		//$_restoreSession=false;
203
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
203
+		if (is_null($_reuseCache))
204
+		{
205
+			$_reuseCache = $_restoreSession;
206
+		}
204 207
 		//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());
205 208
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
206 209
 		self::$profileDefunct = Cache::getCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),5*1);
@@ -231,9 +234,15 @@  discard block
 block discarded – undo
231 234
 			{
232 235
 				$profileID = Mail\Account::get_default_acc_id();
233 236
 			}
234
-			if ($profileID!=$_profileID) $_restoreSession==false;
237
+			if ($profileID!=$_profileID)
238
+			{
239
+				$_restoreSession==false;
240
+			}
235 241
 			$_profileID=$profileID;
236
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
242
+			if (self::$debug)
243
+			{
244
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
245
+			}
237 246
 		}
238 247
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
239 248
 		if ($_oldImapServerObject===true)
@@ -272,7 +281,8 @@  discard block
 block discarded – undo
272 281
 				// TODO: merge mailprefs into userprefs, for easy treatment
273 282
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
274 283
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
275
-			} catch (\Exception $e)
284
+			}
285
+			catch (\Exception $e)
276 286
 			{
277 287
 				$newprofileID = Mail\Account::get_default_acc_id();
278 288
 				// try loading the default profile for the user
@@ -290,9 +300,15 @@  discard block
 block discarded – undo
290 300
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
291 301
 		}
292 302
 		self::$instances[$_profileID]->profileID = $_profileID;
293
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
303
+		if (!isset(self::$instances[$_profileID]->idna2))
304
+		{
305
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
306
+		}
294 307
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
295
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
308
+		if (is_null(self::$mailConfig))
309
+		{
310
+			self::$mailConfig = Config::read('mail');
311
+		}
296 312
 		return self::$instances[$_profileID];
297 313
 	}
298 314
 
@@ -308,7 +324,10 @@  discard block
 block discarded – undo
308 324
 	public static function fixInvalidAliasAddress($refrence, $address)
309 325
 	{
310 326
 		$parts = explode('@', $refrence);
311
-		if (!strpos($address,'@') && !empty($parts[1])) $address .= '@'.$parts[1];
327
+		if (!strpos($address,'@') && !empty($parts[1]))
328
+		{
329
+			$address .= '@'.$parts[1];
330
+		}
312 331
 		return $address;
313 332
 	}
314 333
 
@@ -333,14 +352,20 @@  discard block
 block discarded – undo
333 352
 			}
334 353
 			catch (\Exception $e)
335 354
 			{
336
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
355
+				if ($_profileID != Mail\Account::get_default_acc_id())
356
+				{
357
+					$_profileID = Mail\Account::get_default_acc_id();
358
+				}
337 359
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
338 360
 				return false;
339 361
 			}
340 362
 		}
341 363
 		if ($oldProfileID != $_profileID)
342 364
 		{
343
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
365
+			if ($oldProfileID && $_profileID==0)
366
+			{
367
+				$_profileID = $oldProfileID;
368
+			}
344 369
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
345 370
 			// save prefs
346 371
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -370,11 +395,17 @@  discard block
 block discarded – undo
370 395
 				{
371 396
 					return $_acc_id;
372 397
 				}
373
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
398
+				if (self::$debug)
399
+				{
400
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
401
+				}
374 402
 			}
375 403
 			catch (\Exception $e) {
376 404
 				unset($e);
377
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
405
+				if (self::$debug)
406
+				{
407
+					error_log(__METHOD__."($_acc_id) account NOT found!");
408
+				}
378 409
 			}
379 410
 		}
380 411
 		// no account specified or specified account not found or not valid
@@ -383,11 +414,17 @@  discard block
 block discarded – undo
383 414
 		{
384 415
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
385 416
 			{
386
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
417
+				if (self::$debug && $_acc_id)
418
+				{
419
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
420
+				}
387 421
 				return $acc_id;
388 422
 			}
389 423
 		}
390
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
424
+		if (self::$debug)
425
+		{
426
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
427
+		}
391 428
 		return 0;
392 429
 	}
393 430
 
@@ -403,10 +440,19 @@  discard block
 block discarded – undo
403 440
 	 */
404 441
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
405 442
 	{
406
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
407
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
443
+		if (is_null($_reuseCache))
444
+		{
445
+			$_reuseCache = $_restoreSession;
446
+		}
447
+		if (!empty($_displayCharset))
448
+		{
449
+			self::$displayCharset = $_displayCharset;
450
+		}
408 451
 		// not nummeric, we assume we only want an empty class object
409
-		if (!is_numeric($_profileID)) return true;
452
+		if (!is_numeric($_profileID))
453
+		{
454
+			return true;
455
+		}
410 456
 		if ($_restoreSession)
411 457
 		{
412 458
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -421,7 +467,10 @@  discard block
 block discarded – undo
421 467
 			$firstMessage = $this->sessionData['previewMessage'];
422 468
 			$this->sessionData = array();
423 469
 		}
424
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
470
+		if (!$_reuseCache)
471
+		{
472
+			$this->forcePrefReload($_profileID,!$_reuseCache);
473
+		}
425 474
 		try
426 475
 		{
427 476
 			$this->profileID = self::validateProfileID($_profileID);
@@ -445,7 +494,10 @@  discard block
 block discarded – undo
445 494
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
446 495
 		}
447 496
 
448
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
497
+		if (is_null(self::$mailConfig))
498
+		{
499
+			self::$mailConfig = Config::read('mail');
500
+		}
449 501
 	}
450 502
 
451 503
 	/**
@@ -474,7 +526,10 @@  discard block
 block discarded – undo
474 526
 		// unset the mail_preferences session object, to force the reload/rebuild
475 527
 		Cache::setSession('mail','mail_preferences',serialize(array()));
476 528
 		Cache::setSession('emailadmin','session_data',serialize(array()));
477
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
529
+		if ($_resetFolderObjects)
530
+		{
531
+			self::resetFolderObjectCache($_profile_id);
532
+		}
478 533
 	}
479 534
 
480 535
 	/**
@@ -484,7 +539,10 @@  discard block
 block discarded – undo
484 539
 	{
485 540
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
486 541
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
487
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
542
+		if (!empty(self::$activeFolderCache[$this->profileID]))
543
+		{
544
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
545
+		}
488 546
 	}
489 547
 
490 548
 	/**
@@ -493,7 +551,10 @@  discard block
 block discarded – undo
493 551
 	function saveSessionData()
494 552
 	{
495 553
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
496
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
554
+		if (!empty($this->sessionData['mailbox']))
555
+		{
556
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
557
+		}
497 558
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
498 559
 		{
499 560
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -516,8 +577,14 @@  discard block
 block discarded – undo
516 577
 	 */
517 578
 	static function unsetCachedObjects($_profileID=null)
518 579
 	{
519
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
520
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
580
+		if (is_null($_profileID))
581
+		{
582
+			$_profileID = Mail\Account::get_default_acc_id();
583
+		}
584
+		if (is_array($_profileID) && $_profileID['account_id'])
585
+		{
586
+			$account_id = $_profileID['account_id'];
587
+		}
521 588
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
522 589
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
523 590
 		{
@@ -550,7 +617,10 @@  discard block
 block discarded – undo
550 617
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
551 618
 			}
552 619
 
553
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
620
+			if (isset(self::$instances[$_profileID]))
621
+			{
622
+				unset(self::$instances[$_profileID]);
623
+			}
554 624
 		}
555 625
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
556 626
 		{
@@ -579,7 +649,10 @@  discard block
 block discarded – undo
579 649
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
580 650
 	{
581 651
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
582
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
652
+		if (is_null($account_id))
653
+		{
654
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
655
+		}
583 656
 		if (is_array($_ImapServerId))
584 657
 		{
585 658
 			// called via hook
@@ -618,7 +691,10 @@  discard block
 block discarded – undo
618 691
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
619 692
 	{
620 693
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
621
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
694
+		if (is_null($account_id))
695
+		{
696
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
697
+		}
622 698
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
623 699
 		// or treat it as not given. we try that path
624 700
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -692,10 +768,14 @@  discard block
 block discarded – undo
692 768
 
693 769
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
694 770
 
695
-		foreach($identities as $ik => $ident) {
771
+		foreach($identities as $ik => $ident)
772
+		{
696 773
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
697 774
 			$identity = Mail\Account::read_identity($ik);
698
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
775
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
776
+			{
777
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
778
+			}
699 779
 		}
700 780
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
701 781
 		return $userEMailAdresses;
@@ -713,13 +793,20 @@  discard block
 block discarded – undo
713 793
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
714 794
 		{
715 795
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
716
-			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']);
796
+			if (!$resolve_placeholders)
797
+			{
798
+				$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']);
799
+			}
717 800
 
718
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
801
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
802
+			{
719 803
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
720 804
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
721 805
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
722
-				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']);
806
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
807
+				{
808
+					$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']);
809
+				}
723 810
 			}
724 811
 		}
725 812
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -739,12 +826,16 @@  discard block
 block discarded – undo
739 826
 			$account = Mail\Account::read($account);
740 827
 		}
741 828
 		$userEMailAdresses = array();
742
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
829
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
830
+		{
743 831
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
744 832
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
745 833
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
746 834
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
747
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
835
+			if (empty($identity['ident_id']))
836
+			{
837
+				$identity['ident_id'] = $identity['acc_id'];
838
+			}
748 839
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
749 840
 			{
750 841
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -787,15 +878,25 @@  discard block
 block discarded – undo
787 878
 		// account select box
788 879
 		$selectedID = $this->profileID;
789 880
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
790
-		if ($allAccountData) {
881
+		if ($allAccountData)
882
+		{
791 883
 			$rememberFirst=$selectedFound=null;
792 884
 			foreach ($allAccountData as $tmpkey => $icServers)
793 885
 			{
794
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
795
-				if ($tmpkey == $selectedID) $selectedFound=true;
886
+				if (is_null($rememberFirst))
887
+				{
888
+					$rememberFirst = $tmpkey;
889
+				}
890
+				if ($tmpkey == $selectedID)
891
+				{
892
+					$selectedFound=true;
893
+				}
796 894
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
797 895
 				$host = $icServers->acc_imap_host;
798
-				if (empty($host)) continue;
896
+				if (empty($host))
897
+				{
898
+					continue;
899
+				}
799 900
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
800 901
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
801 902
 			}
@@ -855,7 +956,10 @@  discard block
 block discarded – undo
855 956
 	 */
856 957
 	function reopen($_foldername)
857 958
 	{
858
-		if (self::$debugTimes) $starttime = microtime (true);
959
+		if (self::$debugTimes)
960
+		{
961
+			$starttime = microtime (true);
962
+		}
859 963
 
860 964
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
861 965
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -865,12 +969,16 @@  discard block
 block discarded – undo
865 969
 		//{
866 970
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
867 971
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
868
-			if ($this->folderIsSelectable($_foldername)) {
972
+			if ($this->folderIsSelectable($_foldername))
973
+			{
869 974
 				$this->icServer->openMailbox($_foldername);
870 975
 			}
871 976
 			$folderOpened = $_foldername;
872 977
 		//}
873
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
978
+		if (self::$debugTimes)
979
+		{
980
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
981
+		}
874 982
 	}
875 983
 
876 984
 
@@ -885,13 +993,22 @@  discard block
 block discarded – undo
885 993
 	{
886 994
 		//error_log( "-------------------------->open connection ".function_backtrace());
887 995
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
888
-		if (self::$debugTimes) $starttime = microtime (true);
996
+		if (self::$debugTimes)
997
+		{
998
+			$starttime = microtime (true);
999
+		}
889 1000
 		$mailbox=null;
890 1001
 		try
891 1002
 		{
892
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
893
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
894
-/*
1003
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
1004
+			{
1005
+				$mailbox = $this->sessionData['mailbox'];
1006
+			}
1007
+			if (empty($mailbox))
1008
+			{
1009
+				$mailbox = $this->icServer->getCurrentMailbox();
1010
+			}
1011
+			/*
895 1012
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
896 1013
 			{
897 1014
 				$this->icServer->openMailbox($mailbox);
@@ -916,7 +1033,10 @@  discard block
 block discarded – undo
916 1033
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
917 1034
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
918 1035
 		}
919
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1036
+		if (self::$debugTimes)
1037
+		{
1038
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1039
+		}
920 1040
 	}
921 1041
 
922 1042
 	/**
@@ -928,7 +1048,10 @@  discard block
 block discarded – undo
928 1048
 	function getQuotaRoot()
929 1049
 	{
930 1050
 		static $quota;
931
-		if (isset($quota)) return $quota;
1051
+		if (isset($quota))
1052
+		{
1053
+			return $quota;
1054
+		}
932 1055
 		if (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID]))
933 1056
 		{
934 1057
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -937,7 +1060,8 @@  discard block
 block discarded – undo
937 1060
 		try
938 1061
 		{
939 1062
 			$this->icServer->getCurrentMailbox();
940
-			if(!$this->icServer->hasCapability('QUOTA')) {
1063
+			if(!$this->icServer->hasCapability('QUOTA'))
1064
+			{
941 1065
 				$quota = false;
942 1066
 				return false;
943 1067
 			}
@@ -955,12 +1079,15 @@  discard block
 block discarded – undo
955 1079
 			}
956 1080
 		}
957 1081
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
958
-		if(is_array($quota)) {
1082
+		if(is_array($quota))
1083
+		{
959 1084
 			$quota = array(
960 1085
 				'usage'	=> $quota['USED'],
961 1086
 				'limit'	=> $quota['QMAX'],
962 1087
 			);
963
-		} else {
1088
+		}
1089
+		else
1090
+		{
964 1091
 			$quota = false;
965 1092
 		}
966 1093
 		return $quota;
@@ -976,7 +1103,11 @@  discard block
 block discarded – undo
976 1103
 	static function getTimeOut($_use='IMAP')
977 1104
 	{
978 1105
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
979
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1106
+		if (empty($timeout))
1107
+		{
1108
+			$timeout = ($_use=='SIEVE'?10:20);
1109
+		}
1110
+		// this is the default value
980 1111
 		return $timeout;
981 1112
 	}
982 1113
 
@@ -994,9 +1125,13 @@  discard block
 block discarded – undo
994 1125
 		$foldersNameSpace = array();
995 1126
 		$delimiter = $this->getHierarchyDelimiter();
996 1127
 		// TODO: cache by $this->icServer->ImapServerId
997
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1128
+		if (is_null($nameSpace))
1129
+		{
1130
+			$nameSpace = $this->icServer->getNameSpaceArray();
1131
+		}
998 1132
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
999
-		if (is_array($nameSpace)) {
1133
+		if (is_array($nameSpace))
1134
+		{
1000 1135
 			foreach($nameSpace as $type => $singleNameSpaceArray)
1001 1136
 			{
1002 1137
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -1013,7 +1148,9 @@  discard block
 block discarded – undo
1013 1148
 						$_foldersNameSpace['prefix_present'] = 'forced';
1014 1149
 						// uw-imap server with mailbox prefix or dovecot maybe
1015 1150
 						$_foldersNameSpace['prefix'] = 'mail';
1016
-					} else {
1151
+					}
1152
+					else
1153
+					{
1017 1154
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
1018 1155
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
1019 1156
 					}
@@ -1040,7 +1177,10 @@  discard block
 block discarded – undo
1040 1177
 		foreach($nameSpace as &$singleNameSpace)
1041 1178
 		{
1042 1179
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1043
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1180
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1181
+			{
1182
+				return $singleNameSpace['prefix'];
1183
+			}
1044 1184
 		}
1045 1185
 		return "";
1046 1186
 	}
@@ -1054,8 +1194,14 @@  discard block
 block discarded – undo
1054 1194
 	function getHierarchyDelimiter($_useCache=true)
1055 1195
 	{
1056 1196
 		static $HierarchyDelimiter = null;
1057
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1058
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1197
+		if (is_null($HierarchyDelimiter))
1198
+		{
1199
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1200
+		}
1201
+		if ($_useCache===false)
1202
+		{
1203
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1204
+		}
1059 1205
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1060 1206
 		{
1061 1207
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1089,14 +1235,19 @@  discard block
 block discarded – undo
1089 1235
 	{
1090 1236
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1091 1237
 		static $_specialUseFolders = null;
1092
-		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);
1238
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1239
+		{
1240
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1241
+		}
1093 1242
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1094 1243
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1095 1244
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1096 1245
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1097 1246
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1098 1247
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1099
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1248
+		{
1249
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1250
+		}
1100 1251
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1101 1252
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1102 1253
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1124,7 +1275,8 @@  discard block
 block discarded – undo
1124 1275
 	function folderIsSelectable($folderToSelect)
1125 1276
 	{
1126 1277
 		$retval = true;
1127
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1278
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1279
+		{
1128 1280
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1129 1281
 			{
1130 1282
 				$retval = false;
@@ -1177,7 +1329,10 @@  discard block
 block discarded – undo
1177 1329
 	 */
1178 1330
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1179 1331
 	{
1180
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1332
+		if (self::$debug)
1333
+		{
1334
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1335
+		}
1181 1336
 		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1182 1337
 		{
1183 1338
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -1189,7 +1344,10 @@  discard block
 block discarded – undo
1189 1344
 		{
1190 1345
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1191 1346
 		}
1192
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1347
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1348
+		{
1349
+			return $folderInfoCache[$_folderName];
1350
+		}
1193 1351
 		$retValue = array();
1194 1352
 		$retValue['subscribed'] = false;
1195 1353
 /*
@@ -1218,7 +1376,10 @@  discard block
 block discarded – undo
1218 1376
 			if (is_array($ret))
1219 1377
 			{
1220 1378
 				$retkeys = array_keys($ret);
1221
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1379
+				if ($retkeys[0]==$_folderName)
1380
+				{
1381
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1382
+				}
1222 1383
 			}
1223 1384
 			else
1224 1385
 			{
@@ -1227,7 +1388,8 @@  discard block
 block discarded – undo
1227 1388
 		}
1228 1389
 		$folderInfo = $folderInfoCache[$_folderName];
1229 1390
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1230
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1391
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1392
+		{
1231 1393
 			try
1232 1394
 			{
1233 1395
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1262,7 +1424,8 @@  discard block
 block discarded – undo
1262 1424
 		$retValue['shortName']		= array_pop($shortNameParts);
1263 1425
 		$retValue['displayName']	= $_folderName;
1264 1426
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1265
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1427
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1428
+		{
1266 1429
 			$retValue['displayName']	= lang('INBOX');
1267 1430
 			$retValue['shortDisplayName']	= lang('INBOX');
1268 1431
 		}
@@ -1271,7 +1434,10 @@  discard block
 block discarded – undo
1271 1434
 		{
1272 1435
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1273 1436
 		}
1274
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1437
+		if ($folderInfo)
1438
+		{
1439
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1440
+		}
1275 1441
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1276 1442
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1277 1443
 		{
@@ -1283,24 +1449,34 @@  discard block
 block discarded – undo
1283 1449
 		static $subscribedFolders = null;
1284 1450
 		static $nameSpace = null;
1285 1451
 		static $prefix = null;
1286
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1452
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1453
+		{
1454
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1455
+		}
1287 1456
 		if (!empty($nameSpace[$this->profileID]))
1288 1457
 		{
1289 1458
 			$nsNoPersonal=array();
1290 1459
 			foreach($nameSpace[$this->profileID] as &$ns)
1291 1460
 			{
1292
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1461
+				if ($ns['type']!='personal')
1462
+				{
1463
+					$nsNoPersonal[]=$ns;
1464
+				}
1293 1465
 			}
1294 1466
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1295 1467
 		}
1296
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1468
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1469
+		{
1470
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1471
+		}
1297 1472
 
1298 1473
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1299 1474
 		{
1300 1475
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1301 1476
 		}
1302 1477
 
1303
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1478
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1479
+		{
1304 1480
 			$retValue['subscribed'] = true;
1305 1481
 		}
1306 1482
 
@@ -1319,8 +1495,7 @@  discard block
 block discarded – undo
1319 1495
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1320 1496
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1321 1497
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1322
-			)
1323
-			{
1498
+			) {
1324 1499
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1325 1500
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1326 1501
 				try
@@ -1332,13 +1507,19 @@  discard block
 block discarded – undo
1332 1507
 				}
1333 1508
 				catch (\Exception $ee)
1334 1509
 				{
1335
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1510
+					if (self::$debug)
1511
+					{
1512
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1513
+					}
1336 1514
 				}
1337 1515
 			}
1338 1516
 		}
1339 1517
 		catch (\Exception $e)
1340 1518
 		{
1341
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1519
+			if (self::$debug)
1520
+			{
1521
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1522
+			}
1342 1523
 		}
1343 1524
 
1344 1525
 		return $retValue;
@@ -1363,8 +1544,14 @@  discard block
 block discarded – undo
1363 1544
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1364 1545
 	{
1365 1546
 		//self::$debug=true;
1366
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1367
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1547
+		if (self::$debug)
1548
+		{
1549
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1550
+		}
1551
+		if (self::$debug)
1552
+		{
1553
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1554
+		}
1368 1555
 		$reverse = (bool)$_reverse;
1369 1556
 		// get the list of messages to fetch
1370 1557
 		$this->reopen($_folderName);
@@ -1385,21 +1572,34 @@  discard block
 block discarded – undo
1385 1572
 				//$_filter['range'] ="$start:$end";
1386 1573
 				//$_filter['range'] ="$_startMessage:*";
1387 1574
 			}
1388
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1389
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1575
+			if (self::$debug)
1576
+			{
1577
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1578
+			}
1579
+			if (self::$debug||self::$debugTimes)
1580
+			{
1581
+				$starttime = microtime (true);
1582
+			}
1390 1583
 			//see this example below for a 12 week datefilter (since)
1391 1584
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1392 1585
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1393 1586
 			$sortResult = $_sortResult['match']->ids;
1394 1587
 			//$modseq = $_sortResult['modseq'];
1395 1588
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1396
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1589
+			if (self::$debug||self::$debugTimes)
1590
+			{
1591
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1592
+			}
1397 1593
 
1398
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1594
+			if (self::$debug)
1595
+			{
1596
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1597
+			}
1399 1598
 			#$this->icServer->setDebug(false);
1400 1599
 			#print "</pre>";
1401 1600
 			// nothing found
1402
-			if(!is_array($sortResult) || empty($sortResult)) {
1601
+			if(!is_array($sortResult) || empty($sortResult))
1602
+			{
1403 1603
 				$retValue = array();
1404 1604
 				$retValue['info']['total']	= 0;
1405 1605
 				$retValue['info']['first']	= 0;
@@ -1411,7 +1611,8 @@  discard block
 block discarded – undo
1411 1611
 			#_debug_array($sortResult);
1412 1612
 			#_debug_array(array_slice($sortResult, -5, -2));
1413 1613
 			//error_log("REVERSE: $reverse");
1414
-			if($reverse === true) {
1614
+			if($reverse === true)
1615
+			{
1415 1616
 				if  ($_startMessage<=$total)
1416 1617
 				{
1417 1618
 					$startMessage = $_startMessage-1;
@@ -1423,7 +1624,10 @@  discard block
 block discarded – undo
1423 1624
 					{
1424 1625
 						$numberOfMessages = $total%$_numberOfMessages;
1425 1626
 						//$numberOfMessages = abs($_startMessage-$total-1);
1426
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1627
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1628
+						{
1629
+							$_numberOfMessages = $numberOfMessages;
1630
+						}
1427 1631
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1428 1632
 					}
1429 1633
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1437,19 +1641,36 @@  discard block
 block discarded – undo
1437 1641
 					//$retValue['info']['first'] = $startMessage;
1438 1642
 					//$retValue['info']['last'] = $total;
1439 1643
 				}
1440
-				if($startMessage > 0) {
1441
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1644
+				if($startMessage > 0)
1645
+				{
1646
+					if (self::$debug)
1647
+					{
1648
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1649
+					}
1442 1650
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1443
-				} else {
1444
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1651
+				}
1652
+				else
1653
+				{
1654
+					if (self::$debug)
1655
+					{
1656
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1657
+					}
1445 1658
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1446 1659
 				}
1447 1660
 				$sortResult = array_reverse($sortResult);
1448
-			} else {
1449
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1661
+			}
1662
+			else
1663
+			{
1664
+				if (self::$debug)
1665
+				{
1666
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1667
+				}
1450 1668
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1451 1669
 			}
1452
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1670
+			if (self::$debug)
1671
+			{
1672
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1673
+			}
1453 1674
 		}
1454 1675
 		else
1455 1676
 		{
@@ -1458,7 +1679,10 @@  discard block
 block discarded – undo
1458 1679
 
1459 1680
 
1460 1681
 		// fetch the data for the selected messages
1461
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1682
+		if (self::$debug||self::$debugTimes)
1683
+		{
1684
+			$starttime = microtime(true);
1685
+		}
1462 1686
 		try
1463 1687
 		{
1464 1688
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1482,7 +1706,10 @@  discard block
 block discarded – undo
1482 1706
 			$fquery->flags();
1483 1707
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1484 1708
 			// if $_fetchPreviews is activated fetch part of the messages too
1485
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1709
+			if ($_fetchPreviews)
1710
+			{
1711
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1712
+			}
1486 1713
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1487 1714
 				'ids' => $uidsToFetch,
1488 1715
 			));
@@ -1505,14 +1732,20 @@  discard block
 block discarded – undo
1505 1732
 
1506 1733
 		$cnt = 0;
1507 1734
 
1508
-		foreach((array)$sortResult as $uid) {
1735
+		foreach((array)$sortResult as $uid)
1736
+		{
1509 1737
 			$sortOrder[$uid] = $cnt++;
1510 1738
 		}
1511 1739
 
1512 1740
 		$count = 0;
1513
-		if (is_object($headersNew)) {
1514
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1515
-			foreach($headersNew->ids() as $id) {
1741
+		if (is_object($headersNew))
1742
+		{
1743
+			if (self::$debug||self::$debugTimes)
1744
+			{
1745
+				$starttime = microtime(true);
1746
+			}
1747
+			foreach($headersNew->ids() as $id)
1748
+			{
1516 1749
 				$_headerObject = $headersNew->get($id);
1517 1750
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1518 1751
 				$headerObject = array();
@@ -1525,7 +1758,10 @@  discard block
 block discarded – undo
1525 1758
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1526 1759
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1527 1760
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1528
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1761
+				if (empty($headerForPrio))
1762
+				{
1763
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1764
+				}
1529 1765
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1530 1766
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1531 1767
 				if ($_fetchPreviews)
@@ -1536,12 +1772,16 @@  discard block
 block discarded – undo
1536 1772
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1537 1773
 					{
1538 1774
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1539
-						if ($length===false) $length = strlen($bodyPreview);
1775
+						if ($length===false)
1776
+						{
1777
+							$length = strlen($bodyPreview);
1778
+						}
1540 1779
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1541 1780
 					}
1542 1781
 				}
1543 1782
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1544
-				if (self::$debug) {
1783
+				if (self::$debug)
1784
+				{
1545 1785
 					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'));
1546 1786
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1547 1787
 				}
@@ -1551,11 +1791,16 @@  discard block
 block discarded – undo
1551 1791
 					$total--;
1552 1792
 					continue;
1553 1793
 				}
1554
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1794
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1795
+				{
1555 1796
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1556
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1797
+				}
1798
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1799
+				{
1557 1800
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1558
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1801
+				}
1802
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1803
+				{
1559 1804
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1560 1805
 				} /*else $sent_not = "";*/
1561 1806
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1587,7 +1832,11 @@  discard block
 block discarded – undo
1587 1832
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1588 1833
 						foreach ($rfcAddr as $_rfcAddr)
1589 1834
 						{
1590
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1835
+							if (!$_rfcAddr->valid)
1836
+							{
1837
+								continue;
1838
+							}
1839
+							// skip. not a valid address
1591 1840
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1592 1841
 						}
1593 1842
 					}
@@ -1603,7 +1852,10 @@  discard block
 block discarded – undo
1603 1852
 				{
1604 1853
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1605 1854
 					// needed to parse the Headers of the Message
1606
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1855
+					if (empty($bodyPreview))
1856
+					{
1857
+						$bodyPreview = $_headerObject->getFullMsg();
1858
+					}
1607 1859
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1608 1860
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1609 1861
 					foreach($base->partIterator() as $part)
@@ -1616,7 +1868,8 @@  discard block
 block discarded – undo
1616 1868
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1617 1869
 											)), $charset, 'utf-8');
1618 1870
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1619
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1871
+						}
1872
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1620 1873
 						{
1621 1874
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1622 1875
 						}
@@ -1632,7 +1885,10 @@  discard block
 block discarded – undo
1632 1885
 				$messageMimeType='';
1633 1886
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1634 1887
 				{
1635
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1888
+					if ($mime_id==0 || $messageMimeType==='')
1889
+					{
1890
+						$messageMimeType = $mime_type;
1891
+					}
1636 1892
 					$part = $mailStructureObject->getPart($mime_id);
1637 1893
 					$partdisposition = $part->getDisposition();
1638 1894
 					$partPrimaryType = $part->getPrimaryType();
@@ -1642,7 +1898,8 @@  discard block
 block discarded – undo
1642 1898
 					// bodypreview could be found (multipart/....)
1643 1899
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1644 1900
 						((intval($mime_id) === 1) || !$mime_id) &&
1645
-						($partdisposition !== 'attachment')) {
1901
+						($partdisposition !== 'attachment'))
1902
+					{
1646 1903
 							$_structure=$part;
1647 1904
 							$this->fetchPartContents($uid, $_structure, false,true);
1648 1905
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1664,10 +1921,19 @@  discard block
 block discarded – undo
1664 1921
 					if ($mime_type=='message/rfc822')
1665 1922
 					{
1666 1923
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1667
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1924
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1925
+						{
1926
+if ($sub_id != $mime_id)
1927
+						{
1928
+							$skipParts[$sub_id] = $sub_type;
1929
+						}
1930
+						}
1668 1931
 					}
1669 1932
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1670
-					if (array_key_exists($mime_id,$skipParts)) continue;
1933
+					if (array_key_exists($mime_id,$skipParts))
1934
+					{
1935
+						continue;
1936
+					}
1671 1937
 					if ($partdisposition=='attachment' ||
1672 1938
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1673 1939
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1678,7 +1944,10 @@  discard block
 block discarded – undo
1678 1944
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1679 1945
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1680 1946
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1681
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1947
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1948
+						{
1949
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1950
+						}
1682 1951
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1683 1952
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1684 1953
 						{
@@ -1692,18 +1961,27 @@  discard block
 block discarded – undo
1692 1961
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1693 1962
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1694 1963
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1695
-				if (empty($headerObject['UID'])) continue;
1964
+				if (empty($headerObject['UID']))
1965
+				{
1966
+					continue;
1967
+				}
1696 1968
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1697 1969
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1698
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1970
+				if(substr($headerObject['DATE'],-2) === 'UT')
1971
+				{
1699 1972
 					$headerObject['DATE'] .= 'C';
1700 1973
 				}
1701
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1974
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1975
+				{
1702 1976
 					$headerObject['INTERNALDATE'] .= 'C';
1703 1977
 				}
1704 1978
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1705 1979
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1706
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1980
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1981
+				{
1982
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1983
+				}
1984
+				}
1707 1985
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1708 1986
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1709 1987
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1714,25 +1992,35 @@  discard block
 block discarded – undo
1714 1992
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1715 1993
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1716 1994
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1717
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1718
-				if (is_array($headerObject['FLAGS'])) {
1995
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1996
+				{
1997
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1998
+				}
1999
+				if (is_array($headerObject['FLAGS']))
2000
+				{
1719 2001
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1720 2002
 				}
1721 2003
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1722
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
2004
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
2005
+				{
1723 2006
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1724 2007
 				}
1725
-				if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) {
2008
+				if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0])
2009
+				{
1726 2010
 					$retValue['header'][$sortOrder[$uid]]['reply_to_address'] = self::decode_header($headerObject['REPLY-TO'][0],true);
1727 2011
 				}
1728
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
2012
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
2013
+				{
1729 2014
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1730 2015
 					if (count($headerObject['TO'])>1)
1731 2016
 					{
1732 2017
 						$ki=0;
1733 2018
 						foreach($headerObject['TO'] as $k => $add)
1734 2019
 						{
1735
-							if ($k==0) continue;
2020
+							if ($k==0)
2021
+							{
2022
+								continue;
2023
+							}
1736 2024
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1737 2025
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1738 2026
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1740,7 +2028,8 @@  discard block
 block discarded – undo
1740 2028
 						}
1741 2029
 					}
1742 2030
 				}
1743
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
2031
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
2032
+				{
1744 2033
 					$ki=0;
1745 2034
 					foreach($headerObject['CC'] as $k => $add)
1746 2035
 					{
@@ -1754,27 +2043,41 @@  discard block
 block discarded – undo
1754 2043
 
1755 2044
 				$count++;
1756 2045
 			}
1757
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2046
+			if (self::$debug||self::$debugTimes)
2047
+			{
2048
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2049
+			}
1758 2050
 			//self::$debug=false;
1759 2051
 			// sort the messages to the requested displayorder
1760
-			if(is_array($retValue['header'])) {
2052
+			if(is_array($retValue['header']))
2053
+			{
1761 2054
 				$countMessages = $total;
1762
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2055
+				if (isset($_filter['range']))
2056
+				{
2057
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2058
+				}
1763 2059
 				ksort($retValue['header']);
1764 2060
 				$retValue['info']['total']	= $total;
1765 2061
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1766 2062
 				$retValue['info']['first']	= $_startMessage;
1767 2063
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1768 2064
 				return $retValue;
1769
-			} else {
2065
+			}
2066
+			else
2067
+			{
1770 2068
 				$retValue = array();
1771 2069
 				$retValue['info']['total']	= 0;
1772 2070
 				$retValue['info']['first']	= 0;
1773 2071
 				$retValue['info']['last']	= 0;
1774 2072
 				return $retValue;
1775 2073
 			}
1776
-		} else {
1777
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2074
+		}
2075
+		else
2076
+		{
2077
+			if ($headersNew == null && empty($_thisUIDOnly))
2078
+			{
2079
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2080
+			}
1778 2081
 			$retValue = array();
1779 2082
 			$retValue['info']['total']  = 0;
1780 2083
 			$retValue['info']['first']  = 0;
@@ -1791,7 +2094,10 @@  discard block
 block discarded – undo
1791 2094
 	 */
1792 2095
 	static function prepareFlagsArray($headerObject)
1793 2096
 	{
1794
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2097
+		if (is_array($headerObject['FLAGS']))
2098
+		{
2099
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2100
+		}
1795 2101
 		$retValue = array();
1796 2102
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1797 2103
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1842,26 +2148,45 @@  discard block
 block discarded – undo
1842 2148
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1843 2149
 		$try2useCache = true;
1844 2150
 		static $eMailListContainsDeletedMessages = null;
1845
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2151
+		if (is_null($eMailListContainsDeletedMessages))
2152
+		{
2153
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2154
+		}
1846 2155
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1847 2156
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1848 2157
 		{
1849
-			if (self::$debugTimes) $starttime = microtime(true);
1850
-			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);
2158
+			if (self::$debugTimes)
2159
+			{
2160
+				$starttime = microtime(true);
2161
+			}
2162
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2163
+			{
2164
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2165
+			}
1851 2166
 			$five=true;
1852 2167
 			$dReverse=1;
1853 2168
 			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false);
1854
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2169
+			if (self::$debug)
2170
+			{
2171
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2172
+			}
1855 2173
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1856 2174
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1857
-			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']);
2175
+			if (self::$debugTimes)
2176
+			{
2177
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2178
+			}
2179
+			//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']);
1858 2180
 		}
1859 2181
 		$try2useCache = false;
1860 2182
 		//self::$supportsORinQuery[$this->profileID]=true;
1861 2183
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1862 2184
 		{
1863 2185
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1864
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2186
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2187
+			{
2188
+				self::$supportsORinQuery[$this->profileID]=true;
2189
+			}
1865 2190
 		}
1866 2191
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1867 2192
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1872,15 +2197,26 @@  discard block
 block discarded – undo
1872 2197
 		}
1873 2198
 		//_debug_array($filter);
1874 2199
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1875
-		if($this->icServer->hasCapability('SORT')) {
2200
+		if($this->icServer->hasCapability('SORT'))
2201
+		{
1876 2202
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1877 2203
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1878 2204
 			// there is no messing with the dates)
1879 2205
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1880
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2206
+			if (self::$debug)
2207
+			{
2208
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2209
+			}
1881 2210
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1882
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1883
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2211
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2212
+			{
2213
+				$_reverse=false;
2214
+			}
2215
+			// as we reversed the result already
2216
+			if (self::$debug)
2217
+			{
2218
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2219
+			}
1884 2220
 			try
1885 2221
 			{
1886 2222
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1889,7 +2225,10 @@  discard block
 block discarded – undo
1889 2225
 				// Attempt another search without sorting filter if first try failed with
1890 2226
 				// no result, as may some servers do not coupe well with sort option
1891 2227
 				// eventhough they claim to support SORT capability.
1892
-				if (!isset($sortResult['count'])) $sortResult = $this->icServer->search($_folderName, $filter);
2228
+				if (!isset($sortResult['count']))
2229
+				{
2230
+					$sortResult = $this->icServer->search($_folderName, $filter);
2231
+				}
1893 2232
 
1894 2233
 			// if there is an Error, we assume that the server is not capable of sorting
1895 2234
 			}
@@ -1898,7 +2237,10 @@  discard block
 block discarded – undo
1898 2237
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1899 2238
 				$resultByUid = false;
1900 2239
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1901
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2240
+				if ($_reverse)
2241
+				{
2242
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2243
+				}
1902 2244
 				try
1903 2245
 				{
1904 2246
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1910,9 +2252,17 @@  discard block
 block discarded – undo
1910 2252
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1911 2253
 				}
1912 2254
 			}
1913
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1914
-		} else {
1915
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2255
+			if (self::$debug)
2256
+			{
2257
+				error_log(__METHOD__.print_r($sortResult,true));
2258
+			}
2259
+		}
2260
+		else
2261
+		{
2262
+			if (self::$debug)
2263
+			{
2264
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2265
+			}
1916 2266
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1917 2267
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1918 2268
 			try
@@ -1926,7 +2276,10 @@  discard block
 block discarded – undo
1926 2276
 				// possible error OR Query. But Horde gives no detailed Info :-(
1927 2277
 				self::$supportsORinQuery[$this->profileID]=false;
1928 2278
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1929
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2279
+				if (self::$debug)
2280
+				{
2281
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2282
+				}
1930 2283
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1931 2284
 				try
1932 2285
 				{
@@ -1937,11 +2290,15 @@  discard block
 block discarded – undo
1937 2290
 				{
1938 2291
 				}
1939 2292
 			}
1940
-			if(is_array($sortResult['match'])) {
2293
+			if(is_array($sortResult['match']))
2294
+			{
1941 2295
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1942 2296
 					sort($sortResult['match'], SORT_NUMERIC);
1943 2297
 			}
1944
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2298
+			if (self::$debug)
2299
+			{
2300
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2301
+			}
1945 2302
 		}
1946 2303
 		if ($setSession)
1947 2304
 		{
@@ -1970,7 +2327,8 @@  discard block
 block discarded – undo
1970 2327
 		$_reverse=false;
1971 2328
 		if (is_numeric($_sort))
1972 2329
 		{
1973
-			switch($_sort) {
2330
+			switch($_sort)
2331
+			{
1974 2332
 				case 2:
1975 2333
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1976 2334
 					break;
@@ -1992,7 +2350,8 @@  discard block
 block discarded – undo
1992 2350
 		}
1993 2351
 		else
1994 2352
 		{
1995
-			switch(strtoupper($_sort)) {
2353
+			switch(strtoupper($_sort))
2354
+			{
1996 2355
 				case 'FROMADDRESS':
1997 2356
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1998 2357
 					break;
@@ -2018,7 +2377,10 @@  discard block
 block discarded – undo
2018 2377
 					break;
2019 2378
 			}
2020 2379
 		}
2021
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2380
+		if ($_reverse)
2381
+		{
2382
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2383
+		}
2022 2384
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
2023 2385
 		return $retValue;
2024 2386
 	}
@@ -2037,7 +2399,10 @@  discard block
 block discarded – undo
2037 2399
 		$imapFilter->charset('UTF-8');
2038 2400
 
2039 2401
 		//_debug_array($_criterias);
2040
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2402
+		if (self::$debug)
2403
+		{
2404
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2405
+		}
2041 2406
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2042 2407
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2043 2408
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -2052,11 +2417,13 @@  discard block
 block discarded – undo
2052 2417
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2053 2418
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2054 2419
 		$statusQueryValid = false;
2055
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2420
+		foreach((array)$_criterias['status'] as $k => $criteria)
2421
+		{
2056 2422
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2057 2423
 			$imapStatusFilter->charset('UTF-8');
2058 2424
 			$criteria = strtoupper($criteria);
2059
-			switch ($criteria) {
2425
+			switch ($criteria)
2426
+			{
2060 2427
 				case 'ANSWERED':
2061 2428
 				case 'DELETED':
2062 2429
 				case 'FLAGGED':
@@ -2139,9 +2506,11 @@  discard block
 block discarded – undo
2139 2506
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2140 2507
 		$imapSearchFilter->charset('UTF-8');
2141 2508
 
2142
-		if(!empty($_criterias['string'])) {
2509
+		if(!empty($_criterias['string']))
2510
+		{
2143 2511
 			$criteria = strtoupper($_criterias['type']);
2144
-			switch ($criteria) {
2512
+			switch ($criteria)
2513
+			{
2145 2514
 				case 'BYDATE':
2146 2515
 				case 'QUICK':
2147 2516
 				case 'QUICKWITHCC':
@@ -2149,9 +2518,12 @@  discard block
 block discarded – undo
2149 2518
 					//$imapSearchFilter->charset('UTF-8');
2150 2519
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2151 2520
 					$imapFilter2->charset('UTF-8');
2152
-					if($this->isSentFolder($_folder)) {
2521
+					if($this->isSentFolder($_folder))
2522
+					{
2153 2523
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2154
-					} else {
2524
+					}
2525
+					else
2526
+					{
2155 2527
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2156 2528
 					}
2157 2529
 					if ($_supportsOrInQuery)
@@ -2182,7 +2554,10 @@  discard block
 block discarded – undo
2182 2554
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2183 2555
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2184 2556
 						$numberinBytes=(float)$_criterias['string'];
2185
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2557
+						if (isset($multipleBy[$unit]))
2558
+						{
2559
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2560
+						}
2186 2561
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2187 2562
 						$_criterias['string']=$numberinBytes;
2188 2563
 					}
@@ -2219,8 +2594,14 @@  discard block
 block discarded – undo
2219 2594
 					break;
2220 2595
 			}
2221 2596
 		}
2222
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2223
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2597
+		if ($statusQueryValid && !$queryValid)
2598
+		{
2599
+			$queryValid=true;
2600
+		}
2601
+		if ($queryValid)
2602
+		{
2603
+			$imapFilter->andSearch($imapSearchFilter);
2604
+		}
2224 2605
 
2225 2606
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2226 2607
 		{
@@ -2235,7 +2616,8 @@  discard block
 block discarded – undo
2235 2616
 				unset($_criterias['before']);
2236 2617
 				$criteria=$_criterias['range']='ON';
2237 2618
 			}
2238
-			switch ($criteria) {
2619
+			switch ($criteria)
2620
+			{
2239 2621
 				case 'BETWEEN':
2240 2622
 					//try to be smart about missing
2241 2623
 					//enddate
@@ -2271,8 +2653,14 @@  discard block
 block discarded – undo
2271 2653
 					$rangeValid = true;
2272 2654
 					break;
2273 2655
 			}
2274
-			if ($rangeValid && !$queryValid) $queryValid=true;
2275
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2656
+			if ($rangeValid && !$queryValid)
2657
+			{
2658
+				$queryValid=true;
2659
+			}
2660
+			if ($rangeValid)
2661
+			{
2662
+				$imapFilter->andSearch($imapRangeFilter);
2663
+			}
2276 2664
 		}
2277 2665
 		if (self::$debug)
2278 2666
 		{
@@ -2280,10 +2668,13 @@  discard block
 block discarded – undo
2280 2668
 			$query_str = $imapFilter->build();
2281 2669
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2282 2670
 		}
2283
-		if($queryValid==false) {
2671
+		if($queryValid==false)
2672
+		{
2284 2673
 			$imapFilter->flag('DELETED', $set=false);
2285 2674
 			return $imapFilter;
2286
-		} else {
2675
+		}
2676
+		else
2677
+		{
2287 2678
 			return $imapFilter;
2288 2679
 		}
2289 2680
 	}
@@ -2340,7 +2731,10 @@  discard block
 block discarded – undo
2340 2731
 					}
2341 2732
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2342 2733
 				}
2343
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2734
+				if (!empty($stringA))
2735
+				{
2736
+					$_string = implode(',',$stringA);
2737
+				}
2344 2738
 			}
2345 2739
 			if ($_tryIDNConversion==='FORCE')
2346 2740
 			{
@@ -2365,7 +2759,10 @@  discard block
 block discarded – undo
2365 2759
 		{
2366 2760
 			return 'No Subject';
2367 2761
 		}
2368
-		if ($decode) $_string = self::decode_header($_string);
2762
+		if ($decode)
2763
+		{
2764
+			$_string = self::decode_header($_string);
2765
+		}
2369 2766
 		// make sure its utf-8
2370 2767
 		$test = @json_encode($_string);
2371 2768
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2403,7 +2800,8 @@  discard block
 block discarded – undo
2403 2800
 	 * @param string _parent the parent foldername
2404 2801
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2405 2802
 	 */
2406
-	function _encodeFolderName($_folderName) {
2803
+	function _encodeFolderName($_folderName)
2804
+	{
2407 2805
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2408 2806
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2409 2807
 	}
@@ -2419,21 +2817,36 @@  discard block
 block discarded – undo
2419 2817
 	 */
2420 2818
 	function createFolder($_parent, $_folderName, &$_error)
2421 2819
 	{
2422
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2820
+		if (self::$debug)
2821
+		{
2822
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2823
+		}
2423 2824
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2424 2825
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2425 2826
 
2426
-		if(empty($parent)) {
2827
+		if(empty($parent))
2828
+		{
2427 2829
 			$newFolderName = $folderName;
2428
-		} else {
2830
+		}
2831
+		else
2832
+		{
2429 2833
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2430 2834
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2431 2835
 		}
2432
-		if (empty($newFolderName)) return false;
2433
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2836
+		if (empty($newFolderName))
2837
+		{
2838
+			return false;
2839
+		}
2840
+		if (self::$debug)
2841
+		{
2842
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2843
+		}
2434 2844
 		if ($this->folderExists($newFolderName,true))
2435 2845
 		{
2436
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2846
+			if (self::$debug)
2847
+			{
2848
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2849
+			}
2437 2850
 			return $newFolderName;
2438 2851
 		}
2439 2852
 		try
@@ -2481,13 +2894,19 @@  discard block
 block discarded – undo
2481 2894
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2482 2895
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2483 2896
 
2484
-		if(empty($parent)) {
2897
+		if(empty($parent))
2898
+		{
2485 2899
 			$newFolderName = $folderName;
2486
-		} else {
2900
+		}
2901
+		else
2902
+		{
2487 2903
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2488 2904
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2489 2905
 		}
2490
-		if (self::$debug) error_log("create folder: $newFolderName");
2906
+		if (self::$debug)
2907
+		{
2908
+			error_log("create folder: $newFolderName");
2909
+		}
2491 2910
 		try
2492 2911
 		{
2493 2912
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2561,8 +2980,14 @@  discard block
 block discarded – undo
2561 2980
 	 */
2562 2981
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2563 2982
 	{
2564
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2565
-		if (self::$debugTimes) $starttime = microtime (true);
2983
+		if (self::$debug)
2984
+		{
2985
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2986
+		}
2987
+		if (self::$debugTimes)
2988
+		{
2989
+			$starttime = microtime (true);
2990
+		}
2566 2991
 		static $folders2return;
2567 2992
 		//$_subscribedOnly=false;
2568 2993
 		// always use static on single request if info is available;
@@ -2570,23 +2995,35 @@  discard block
 block discarded – undo
2570 2995
 		// set $_useCacheIfPossible to false !
2571 2996
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2572 2997
 		{
2573
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2998
+			if (self::$debugTimes)
2999
+			{
3000
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
3001
+			}
2574 3002
 			return $folders2return[$this->icServer->ImapServerId];
2575 3003
 		}
2576 3004
 
2577 3005
 		if ($_subscribedOnly && $_getCounters===false)
2578 3006
 		{
2579
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
3007
+			if (is_null($folders2return))
3008
+			{
3009
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
3010
+			}
2580 3011
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2581 3012
 			{
2582 3013
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2583
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
3014
+				if (self::$debugTimes)
3015
+				{
3016
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
3017
+				}
2584 3018
 				return $folders2return[$this->icServer->ImapServerId];
2585 3019
 			}
2586 3020
 		}
2587 3021
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2588 3022
 		static $folderBasicInfo;
2589
-		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);
3023
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
3024
+		{
3025
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
3026
+		}
2590 3027
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2591 3028
 
2592 3029
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2599,7 +3036,8 @@  discard block
 block discarded – undo
2599 3036
 		$inboxData->shortFolderName	= 'INBOX';
2600 3037
 		$inboxData->shortDisplayName	= lang('INBOX');
2601 3038
 		$inboxData->subscribed = true;
2602
-		if($_getCounters == true) {
3039
+		if($_getCounters == true)
3040
+		{
2603 3041
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2604 3042
 		}
2605 3043
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2618,12 +3056,14 @@  discard block
 block discarded – undo
2618 3056
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2619 3057
 		if (is_array($nameSpace))
2620 3058
 		{
2621
-			foreach($nameSpace as $k => $singleNameSpace) {
3059
+			foreach($nameSpace as $k => $singleNameSpace)
3060
+			{
2622 3061
 				$type = $singleNameSpace['type'];
2623 3062
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2624 3063
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2625 3064
 
2626
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
3065
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
3066
+				{
2627 3067
 					// fetch and sort the subscribed folders
2628 3068
 					// we alway fetch the subscribed, as this provides the only way to tell
2629 3069
 					// if a folder is subscribed or not
@@ -2674,8 +3114,12 @@  discard block
 block discarded – undo
2674 3114
 							}
2675 3115
 						}
2676 3116
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2677
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2678
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3117
+						if (!is_array($foldersNameSpace[$type]['all']))
3118
+						{
3119
+							$foldersNameSpace[$type]['all'] = array();
3120
+						}
3121
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3122
+						{
2679 3123
 							continue;
2680 3124
 						}
2681 3125
 
@@ -2705,7 +3149,8 @@  discard block
 block discarded – undo
2705 3149
 					}
2706 3150
 
2707 3151
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2708
-					foreach ($allMailboxesExt as $mbx) {
3152
+					foreach ($allMailboxesExt as $mbx)
3153
+					{
2709 3154
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2710 3155
 						{
2711 3156
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2728,20 +3173,33 @@  discard block
 block discarded – undo
2728 3173
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2729 3174
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2730 3175
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2731
-						) continue;
3176
+						)
3177
+						{
3178
+							continue;
3179
+						}
2732 3180
 
2733 3181
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2734 3182
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2735 3183
 					}
2736
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3184
+					if (is_array($allMailBoxesExtSorted))
3185
+					{
3186
+						ksort($allMailBoxesExtSorted);
3187
+					}
2737 3188
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2738 3189
 					$allMailboxes = array();
2739
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2740
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3190
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3191
+					{
3192
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3193
+						{
3194
+							$allMailboxes[] = $mbx['MAILBOX'];
3195
+						}
2741 3196
 						//echo "Result:";_debug_array($allMailboxes);
2742 3197
 					}
2743 3198
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2744
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3199
+					if (is_array($foldersNameSpace[$type]['all']))
3200
+					{
3201
+						sort($foldersNameSpace[$type]['all']);
3202
+					}
2745 3203
 				}
2746 3204
 			}
2747 3205
 		}
@@ -2750,24 +3208,50 @@  discard block
 block discarded – undo
2750 3208
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2751 3209
 		$autoFolderObjects = $folders = array();
2752 3210
 		$autofolder_exists = array();
2753
-		foreach( array('personal', 'others', 'shared') as $type) {
2754
-			if(isset($foldersNameSpace[$type])) {
2755
-				if($_subscribedOnly) {
2756
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2757
-				} else {
2758
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2759
-				}
2760
-				foreach((array)$listOfFolders as $folderName) {
3211
+		foreach( array('personal', 'others', 'shared') as $type)
3212
+		{
3213
+			if(isset($foldersNameSpace[$type]))
3214
+			{
3215
+				if($_subscribedOnly)
3216
+				{
3217
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3218
+					{
3219
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3220
+					}
3221
+				}
3222
+				else
3223
+				{
3224
+					if( !empty($foldersNameSpace[$type]['all']))
3225
+					{
3226
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3227
+					}
3228
+				}
3229
+				foreach((array)$listOfFolders as $folderName)
3230
+				{
2761 3231
 					//echo "<br>FolderToCheck:$folderName<br>";
2762 3232
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2763
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2764
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3233
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3234
+					{
3235
+						continue;
3236
+					}
3237
+					//when subscribedonly, we fetch all folders in one go.
3238
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3239
+					{
2765 3240
 						#echo "$folderName failed to be here <br>";
2766 3241
 						continue;
2767 3242
 					}
2768
-					if (isset($folders[$folderName])) continue;
2769
-					if (isset($autoFolderObjects[$folderName])) continue;
2770
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3243
+					if (isset($folders[$folderName]))
3244
+					{
3245
+						continue;
3246
+					}
3247
+					if (isset($autoFolderObjects[$folderName]))
3248
+					{
3249
+						continue;
3250
+					}
3251
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3252
+					{
3253
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3254
+					}
2771 3255
 					$folderParts = explode($delimiter, $folderName);
2772 3256
 					$shortName = array_pop($folderParts);
2773 3257
 
@@ -2775,17 +3259,20 @@  discard block
 block discarded – undo
2775 3259
 					$folderObject->delimiter	= $delimiter;
2776 3260
 					$folderObject->folderName	= $folderName;
2777 3261
 					$folderObject->shortFolderName	= $shortName;
2778
-					if(!$_subscribedOnly) {
3262
+					if(!$_subscribedOnly)
3263
+					{
2779 3264
 						#echo $folderName."->".$type."<br>";
2780 3265
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2781 3266
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2782 3267
 					}
2783 3268
 
2784
-					if($_getCounters == true) {
3269
+					if($_getCounters == true)
3270
+					{
2785 3271
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2786 3272
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2787 3273
 					}
2788
-					if(strtoupper($folderName) == 'INBOX') {
3274
+					if(strtoupper($folderName) == 'INBOX')
3275
+					{
2789 3276
 						$folderName = 'INBOX';
2790 3277
 						$folderObject->folderName	= 'INBOX';
2791 3278
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2793,24 +3280,34 @@  discard block
 block discarded – undo
2793 3280
 						$folderObject->shortDisplayName = lang('INBOX');
2794 3281
 						$folderObject->subscribed	= true;
2795 3282
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2796
-					} elseif (in_array($shortName,self::$autoFolders)) {
3283
+					}
3284
+					elseif (in_array($shortName,self::$autoFolders))
3285
+					{
2797 3286
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2798 3287
 						array_pop($tmpfolderparts);
2799 3288
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2800 3289
 						$folderObject->shortDisplayName = lang($shortName);
2801 3290
 						unset($tmpfolderparts);
2802
-					} else {
3291
+					}
3292
+					else
3293
+					{
2803 3294
 						$folderObject->displayName = $folderObject->folderName;
2804 3295
 						$folderObject->shortDisplayName = $shortName;
2805 3296
 					}
2806 3297
 					//$folderName = $folderName;
2807
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3298
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3299
+					{
2808 3300
 						$autoFolderObjects[$folderName] = $folderObject;
2809
-					} else {
3301
+					}
3302
+					else
3303
+					{
2810 3304
 						$folders[$folderName] = $folderObject;
2811 3305
 					}
2812 3306
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2813
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3307
+					if (!isset(self::$specialUseFolders))
3308
+					{
3309
+						$this->getSpecialUseFolders ();
3310
+					}
2814 3311
 					if (isset(self::$specialUseFolders[$folderName]))
2815 3312
 					{
2816 3313
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2818,7 +3315,8 @@  discard block
 block discarded – undo
2818 3315
 				}
2819 3316
 			}
2820 3317
 		}
2821
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3318
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3319
+		{
2822 3320
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2823 3321
 		}
2824 3322
 		// check if some standard folders are missing and need to be created
@@ -2827,7 +3325,10 @@  discard block
 block discarded – undo
2827 3325
 			// if new folders have been created, re-read folders ignoring the cache
2828 3326
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2829 3327
 		}
2830
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3328
+		if (is_array($folders))
3329
+		{
3330
+			uasort($folders,array($this,"sortByDisplayName"));
3331
+		}
2831 3332
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2832 3333
 		//_debug_array($folders2return); #exit;
2833 3334
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2839,7 +3340,10 @@  discard block
 block discarded – undo
2839 3340
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2840 3341
 		}
2841 3342
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2842
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3343
+		if (self::$debugTimes)
3344
+		{
3345
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3346
+		}
2843 3347
 		return $folders2return[$this->icServer->ImapServerId];
2844 3348
 	}
2845 3349
 
@@ -2867,31 +3371,44 @@  discard block
 block discarded – undo
2867 3371
 
2868 3372
 		$folders = $nameSpace =  array();
2869 3373
 		$nameSpaceTmp = $this->_getNameSpaces();
2870
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3374
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3375
+		{
2871 3376
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2872 3377
 		}
2873 3378
 		unset($nameSpaceTmp);
2874 3379
 
2875 3380
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2876 3381
 		// Get special use folders
2877
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3382
+		if (!isset(self::$specialUseFolders))
3383
+		{
3384
+			$this->getSpecialUseFolders ();
3385
+		}
3386
+		// Set self::$specialUseFolders
2878 3387
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2879
-		if ($_onlyTopLevel) // top level leaves
3388
+		if ($_onlyTopLevel)
3389
+		{
3390
+			// top level leaves
2880 3391
 		{
2881 3392
 			// Get top mailboxes of icServer
2882 3393
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3394
+		}
2883 3395
 			// Trigger examination of namespace to retrieve
2884 3396
 			// folders located in other and shared; needed only for some servers
2885
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3397
+			if (is_null(self::$mailConfig))
3398
+			{
3399
+				self::$mailConfig = Config::read('mail');
3400
+			}
2886 3401
 			if (self::$mailConfig['examineNamespace'])
2887 3402
 			{
2888 3403
 				$prefixes=array();
2889 3404
 				if (is_array($nameSpace))
2890 3405
 				{
2891
-					foreach($nameSpace as $k => $singleNameSpace) {
3406
+					foreach($nameSpace as $k => $singleNameSpace)
3407
+					{
2892 3408
 						$type = $singleNameSpace['type'];
2893 3409
 
2894
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3410
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3411
+						{
2895 3412
 							$prefixes[$type] = $singleNameSpace['prefix'];
2896 3413
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2897 3414
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2967,7 +3484,10 @@  discard block
 block discarded – undo
2967 3484
 							$nFolders [$path] = $folder;
2968 3485
 						}
2969 3486
 					}
2970
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3487
+					if (is_array($aFolders))
3488
+					{
3489
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3490
+					}
2971 3491
 					//ksort($aFolders);
2972 3492
 
2973 3493
 					// Sort none auto folders base on mailbox name
@@ -2977,12 +3497,17 @@  discard block
 block discarded – undo
2977 3497
 				}
2978 3498
 				else
2979 3499
 				{
2980
-					if (is_array($subFolders)) ksort($subFolders);
3500
+					if (is_array($subFolders))
3501
+					{
3502
+						ksort($subFolders);
3503
+					}
2981 3504
 				}
2982 3505
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2983 3506
 			}
2984 3507
 		}
2985
-		elseif ($_nodePath) // single node
3508
+		elseif ($_nodePath)
3509
+		{
3510
+			// single node
2986 3511
 		{
2987 3512
 			switch ($_search)
2988 3513
 			{
@@ -2990,6 +3515,7 @@  discard block
 block discarded – undo
2990 3515
 				case 0:
2991 3516
 				case 2:
2992 3517
 					$path = $_nodePath.''.$delimiter;
3518
+		}
2993 3519
 					break;
2994 3520
 				// Node itself
2995 3521
 				// shouldn't contain next level delimiter
@@ -3008,11 +3534,14 @@  discard block
 block discarded – undo
3008 3534
 
3009 3535
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
3010 3536
 		}
3011
-		elseif(!$_nodePath) // all
3537
+		elseif(!$_nodePath)
3538
+		{
3539
+			// all
3012 3540
 		{
3013 3541
 			if ($_subscribedOnly)
3014 3542
 			{
3015 3543
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3544
+		}
3016 3545
 			}
3017 3546
 			else
3018 3547
 			{
@@ -3024,7 +3553,10 @@  discard block
 block discarded – undo
3024 3553
 		{
3025 3554
 			// SORTING FOLDERS
3026 3555
 			//self::$debugTimes=true;
3027
-			if (self::$debugTimes) $starttime = microtime (true);
3556
+			if (self::$debugTimes)
3557
+			{
3558
+				$starttime = microtime (true);
3559
+			}
3028 3560
 			// Merge of all auto folders and specialusefolders
3029 3561
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
3030 3562
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -3034,73 +3566,103 @@  discard block
 block discarded – undo
3034 3566
 			$isGoogleMail=false;
3035 3567
 			foreach($autoFoldersTmp as $afk=>$aF)
3036 3568
 			{
3037
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3569
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3570
+				{
3571
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3572
+				}
3038 3573
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3039 3574
 			}
3040 3575
 			//error_log(array2string($mySpecialUseFolders));
3041
-			foreach ($tmpFolders as $k => $f) {
3576
+			foreach ($tmpFolders as $k => $f)
3577
+			{
3042 3578
 				$sorted=false;
3043
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3044
-					if (strtoupper($k)=='INBOX') {
3579
+				if (strtoupper(substr($k,0,5))=='INBOX')
3580
+				{
3581
+					if (strtoupper($k)=='INBOX')
3582
+					{
3045 3583
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3046 3584
 						$inboxFolderObject[$k]=$f;
3047 3585
 						unset($folders[$k]);
3048 3586
 						$sorted=true;
3049
-					} else {
3587
+					}
3588
+					else
3589
+					{
3050 3590
 						$isAutoFolder=false;
3051 3591
 						foreach($autoFoldersTmp as $afk=>$aF)
3052 3592
 						{
3053 3593
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3054 3594
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3055 3595
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3056
-								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
3057 3599
 							{
3058 3600
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3059 3601
 								$isAutoFolder=true;
3602
+							}
3060 3603
 								$autoFolderObjects[$k]=$f;
3061 3604
 								break;
3062 3605
 							}
3063 3606
 						}
3064
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3607
+						if ($isAutoFolder==false)
3608
+						{
3609
+							$inboxSubFolderObjects[$k]=$f;
3610
+						}
3065 3611
 						unset($folders[$k]);
3066 3612
 						$sorted=true;
3067 3613
 					}
3068
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3614
+				}
3615
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3616
+				{
3069 3617
 					$isGoogleMail=true;
3070
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3618
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3619
+					{
3071 3620
 						$googleMailFolderObject[$k]=$f;
3072 3621
 						unset($folders[$k]);
3073 3622
 						$sorted=true;
3074
-					} else {
3623
+					}
3624
+					else
3625
+					{
3075 3626
 						$isAutoFolder=false;
3076 3627
 						foreach($autoFoldersTmp as $afk=>$aF)
3077 3628
 						{
3078 3629
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3079 3630
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3080 3631
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3081
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3632
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3633
+							{
3634
+								// k is parent of an autofolder
3082 3635
 							{
3083 3636
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3084 3637
 								$isAutoFolder=true;
3638
+							}
3085 3639
 								$googleAutoFolderObjects[$k]=$f;
3086 3640
 								break;
3087 3641
 							}
3088 3642
 						}
3089
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3643
+						if ($isAutoFolder==false)
3644
+						{
3645
+							$googleSubFolderObjects[$k]=$f;
3646
+						}
3090 3647
 						unset($folders[$k]);
3091 3648
 						$sorted=true;
3092 3649
 					}
3093
-				} else {
3650
+				}
3651
+				else
3652
+				{
3094 3653
 					$isAutoFolder=false;
3095 3654
 					foreach($autoFoldersTmp as $afk=>$aF)
3096 3655
 					{
3097 3656
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3098 3657
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3099 3658
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3100
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3659
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3660
+						{
3661
+							// k is parent of an autofolder
3101 3662
 						{
3102 3663
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3103 3664
 							$isAutoFolder=true;
3665
+						}
3104 3666
 							$autoFolderObjects[$k]=$f;
3105 3667
 							unset($folders[$k]);
3106 3668
 							$sorted=true;
@@ -3116,7 +3678,8 @@  discard block
 block discarded – undo
3116 3678
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3117 3679
 						{
3118 3680
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3119
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3681
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3682
+							{
3120 3683
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3121 3684
 								$typeFolderObject[$type][$k]=$f;
3122 3685
 								unset($folders[$k]);
@@ -3143,9 +3706,12 @@  discard block
 block discarded – undo
3143 3706
 				}
3144 3707
 			}
3145 3708
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3146
-			if (!$isGoogleMail) {
3709
+			if (!$isGoogleMail)
3710
+			{
3147 3711
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3148
-			} else {
3712
+			}
3713
+			else
3714
+			{
3149 3715
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3150 3716
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3151 3717
 				unset($googleAutoFolderObjects);
@@ -3162,7 +3728,10 @@  discard block
 block discarded – undo
3162 3728
 				}
3163 3729
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3164 3730
 			}
3165
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3731
+			if (self::$debugTimes)
3732
+			{
3733
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3734
+			}
3166 3735
 			//self::$debugTimes=false;
3167 3736
 		}
3168 3737
 		// Get counter information and add them to each fetched folders array
@@ -3212,7 +3781,13 @@  discard block
 block discarded – undo
3212 3781
 		$rv = false;
3213 3782
 		foreach ($haystack as $k => $v)
3214 3783
 		{
3215
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3784
+			foreach($v as &$sv)
3785
+			{
3786
+if (trim($sv)==trim($needle))
3787
+			{
3788
+				return $k;
3789
+			}
3790
+			}
3216 3791
 		}
3217 3792
 		return $rv;
3218 3793
 	}
@@ -3239,7 +3814,10 @@  discard block
 block discarded – undo
3239 3814
 	 */
3240 3815
 	static function pathToFolderData ($_path, $_hDelimiter)
3241 3816
 	{
3242
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3817
+		if (!strpos($_path, self::DELIMITER))
3818
+		{
3819
+			$_path = self::DELIMITER.$_path;
3820
+		}
3243 3821
 		list(,$path) = explode(self::DELIMITER, $_path);
3244 3822
 		$path_chain = $parts = explode($_hDelimiter, $path);
3245 3823
 		$name = array_pop($parts);
@@ -3268,7 +3846,10 @@  discard block
 block discarded – undo
3268 3846
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3269 3847
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3270 3848
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3271
-		if ($pos1 == $pos2) return 0;
3849
+		if ($pos1 == $pos2)
3850
+		{
3851
+			return 0;
3852
+		}
3272 3853
 		return ($pos1 < $pos2) ? -1 : 1;
3273 3854
 	}
3274 3855
 
@@ -3299,7 +3880,10 @@  discard block
 block discarded – undo
3299 3880
 		// 0, 1 und -1
3300 3881
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3301 3882
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3302
-		if ($pos1 == $pos2) return 0;
3883
+		if ($pos1 == $pos2)
3884
+		{
3885
+			return 0;
3886
+		}
3303 3887
 		return ($pos1 < $pos2) ? -1 : 1;
3304 3888
 	}
3305 3889
 
@@ -3320,11 +3904,18 @@  discard block
 block discarded – undo
3320 3904
 		}
3321 3905
 		catch (\Exception $e)
3322 3906
 		{
3323
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3907
+			if (self::$debug)
3908
+			{
3909
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3910
+			}
3324 3911
 			return false;
3325 3912
 		}
3326
-		if(is_array($folderStatus)) {
3327
-			if ($_returnObject===false) return $folderStatus;
3913
+		if(is_array($folderStatus))
3914
+		{
3915
+			if ($_returnObject===false)
3916
+			{
3917
+				return $folderStatus;
3918
+			}
3328 3919
 			$status =  new \stdClass;
3329 3920
 			$status->messages   = $folderStatus['MESSAGES'];
3330 3921
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3351,7 +3942,8 @@  discard block
 block discarded – undo
3351 3942
 	{
3352 3943
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3353 3944
 		$maxreclevel=25;
3354
-		if ($reclevel > $maxreclevel) {
3945
+		if ($reclevel > $maxreclevel)
3946
+		{
3355 3947
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3356 3948
 			return array();
3357 3949
 		}
@@ -3365,7 +3957,8 @@  discard block
 block discarded – undo
3365 3957
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3366 3958
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3367 3959
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3368
-		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"]))) {
3960
+		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"])))
3961
+		{
3369 3962
 			// if there are children fetch them
3370 3963
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3371 3964
 
@@ -3373,7 +3966,8 @@  discard block
 block discarded – undo
3373 3966
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3374 3967
 			//_debug_array($buff);
3375 3968
 			$allMailboxes = array();
3376
-			foreach ($buff as $mbxname) {
3969
+			foreach ($buff as $mbxname)
3970
+			{
3377 3971
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3378 3972
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3379 3973
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3382,9 +3976,14 @@  discard block
 block discarded – undo
3382 3976
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3383 3977
 				}
3384 3978
 			}
3385
-			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'];
3979
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3980
+			{
3981
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3982
+			}
3386 3983
 			return $allMailboxes;
3387
-		} else {
3984
+		}
3985
+		else
3986
+		{
3388 3987
 			return array($_mailbox);
3389 3988
 		}
3390 3989
 	}
@@ -3408,14 +4007,21 @@  discard block
 block discarded – undo
3408 4007
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3409 4008
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3410 4009
 		);
3411
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
4010
+		if ($_type == 'Templates')
4011
+		{
4012
+			$_type = 'Template';
4013
+		}
4014
+		// for some reason self::$autofolders uses 'Templates'!
3412 4015
 		$created = false;
3413 4016
 		if (!isset($types[$_type]))
3414 4017
 		{
3415 4018
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3416 4019
 			return false;
3417 4020
 		}
3418
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
4021
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
4022
+		{
4023
+			self::$specialUseFolders = $this->getSpecialUseFolders();
4024
+		}
3419 4025
 
3420 4026
 		//highest precedence
3421 4027
 		try
@@ -3425,25 +4031,39 @@  discard block
 block discarded – undo
3425 4031
 		catch (\Exception $e)
3426 4032
 		{
3427 4033
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3428
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
4034
+			if ($_type != 'Outbox')
4035
+			{
4036
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
4037
+			}
3429 4038
 			$_folderName = false;
3430 4039
 		}
3431 4040
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3432
-		if ($_type == 'Archive') {
3433
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4041
+		if ($_type == 'Archive')
4042
+		{
4043
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4044
+			{
3434 4045
 				return false;
3435
-			} else {
4046
+			}
4047
+			else
4048
+			{
3436 4049
 				return $_folderName;
3437 4050
 			}
3438 4051
 
3439 4052
 		}
3440 4053
 		// does the folder exist??? (is configured/preset, but non-existent)
3441
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4054
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4055
+		{
3442 4056
 			try
3443 4057
 			{
3444 4058
 				$error = null;
3445
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3446
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4059
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
4060
+				{
4061
+					$created = true;
4062
+				}
4063
+				if ($error)
4064
+				{
4065
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4066
+				}
3447 4067
 			}
3448 4068
 			catch(Exception $e)
3449 4069
 			{
@@ -3452,9 +4072,16 @@  discard block
 block discarded – undo
3452 4072
 			}
3453 4073
 		}
3454 4074
 		// not sure yet if false is the correct behavior on none
3455
-		if ($_folderName =='none') return 'none' ; //false;
4075
+		if ($_folderName =='none')
4076
+		{
4077
+			return 'none' ;
4078
+		}
4079
+		//false;
3456 4080
 		//no (valid) folder found yet; try specialUseFolders
3457
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
4081
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
4082
+		{
4083
+			$_folderName = $f;
4084
+		}
3458 4085
 		//no specialUseFolder; try some Defaults
3459 4086
 		if (empty($_folderName) && isset($types[$_type]))
3460 4087
 		{
@@ -3480,7 +4107,10 @@  discard block
 block discarded – undo
3480 4107
 					$error = null;
3481 4108
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3482 4109
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3483
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4110
+					if ($error)
4111
+					{
4112
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4113
+					}
3484 4114
 				}
3485 4115
 				catch(Exception $e)
3486 4116
 				{
@@ -3583,25 +4213,35 @@  discard block
 block discarded – undo
3583 4213
 	function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3584 4214
 	{
3585 4215
 		$sentFolder = $this->getSentFolder($_checkexistance);
3586
-		if(empty($sentFolder)) {
4216
+		if(empty($sentFolder))
4217
+		{
3587 4218
 			return false;
3588 4219
 		}
3589 4220
 		// does the folder exist???
3590
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4221
+		if ($_checkexistance && !$this->folderExists($_folderName))
4222
+		{
3591 4223
 			return false;
3592 4224
 		}
3593 4225
 
3594 4226
 		if ($_exactMatch)
3595 4227
 		{
3596
-			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) {
4228
+			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder))
4229
+			{
3597 4230
 				return true;
3598
-			} else {
4231
+			}
4232
+			else
4233
+			{
3599 4234
 				return false;
3600 4235
 			}
3601
-		} else {
3602
-			if(false !== stripos($_folderName, $sentFolder)) {
4236
+		}
4237
+		else
4238
+		{
4239
+			if(false !== stripos($_folderName, $sentFolder))
4240
+			{
3603 4241
 				return true;
3604
-			} else {
4242
+			}
4243
+			else
4244
+			{
3605 4245
 				return false;
3606 4246
 			}
3607 4247
 		}
@@ -3616,23 +4256,33 @@  discard block
 block discarded – undo
3616 4256
 	 */
3617 4257
 	function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3618 4258
 	{
3619
-		if (stripos($_folderName, 'Outbox')===false) {
4259
+		if (stripos($_folderName, 'Outbox')===false)
4260
+		{
3620 4261
 			return false;
3621 4262
 		}
3622 4263
 		// does the folder exist???
3623
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4264
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4265
+		{
3624 4266
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3625 4267
 			if ($_exactMatch)
3626 4268
 			{
3627
-				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) {
4269
+				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder))
4270
+				{
3628 4271
 					return true;
3629
-				} else {
4272
+				}
4273
+				else
4274
+				{
3630 4275
 					return false;
3631 4276
 				}
3632
-			} else {
3633
-				if(false !== stripos($_folderName, $outboxFolder)) {
4277
+			}
4278
+			else
4279
+			{
4280
+				if(false !== stripos($_folderName, $outboxFolder))
4281
+				{
3634 4282
 					return true;
3635
-				} else {
4283
+				}
4284
+				else
4285
+				{
3636 4286
 					return false;
3637 4287
 				}
3638 4288
 			}
@@ -3650,25 +4300,38 @@  discard block
 block discarded – undo
3650 4300
 	function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3651 4301
 	{
3652 4302
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3653
-		if(empty($draftFolder)) {
4303
+		if(empty($draftFolder))
4304
+		{
3654 4305
 			return false;
3655 4306
 		}
3656 4307
 		// does the folder exist???
3657
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4308
+		if ($_checkexistance && !$this->folderExists($_folderName))
4309
+		{
3658 4310
 			return false;
3659 4311
 		}
3660
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
4312
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4313
+		{
4314
+			$_folderName = $_folderName->utf8;
4315
+		}
3661 4316
 		if ($_exactMatch)
3662 4317
 		{
3663
-			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) {
4318
+			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder))
4319
+			{
4320
+				return true;
4321
+			}
4322
+			else
4323
+			{
4324
+				return false;
4325
+			}
4326
+		}
4327
+		else
4328
+		{
4329
+			if(false !== stripos($_folderName, $draftFolder))
4330
+			{
3664 4331
 				return true;
3665
-			} else {
3666
-				return false;
3667 4332
 			}
3668
-		} else {
3669
-			if(false !== stripos($_folderName, $draftFolder)) {
3670
-				return true;
3671
-			} else {
4333
+			else
4334
+			{
3672 4335
 				return false;
3673 4336
 			}
3674 4337
 		}
@@ -3684,25 +4347,35 @@  discard block
 block discarded – undo
3684 4347
 	function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3685 4348
 	{
3686 4349
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3687
-		if(empty($trashFolder)) {
4350
+		if(empty($trashFolder))
4351
+		{
3688 4352
 			return false;
3689 4353
 		}
3690 4354
 		// does the folder exist???
3691
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4355
+		if ($_checkexistance && !$this->folderExists($_folderName))
4356
+		{
3692 4357
 			return false;
3693 4358
 		}
3694 4359
 
3695 4360
 		if ($_exactMatch)
3696 4361
 		{
3697
-			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) {
4362
+			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder))
4363
+			{
3698 4364
 				return true;
3699
-			} else {
4365
+			}
4366
+			else
4367
+			{
3700 4368
 				return false;
3701 4369
 			}
3702
-		} else {
3703
-			if(false !== stripos($_folderName, $trashFolder)) {
4370
+		}
4371
+		else
4372
+		{
4373
+			if(false !== stripos($_folderName, $trashFolder))
4374
+			{
3704 4375
 				return true;
3705
-			} else {
4376
+			}
4377
+			else
4378
+			{
3706 4379
 				return false;
3707 4380
 			}
3708 4381
 		}
@@ -3718,24 +4391,34 @@  discard block
 block discarded – undo
3718 4391
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3719 4392
 	{
3720 4393
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3721
-		if(empty($templateFolder)) {
4394
+		if(empty($templateFolder))
4395
+		{
3722 4396
 			return false;
3723 4397
 		}
3724 4398
 		// does the folder exist???
3725
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4399
+		if ($_checkexistance && !$this->folderExists($_folderName))
4400
+		{
3726 4401
 			return false;
3727 4402
 		}
3728 4403
 		if ($_exactMatch)
3729 4404
 		{
3730
-			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) {
4405
+			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder))
4406
+			{
3731 4407
 				return true;
3732
-			} else {
4408
+			}
4409
+			else
4410
+			{
3733 4411
 				return false;
3734 4412
 			}
3735
-		} else {
3736
-			if(false !== stripos($_folderName, $templateFolder)) {
4413
+		}
4414
+		else
4415
+		{
4416
+			if(false !== stripos($_folderName, $templateFolder))
4417
+			{
3737 4418
 				return true;
3738
-			} else {
4419
+			}
4420
+			else
4421
+			{
3739 4422
 				return false;
3740 4423
 			}
3741 4424
 		}
@@ -3754,15 +4437,27 @@  discard block
 block discarded – undo
3754 4437
 		if (empty($_folder))
3755 4438
 		{
3756 4439
 			// this error is more or less without significance, unless we force the check
3757
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4440
+			if ($_forceCheck===true)
4441
+			{
4442
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4443
+			}
3758 4444
 			return false;
3759 4445
 		}
3760 4446
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3761
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3762
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4447
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4448
+		{
4449
+			return true;
4450
+		}
4451
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4452
+		{
4453
+			$_folder =  $_folder->utf8;
4454
+		}
3763 4455
 		// reduce traffic within the Instance per User; Expire every 5 hours
3764 4456
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3765
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4457
+		if (is_null($folderInfo))
4458
+		{
4459
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4460
+		}
3766 4461
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3767 4462
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3768 4463
 		{
@@ -3780,7 +4475,8 @@  discard block
 block discarded – undo
3780 4475
 
3781 4476
 		// does the folder exist???
3782 4477
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3783
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4478
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4479
+		{
3784 4480
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3785 4481
 			//return false;
3786 4482
 			//try to connect
@@ -3821,9 +4517,12 @@  discard block
 block discarded – undo
3821 4517
 
3822 4518
 		$this->icServer->openMailbox($folderName);
3823 4519
 
3824
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4520
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4521
+		{
3825 4522
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3826
-		} else {
4523
+		}
4524
+		else
4525
+		{
3827 4526
 			$this->icServer->expunge($folderName);
3828 4527
 		}
3829 4528
 	}
@@ -3842,10 +4541,16 @@  discard block
 block discarded – undo
3842 4541
 	{
3843 4542
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3844 4543
 		$oldMailbox = '';
3845
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4544
+		if (is_null($_folder) || empty($_folder))
4545
+		{
4546
+			$_folder = $this->sessionData['mailbox'];
4547
+		}
3846 4548
 		if (empty($_messageUID))
3847 4549
 		{
3848
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4550
+			if (self::$debug)
4551
+			{
4552
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4553
+			}
3849 4554
 			return false;
3850 4555
 		}
3851 4556
 		elseif ($_messageUID==='all')
@@ -3855,32 +4560,48 @@  discard block
 block discarded – undo
3855 4560
 		else
3856 4561
 		{
3857 4562
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3858
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4563
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4564
+			{
4565
+				$_messageUID = (array)$_messageUID;
4566
+			}
3859 4567
 			$uidsToDelete->add($_messageUID);
3860 4568
 		}
3861 4569
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3862
-		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");
4570
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4571
+		{
4572
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4573
+		}
3863 4574
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3864 4575
 		$trashFolder    = $this->getTrashFolder();
3865 4576
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3866 4577
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3867 4578
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3868
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4579
+		   (strtolower($_folder) == strtolower($draftFolder)))
4580
+		{
3869 4581
 			$deleteOptions = "remove_immediately";
3870 4582
 		}
3871
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4583
+		if($this->icServer->getCurrentMailbox() != $_folder)
4584
+		{
3872 4585
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3873 4586
 			$this->icServer->openMailbox($_folder);
3874 4587
 		}
3875 4588
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3876 4589
 		$updateCache = false;
3877
-		switch($deleteOptions) {
4590
+		switch($deleteOptions)
4591
+		{
3878 4592
 			case "move_to_trash":
3879 4593
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3880 4594
 				$updateCache = true;
3881
-				if(!empty($trashFolder)) {
3882
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3883
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4595
+				if(!empty($trashFolder))
4596
+				{
4597
+					if (self::$debug)
4598
+					{
4599
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4600
+					}
4601
+					if (self::$debug)
4602
+					{
4603
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4604
+					}
3884 4605
 					// copy messages
3885 4606
 					try
3886 4607
 					{
@@ -3896,7 +4617,10 @@  discard block
 block discarded – undo
3896 4617
 			case "mark_as_deleted":
3897 4618
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3898 4619
 				// mark messages as deleted
3899
-				if (is_null($_messageUID)) $_messageUID='all';
4620
+				if (is_null($_messageUID))
4621
+				{
4622
+					$_messageUID='all';
4623
+				}
3900 4624
 				foreach((array)$_messageUID as $key =>$uid)
3901 4625
 				{
3902 4626
 					//flag messages, that are flagged for deletion as seen too
@@ -3904,7 +4628,10 @@  discard block
 block discarded – undo
3904 4628
 					$flags = $this->getFlags($uid);
3905 4629
 					$this->flagMessages('delete', $uid, $_folder);
3906 4630
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3907
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4631
+					if (strpos( array2string($flags),'Deleted')!==false)
4632
+					{
4633
+						$undelete[] = $uid;
4634
+					}
3908 4635
 					unset($flags);
3909 4636
 				}
3910 4637
 				foreach((array)$undelete as $key =>$uid)
@@ -3916,7 +4643,10 @@  discard block
 block discarded – undo
3916 4643
 			case "remove_immediately":
3917 4644
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3918 4645
 				$updateCache = true;
3919
-				if (is_null($_messageUID)) $_messageUID='all';
4646
+				if (is_null($_messageUID))
4647
+				{
4648
+					$_messageUID='all';
4649
+				}
3920 4650
 				if (is_object($_messageUID))
3921 4651
 				{
3922 4652
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3933,7 +4663,8 @@  discard block
 block discarded – undo
3933 4663
 				$this->icServer->expunge($_folder);
3934 4664
 				break;
3935 4665
 		}
3936
-		if($oldMailbox != '') {
4666
+		if($oldMailbox != '')
4667
+		{
3937 4668
 			$this->icServer->openMailbox($oldMailbox);
3938 4669
 		}
3939 4670
 
@@ -3947,11 +4678,15 @@  discard block
 block discarded – undo
3947 4678
 	 *
3948 4679
 	 * @return null/array flags
3949 4680
 	 */
3950
-	function getFlags ($_messageUID) {
4681
+	function getFlags ($_messageUID)
4682
+	{
3951 4683
 		try
3952 4684
 		{
3953 4685
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3954
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4686
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4687
+			{
4688
+				$_messageUID = (array)$_messageUID;
4689
+			}
3955 4690
 			$uidsToFetch->add($_messageUID);
3956 4691
 			$_folderName = $this->icServer->getCurrentMailbox();
3957 4692
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3959,8 +4694,10 @@  discard block
 block discarded – undo
3959 4694
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3960 4695
 				'ids' => $uidsToFetch,
3961 4696
 			));
3962
-			if (is_object($headersNew)) {
3963
-				foreach($headersNew->ids() as $id) {
4697
+			if (is_object($headersNew))
4698
+			{
4699
+				foreach($headersNew->ids() as $id)
4700
+				{
3964 4701
 					$_headerObject = $headersNew->get($id);
3965 4702
 					$flags = $_headerObject->getFlags();
3966 4703
 				}
@@ -3985,10 +4722,16 @@  discard block
 block discarded – undo
3985 4722
 	 */
3986 4723
 	function getNotifyFlags ($_messageUID, $flags=null)
3987 4724
 	{
3988
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4725
+		if (self::$debug)
4726
+		{
4727
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4728
+		}
3989 4729
 		try
3990 4730
 		{
3991
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4731
+			if($flags===null)
4732
+			{
4733
+				$flags =  $this->getFlags($_messageUID);
4734
+			}
3992 4735
 		}
3993 4736
 		catch (\Exception $e)
3994 4737
 		{
@@ -3996,10 +4739,14 @@  discard block
 block discarded – undo
3996 4739
 		}
3997 4740
 
3998 4741
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3999
-			return true;
4742
+		{
4743
+					return true;
4744
+		}
4000 4745
 
4001 4746
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
4002
-			return false;
4747
+		{
4748
+					return false;
4749
+		}
4003 4750
 
4004 4751
 		return null;
4005 4752
 	}
@@ -4020,7 +4767,10 @@  discard block
 block discarded – undo
4020 4767
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
4021 4768
 		if (empty($_messageUID))
4022 4769
 		{
4023
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4770
+			if (self::$debug)
4771
+			{
4772
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4773
+			}
4024 4774
 			return false;
4025 4775
 		}
4026 4776
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -4028,7 +4778,10 @@  discard block
 block discarded – undo
4028 4778
 		if (is_array($_messageUID)&& count($_messageUID)>50)
4029 4779
 		{
4030 4780
 			$count = $this->getMailBoxCounters($folder,true);
4031
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4781
+			if ($count->messages == count($_messageUID))
4782
+			{
4783
+				$_messageUID='all';
4784
+			}
4032 4785
 		}
4033 4786
 
4034 4787
 		if ($_messageUID==='all')
@@ -4037,7 +4790,10 @@  discard block
 block discarded – undo
4037 4790
 		}
4038 4791
 		else
4039 4792
 		{
4040
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4793
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4794
+			{
4795
+				$_messageUID = (array)$_messageUID;
4796
+			}
4041 4797
 			$messageUIDs = array_chunk($_messageUID,50,true);
4042 4798
 		}
4043 4799
 		try
@@ -4053,7 +4809,8 @@  discard block
 block discarded – undo
4053 4809
 					$uidsToModify = new Horde_Imap_Client_Ids();
4054 4810
 					$uidsToModify->add($uids);
4055 4811
 				}
4056
-				switch($_flag) {
4812
+				switch($_flag)
4813
+				{
4057 4814
 					case "delete":
4058 4815
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
4059 4816
 						break;
@@ -4139,7 +4896,10 @@  discard block
 block discarded – undo
4139 4896
 		{
4140 4897
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4141 4898
 		}
4142
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4899
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4900
+		{
4901
+			$_folder = $folder->utf8;
4902
+		}
4143 4903
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4144 4904
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4145 4905
 
@@ -4168,7 +4928,10 @@  discard block
 block discarded – undo
4168 4928
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4169 4929
 		if (empty($_messageUID))
4170 4930
 		{
4171
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4931
+			if (self::$debug)
4932
+			{
4933
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4934
+			}
4172 4935
 			return false;
4173 4936
 		}
4174 4937
 		elseif ($_messageUID==='all')
@@ -4180,7 +4943,10 @@  discard block
 block discarded – undo
4180 4943
 		{
4181 4944
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4182 4945
 			$uidsToMove = new Horde_Imap_Client_Ids();
4183
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4946
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4947
+			{
4948
+				$_messageUID = (array)$_messageUID;
4949
+			}
4184 4950
 			$uidsToMove->add($_messageUID);
4185 4951
 		}
4186 4952
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4202,12 +4968,14 @@  discard block
 block discarded – undo
4202 4968
 
4203 4969
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4204 4970
 
4205
-			if (is_object($headersNew)) {
4971
+			if (is_object($headersNew))
4972
+			{
4206 4973
 				$c=0;
4207 4974
 				$retUid = new Horde_Imap_Client_Ids();
4208 4975
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4209 4976
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4210
-				foreach($headersNew as &$_headerObject) {
4977
+				foreach($headersNew as &$_headerObject)
4978
+				{
4211 4979
 					$c++;
4212 4980
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4213 4981
 					$date = $_headerObject->getImapDate();
@@ -4291,7 +5059,11 @@  discard block
 block discarded – undo
4291 5059
 	{
4292 5060
 		try {
4293 5061
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4294
-			if ($convert2usertime) $date->setUser();	// convert to user-time
5062
+			if ($convert2usertime)
5063
+			{
5064
+				$date->setUser();
5065
+			}
5066
+			// convert to user-time
4295 5067
 			$date2return = $date->format($format);
4296 5068
 		}
4297 5069
 		catch(\Exception $e)
@@ -4325,9 +5097,15 @@  discard block
 block discarded – undo
4325 5097
 	static function htmlentities($_string, $_charset=false)
4326 5098
 	{
4327 5099
 		//setting the charset (if not given)
4328
-		if ($_charset===false) $_charset = self::$displayCharset;
5100
+		if ($_charset===false)
5101
+		{
5102
+			$_charset = self::$displayCharset;
5103
+		}
4329 5104
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4330
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
5105
+		if (empty($string) && !empty($_string))
5106
+		{
5107
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
5108
+		}
4331 5109
 		return $string;
4332 5110
 	}
4333 5111
 
@@ -4347,18 +5125,41 @@  discard block
 block discarded – undo
4347 5125
 		$_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>'),
4348 5126
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4349 5127
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4350
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4351
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
5128
+		if (stripos($_html,'style')!==false)
5129
+		{
5130
+			Mail\Html::replaceTagsCompletley($_html,'style');
5131
+		}
5132
+		// clean out empty or pagewide style definitions / left over tags
5133
+		if (stripos($_html,'head')!==false)
5134
+		{
5135
+			Mail\Html::replaceTagsCompletley($_html,'head');
5136
+		}
5137
+		// Strip out stuff in head
4352 5138
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4353 5139
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4354 5140
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4355 5141
 
4356
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
5142
+		if (get_magic_quotes_gpc() === 1)
5143
+		{
5144
+			$_html = stripslashes($_html);
5145
+		}
4357 5146
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4358
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4359
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4360
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4361
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5147
+		if (stripos($_html,'!doctype')!==false)
5148
+		{
5149
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
5150
+		}
5151
+		if (stripos($_html,'?xml:namespace')!==false)
5152
+		{
5153
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
5154
+		}
5155
+		if (stripos($_html,'?xml version')!==false)
5156
+		{
5157
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
5158
+		}
5159
+		if (strpos($_html,'!CURSOR')!==false)
5160
+		{
5161
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5162
+		}
4362 5163
 		// htmLawed filter only the 'body'
4363 5164
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4364 5165
 		//if ($matches[2])
@@ -4397,8 +5198,10 @@  discard block
 block discarded – undo
4397 5198
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4398 5199
 		$CharsetFound=false;
4399 5200
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4400
-		if(is_array($_mimePartObject->parameters)) {
4401
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5201
+		if(is_array($_mimePartObject->parameters))
5202
+		{
5203
+			if(isset($_mimePartObject->parameters['CHARSET']))
5204
+			{
4402 5205
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4403 5206
 				$CharsetFound=true;
4404 5207
 			}
@@ -4419,7 +5222,10 @@  discard block
 block discarded – undo
4419 5222
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4420 5223
 	{
4421 5224
 		// decode the part
4422
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5225
+		if (self::$debug)
5226
+		{
5227
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5228
+		}
4423 5229
 		switch (strtoupper($_encoding))
4424 5230
 		{
4425 5231
 			case 'BASE64':
@@ -4460,13 +5266,19 @@  discard block
 block discarded – undo
4460 5266
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4461 5267
 		// as attachment AND as abstracted ical information (we use our notification style here).
4462 5268
 		$partText = $partCalendar = $partHTML = null;
4463
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5269
+		if (self::$debug)
5270
+		{
5271
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5272
+		}
4464 5273
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4465 5274
 		$ignore_first_part = true;
4466 5275
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4467 5276
 		{
4468 5277
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4469
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5278
+			if (self::$debug)
5279
+			{
5280
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5281
+			}
4470 5282
 
4471 5283
 			if ($ignore_first_part)
4472 5284
 			{
@@ -4482,15 +5294,24 @@  discard block
 block discarded – undo
4482 5294
 					switch($mimePart->getSubType())
4483 5295
 					{
4484 5296
 						case 'plain':
4485
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5297
+							if ($mimePart->getBytes() > 0)
5298
+							{
5299
+								$partText = $mimePart;
5300
+							}
4486 5301
 							break;
4487 5302
 
4488 5303
 						case 'html':
4489
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5304
+							if ($mimePart->getBytes() > 0)
5305
+							{
5306
+								$partHTML = $mimePart;
5307
+							}
4490 5308
 							break;
4491 5309
 
4492 5310
 						case 'calendar':
4493
-							if ($mimePart->getBytes() > 0)  $partCalendar = $mimePart;
5311
+							if ($mimePart->getBytes() > 0)
5312
+							{
5313
+								$partCalendar = $mimePart;
5314
+							}
4494 5315
 							break;
4495 5316
 					}
4496 5317
 					break;
@@ -4503,7 +5324,10 @@  discard block
 block discarded – undo
4503 5324
 							if (count($mimePart->getParts()) > 1)
4504 5325
 							{
4505 5326
 								// in a multipart alternative we treat the multipart/related as html part
4506
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5327
+								if (self::$debug)
5328
+								{
5329
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5330
+								}
4507 5331
 								$partHTML = $mimePart;
4508 5332
 								break 3; // GET OUT OF LOOP, will be processed according to type
4509 5333
 							}
@@ -4585,9 +5409,15 @@  discard block
 block discarded – undo
4585 5409
 	 */
4586 5410
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array(), &$partCalendar=null)
4587 5411
 	{
4588
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5412
+		if (self::$debug)
5413
+		{
5414
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5415
+		}
4589 5416
 		$bodyPart = array();
4590
-		if (self::$debug) _debug_array($_structure);
5417
+		if (self::$debug)
5418
+		{
5419
+			_debug_array($_structure);
5420
+		}
4591 5421
 
4592 5422
 		$ignore_first_part = true;
4593 5423
 		//$skipParts = array();
@@ -4595,7 +5425,10 @@  discard block
 block discarded – undo
4595 5425
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4596 5426
 		{
4597 5427
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4598
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5428
+			if (self::$debug)
5429
+			{
5430
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5431
+			}
4599 5432
 			if ($ignore_first_part)
4600 5433
 			{
4601 5434
 				$ignore_first_part = false;
@@ -4613,7 +5446,10 @@  discard block
 block discarded – undo
4613 5446
 			switch($part->getPrimaryType())
4614 5447
 			{
4615 5448
 				case 'multipart':
4616
-					if ($part->getDisposition() == 'attachment') continue;
5449
+					if ($part->getDisposition() == 'attachment')
5450
+					{
5451
+						continue;
5452
+					}
4617 5453
 					switch($part->getSubType())
4618 5454
 					{
4619 5455
 						case 'alternative':
@@ -4678,7 +5514,9 @@  discard block
 block discarded – undo
4678 5514
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4679 5515
 					{
4680 5516
 						$skipParts[$mime_id.'.0'] = $mime_type;
4681
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5517
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5518
+						{
5519
+$skipParts[$sub_id] = $sub_type;}
4682 5520
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4683 5521
 						//break 2;
4684 5522
 					}
@@ -4721,7 +5559,10 @@  discard block
 block discarded – undo
4721 5559
 	 */
4722 5560
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4723 5561
 	{
4724
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5562
+		if (self::$debug)
5563
+		{
5564
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5565
+		}
4725 5566
 
4726 5567
 		if (empty($_folder))
4727 5568
 		{
@@ -4730,7 +5571,10 @@  discard block
 block discarded – undo
4730 5571
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4731 5572
 		// querying contents of body part
4732 5573
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4733
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5574
+		if (!(is_object($_uid) || is_array($_uid)))
5575
+		{
5576
+			$_uid = (array)$_uid;
5577
+		}
4734 5578
 		$uidsToFetch->add($_uid);
4735 5579
 
4736 5580
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4738,9 +5582,12 @@  discard block
 block discarded – undo
4738 5582
 			'peek' => $_preserveSeen,
4739 5583
 			'decode' => true,	// try decode on server, does NOT neccessary work
4740 5584
 		);
4741
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5585
+		if ($_tryDecodingServerside===false)
5586
+		{
5587
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4742 5588
 		{
4743 5589
 			$_tryDecodingServerside=false;
5590
+		}
4744 5591
 			$fetchParams = array(
4745 5592
 				'peek' => $_preserveSeen,
4746 5593
 			);
@@ -4782,7 +5629,10 @@  discard block
 block discarded – undo
4782 5629
 	{
4783 5630
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4784 5631
 		$bodyPart = array();
4785
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5632
+		if (self::$debug)
5633
+		{
5634
+			_debug_array(array($_structure,function_backtrace()));
5635
+		}
4786 5636
 
4787 5637
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4788 5638
 		{
@@ -4833,8 +5683,12 @@  discard block
 block discarded – undo
4833 5683
 	 */
4834 5684
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '', &$calendar_part=null)
4835 5685
 	{
4836
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4837
-		if($_htmlOptions != '') {
5686
+		if (self::$debug)
5687
+		{
5688
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5689
+		}
5690
+		if($_htmlOptions != '')
5691
+		{
4838 5692
 			$this->htmlOptions = $_htmlOptions;
4839 5693
 		}
4840 5694
 		if (empty($_folder))
@@ -4924,7 +5778,9 @@  discard block
 block discarded – undo
4924 5778
 						default:
4925 5779
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4926 5780
 					}
4927
-				} else {
5781
+				}
5782
+				else
5783
+				{
4928 5784
 					// what if the structure->disposition is attachment ,...
4929 5785
 				}
4930 5786
 				return self::normalizeBodyParts($bodyPart);
@@ -4935,13 +5791,18 @@  discard block
 block discarded – undo
4935 5791
 				{
4936 5792
 					case 'rfc822':
4937 5793
 						$newStructure = $_structure->getParts();
4938
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5794
+						if (self::$debug)
5795
+						{
5796
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4939 5797
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4940 5798
 				}
4941 5799
 				break;
4942 5800
 
4943 5801
 			default:
4944
-				if (self::$debug) _debug_array($_structure);
5802
+				if (self::$debug)
5803
+				{
5804
+					_debug_array($_structure);
5805
+				}
4945 5806
 				return array(
4946 5807
 					array(
4947 5808
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4965,9 +5826,12 @@  discard block
 block discarded – undo
4965 5826
 		{
4966 5827
 			foreach($_bodyParts as $singleBodyPart)
4967 5828
 			{
4968
-				if (!isset($singleBodyPart['body'])) {
5829
+				if (!isset($singleBodyPart['body']))
5830
+				{
4969 5831
 					$buff = self::normalizeBodyParts($singleBodyPart);
4970
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5832
+					foreach ((array)$buff as $val)
5833
+					{
5834
+$body2return[] = $val;}
4971 5835
 					continue;
4972 5836
 				}
4973 5837
 				$body2return[] = $singleBodyPart;
@@ -4993,13 +5857,20 @@  discard block
 block discarded – undo
4993 5857
 		$message='';
4994 5858
 		for($i=0; $i<count($bodyParts); $i++)
4995 5859
 		{
4996
-			if (!isset($bodyParts[$i]['body'])) {
5860
+			if (!isset($bodyParts[$i]['body']))
5861
+			{
4997 5862
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4998 5863
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4999 5864
 				continue;
5000 5865
 			}
5001
-			if (isset($bodyParts[$i]['error'])) continue;
5002
-			if (empty($bodyParts[$i]['body'])) continue;
5866
+			if (isset($bodyParts[$i]['error']))
5867
+			{
5868
+				continue;
5869
+			}
5870
+			if (empty($bodyParts[$i]['body']))
5871
+			{
5872
+				continue;
5873
+			}
5003 5874
 			// some characterreplacements, as they fail to translate
5004 5875
 			$sar = array(
5005 5876
 				'@(\x84|\x93|\x94)@',
@@ -5026,13 +5897,17 @@  discard block
 block discarded – undo
5026 5897
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
5027 5898
 			}
5028 5899
 
5029
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5900
+			if ($bodyParts[$i]['charSet']===false)
5901
+			{
5902
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5903
+			}
5030 5904
 			// add line breaks to $bodyParts
5031 5905
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
5032 5906
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
5033 5907
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
5034 5908
 			$mailClass->activeMimeType = 'text/plain';
5035
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5909
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5910
+			{
5036 5911
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
5037 5912
 				if (!$preserveHTML)
5038 5913
 				{
@@ -5078,15 +5953,28 @@  discard block
 block discarded – undo
5078 5953
 						// as we switched off HTMLaweds tidy functionality
5079 5954
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
5080 5955
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
5081
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5956
+						if ($hasOther && $preserveHTML)
5957
+						{
5958
+							$newBody = $matches[1]. $newBody. $matches[3];
5959
+						}
5082 5960
 						$alreadyHtmlLawed=true;
5083 5961
 					}
5084 5962
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
5085
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5963
+					if ($preserveHTML==false)
5964
+					{
5965
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5966
+					}
5086 5967
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
5087
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5968
+					if ($preserveHTML==false)
5969
+					{
5970
+						$newBody = nl2br($newBody);
5971
+					}
5972
+					// we need this, as htmLawed removes \r\n
5088 5973
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
5089
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5974
+					if ($preserveHTML==false)
5975
+					{
5976
+						$newBody = str_replace("<br />","\r\n",$newBody);
5977
+					}
5090 5978
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5091 5979
 				}
5092 5980
 				$message .= $newBody;
@@ -5123,12 +6011,12 @@  discard block
 block discarded – undo
5123 6011
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5124 6012
 				 )
5125 6013
 				)
5126
-			   )
5127
-			{
6014
+			   ) {
5128 6015
 				$s=explode(" ", $line);
5129 6016
 				$line = "";
5130 6017
 				$linecnt = 0;
5131
-				foreach ($s as &$v) {
6018
+				foreach ($s as &$v)
6019
+				{
5132 6020
 					$cnt = strlen($v);
5133 6021
 					// only break long words within the wordboundaries,
5134 6022
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -5138,14 +6026,20 @@  discard block
 block discarded – undo
5138 6026
 						$v=wordwrap($v, $allowedLength, $cut, true);
5139 6027
 					}
5140 6028
 					// the rest should be broken at the start of the new word that exceeds the limit
5141
-					if ($linecnt+$cnt > $allowedLength) {
6029
+					if ($linecnt+$cnt > $allowedLength)
6030
+					{
5142 6031
 						$v=$cut.$v;
5143 6032
 						#$linecnt = 0;
5144 6033
 						$linecnt =strlen($v)-strlen($cut);
5145
-					} else {
6034
+					}
6035
+					else
6036
+					{
5146 6037
 						$linecnt += $cnt;
5147 6038
 					}
5148
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
6039
+					if (strlen($v))
6040
+					{
6041
+						$line .= (strlen($line) ? " " : "").$v;
6042
+					}
5149 6043
 				}
5150 6044
 			}
5151 6045
 			$newStr .= $line . "\n";
@@ -5166,11 +6060,18 @@  discard block
 block discarded – undo
5166 6060
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5167 6061
 	{
5168 6062
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5169
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6063
+		if (empty($_folder))
6064
+		{
6065
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6066
+		}
5170 6067
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5171
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
6068
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
6069
+		{
5172 6070
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5173
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6071
+			if (!(is_object($_uid) || is_array($_uid)))
6072
+			{
6073
+				$_uid = (array)$_uid;
6074
+			}
5174 6075
 			$uidsToFetch->add($_uid);
5175 6076
 
5176 6077
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5180,8 +6081,10 @@  discard block
 block discarded – undo
5180 6081
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5181 6082
 				'ids' => $uidsToFetch,
5182 6083
 			));
5183
-			if (is_object($headersNew)) {
5184
-				foreach($headersNew as &$_headerObject) {
6084
+			if (is_object($headersNew))
6085
+			{
6086
+				foreach($headersNew as &$_headerObject)
6087
+				{
5185 6088
 					$env = $_headerObject->getEnvelope();
5186 6089
 					//_debug_array($envFields->singleFields());
5187 6090
 					$singleFields = $envFields->singleFields();
@@ -5198,7 +6101,10 @@  discard block
 block discarded – undo
5198 6101
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5199 6102
 								$envelope[$v]=$env->$v->addresses;
5200 6103
 								$address = array();
5201
-								if (!is_array($envelope[$v])) break;
6104
+								if (!is_array($envelope[$v]))
6105
+								{
6106
+									break;
6107
+								}
5202 6108
 								foreach ($envelope[$v] as $k => $ad)
5203 6109
 								{
5204 6110
 									if (stripos($ad,'@')===false)
@@ -5235,7 +6141,9 @@  discard block
 block discarded – undo
5235 6141
 				}
5236 6142
 			}
5237 6143
 			return $envelope;
5238
-		} else {
6144
+		}
6145
+		else
6146
+		{
5239 6147
 
5240 6148
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5241 6149
 
@@ -5246,19 +6154,43 @@  discard block
 block discarded – undo
5246 6154
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5247 6155
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5248 6156
 			);
5249
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5250
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5251
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5252
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5253
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5254
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
6157
+			if (isset($headers['IN-REPLY-TO']))
6158
+			{
6159
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
6160
+			}
6161
+			if (isset($headers['REFERENCES']))
6162
+			{
6163
+				$newData['REFERENCES'] = $headers['REFERENCES'];
6164
+			}
6165
+			if (isset($headers['THREAD-TOPIC']))
6166
+			{
6167
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
6168
+			}
6169
+			if (isset($headers['THREAD-INDEX']))
6170
+			{
6171
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6172
+			}
6173
+			if (isset($headers['LIST-ID']))
6174
+			{
6175
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6176
+			}
6177
+			if (isset($headers['SIZE']))
6178
+			{
6179
+				$newData['SIZE'] = $headers['SIZE'];
6180
+			}
5255 6181
 			//_debug_array($newData);
5256 6182
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5257
-			foreach($recepientList as $recepientType) {
5258
-				if(isset($headers[$recepientType])) {
5259
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6183
+			foreach($recepientList as $recepientType)
6184
+			{
6185
+				if(isset($headers[$recepientType]))
6186
+				{
6187
+					if ($decode)
6188
+					{
6189
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6190
+					}
5260 6191
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5261
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6192
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6193
+					{
5262 6194
 						$addressData = array(
5263 6195
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5264 6196
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5266,17 +6198,25 @@  discard block
 block discarded – undo
5266 6198
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5267 6199
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5268 6200
 						);
5269
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6201
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6202
+						{
5270 6203
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5271
-						} else {
6204
+						}
6205
+						else
6206
+						{
5272 6207
 							$addressData['RFC822_EMAIL'] = 'NIL';
5273 6208
 						}
5274 6209
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5275 6210
 					}
5276
-				} else {
5277
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6211
+				}
6212
+				else
6213
+				{
6214
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6215
+					{
5278 6216
 						$newData[$recepientType] = $newData['FROM'];
5279
-					} else {
6217
+					}
6218
+					else
6219
+					{
5280 6220
 						$newData[$recepientType] = array();
5281 6221
 					}
5282 6222
 				}
@@ -5299,9 +6239,15 @@  discard block
 block discarded – undo
5299 6239
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5300 6240
 	{
5301 6241
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5302
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6242
+		if (empty($_folder))
6243
+		{
6244
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6245
+		}
5303 6246
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5304
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6247
+		if (!(is_object($_uid) || is_array($_uid)))
6248
+		{
6249
+			$_uid = (array)$_uid;
6250
+		}
5305 6251
 		$uidsToFetch->add($_uid);
5306 6252
 
5307 6253
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5319,7 +6265,8 @@  discard block
 block discarded – undo
5319 6265
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5320 6266
 			'ids' => $uidsToFetch,
5321 6267
 		));
5322
-		if (is_object($headersNew)) {
6268
+		if (is_object($headersNew))
6269
+		{
5323 6270
 			foreach($headersNew as $_fetchObject)
5324 6271
 			{
5325 6272
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5341,11 +6288,17 @@  discard block
 block discarded – undo
5341 6288
 			}
5342 6289
 			if ($decode === 'object')
5343 6290
 			{
5344
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6291
+				if (is_object($headers))
6292
+				{
6293
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6294
+				}
5345 6295
 				return $headers;
5346 6296
 			}
5347 6297
 			$retValue = is_object($headers) ? $headers->toArray():array();
5348
-			if ($size) $retValue['size'] = $size;
6298
+			if ($size)
6299
+			{
6300
+				$retValue['size'] = $size;
6301
+			}
5349 6302
 		}
5350 6303
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5351 6304
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5377,10 +6330,16 @@  discard block
 block discarded – undo
5377 6330
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5378 6331
 	{
5379 6332
 		static $rawHeaders;
5380
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6333
+		if (empty($_folder))
6334
+		{
6335
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6336
+		}
5381 6337
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5382 6338
 
5383
-		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);
6339
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6340
+		{
6341
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6342
+		}
5384 6343
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5385 6344
 		{
5386 6345
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5388,7 +6347,10 @@  discard block
 block discarded – undo
5388 6347
 		}
5389 6348
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5390 6349
 		$uid = $_uid;
5391
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6350
+		if (!(is_object($_uid) || is_array($_uid)))
6351
+		{
6352
+			$uid = (array)$_uid;
6353
+		}
5392 6354
 		$uidsToFetch->add($uid);
5393 6355
 
5394 6356
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5404,8 +6366,10 @@  discard block
 block discarded – undo
5404 6366
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5405 6367
 			'ids' => $uidsToFetch,
5406 6368
 		));
5407
-		if (is_object($headersNew)) {
5408
-			foreach($headersNew as &$_headerObject) {
6369
+		if (is_object($headersNew))
6370
+		{
6371
+			foreach($headersNew as &$_headerObject)
6372
+			{
5409 6373
 				$retValue = $_headerObject->getHeaderText();
5410 6374
 				if ($_partID != '')
5411 6375
 				{
@@ -5433,22 +6397,33 @@  discard block
 block discarded – undo
5433 6397
 	static function &getStyles($_bodyParts)
5434 6398
 	{
5435 6399
 		$style = '';
5436
-		if (empty($_bodyParts)) return "";
5437
-		foreach((array)$_bodyParts as $singleBodyPart) {
5438
-			if (!isset($singleBodyPart['body'])) {
6400
+		if (empty($_bodyParts))
6401
+		{
6402
+			return "";
6403
+		}
6404
+		foreach((array)$_bodyParts as $singleBodyPart)
6405
+		{
6406
+			if (!isset($singleBodyPart['body']))
6407
+			{
5439 6408
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5440 6409
 				$style .= $singleBodyPart['body'];
5441 6410
 				continue;
5442 6411
 			}
5443 6412
 
5444
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6413
+			if ($singleBodyPart['charSet']===false)
6414
+			{
6415
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6416
+			}
5445 6417
 			$singleBodyPart['body'] = Translation::convert(
5446 6418
 				$singleBodyPart['body'],
5447 6419
 				strtolower($singleBodyPart['charSet'])
5448 6420
 			);
5449 6421
 			$ct = 0;
5450 6422
 			$newStyle=array();
5451
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6423
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6424
+			{
6425
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6426
+			}
5452 6427
 			if ($ct>0)
5453 6428
 			{
5454 6429
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5480,7 +6455,11 @@  discard block
 block discarded – undo
5480 6455
 		// CSS Security
5481 6456
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5482 6457
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5483
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6458
+		if (stripos($css,'script')!==false)
6459
+		{
6460
+			Mail\Html::replaceTagsCompletley($css,'script');
6461
+		}
6462
+		// Strip out script that may be included
5484 6463
 		// 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
5485 6464
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5486 6465
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5502,8 +6481,14 @@  discard block
 block discarded – undo
5502 6481
 	{
5503 6482
 		//TODO: caching einbauen static!
5504 6483
 		static $rawBody;
5505
-		if (is_null($rawBody)) $rawBody = array();
5506
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6484
+		if (is_null($rawBody))
6485
+		{
6486
+			$rawBody = array();
6487
+		}
6488
+		if (empty($_folder))
6489
+		{
6490
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6491
+		}
5507 6492
 		if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5508 6493
 		{
5509 6494
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5512,7 +6497,10 @@  discard block
 block discarded – undo
5512 6497
 
5513 6498
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5514 6499
 		$uid = $_uid;
5515
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6500
+		if (!(is_object($_uid) || is_array($_uid)))
6501
+		{
6502
+			$uid = (array)$_uid;
6503
+		}
5516 6504
 		$uidsToFetch->add($uid);
5517 6505
 
5518 6506
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5525,8 +6513,10 @@  discard block
 block discarded – undo
5525 6513
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5526 6514
 			'ids' => $uidsToFetch,
5527 6515
 		));
5528
-		if (is_object($headersNew)) {
5529
-			foreach($headersNew as &$_headerObject) {
6516
+		if (is_object($headersNew))
6517
+		{
6518
+			foreach($headersNew as &$_headerObject)
6519
+			{
5530 6520
 				$body = $_headerObject->getFullMsg($_stream);
5531 6521
 				if ($_partID != '')
5532 6522
 				{
@@ -5562,14 +6552,20 @@  discard block
 block discarded – undo
5562 6552
 	 */
5563 6553
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5564 6554
 	{
5565
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6555
+		if (self::$debug)
6556
+		{
6557
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6558
+		}
5566 6559
 
5567 6560
 		if (empty($_folder))
5568 6561
 		{
5569 6562
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5570 6563
 		}
5571 6564
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5572
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6565
+		if (!(is_object($_uid) || is_array($_uid)))
6566
+		{
6567
+			$_uid = (array)$_uid;
6568
+		}
5573 6569
 		$uidsToFetch->add($_uid);
5574 6570
 		try
5575 6571
 		{
@@ -5578,7 +6574,10 @@  discard block
 block discarded – undo
5578 6574
 	//		$fquery->envelope();
5579 6575
 	//		$fquery->size();
5580 6576
 			$_fquery->structure();
5581
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6577
+			if ($_partID)
6578
+			{
6579
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6580
+			}
5582 6581
 
5583 6582
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5584 6583
 				'ids' => $uidsToFetch,
@@ -5609,16 +6608,28 @@  discard block
 block discarded – undo
5609 6608
 	 */
5610 6609
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5611 6610
 	{
5612
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5613
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6611
+		if (self::$debug)
6612
+		{
6613
+			error_log( __METHOD__.":$_uid, $_partID");
6614
+		}
6615
+		if (empty($_folder))
6616
+		{
6617
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6618
+		}
5614 6619
 		$attachments = array();
5615 6620
 		if (!isset($_structure))
5616 6621
 		{
5617 6622
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5618 6623
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5619 6624
 		}
5620
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5621
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6625
+		if (!$_structure || !$_structure->contentTypeMap())
6626
+		{
6627
+			return array();
6628
+		}
6629
+		if (!empty($_partID))
6630
+		{
6631
+			$_structure = $_structure->getPart($_partID);
6632
+		}
5622 6633
 		$skipParts = array();
5623 6634
 		$tnefParts = array();
5624 6635
 		$skip = 0;
@@ -5647,7 +6658,13 @@  discard block
 block discarded – undo
5647 6658
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5648 6659
 			{
5649 6660
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5650
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6661
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6662
+				{
6663
+if ($sub_id != $mime_id)
6664
+				{
6665
+					$skipParts[$sub_id] = $sub_type;
6666
+				}
6667
+				}
5651 6668
 			}
5652 6669
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5653 6670
 			{
@@ -5658,7 +6675,10 @@  discard block
 block discarded – undo
5658 6675
 				$partDisposition='attachment';
5659 6676
 			}
5660 6677
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5661
-			if (array_key_exists($mime_id,$skipParts)) continue;
6678
+			if (array_key_exists($mime_id,$skipParts))
6679
+			{
6680
+				continue;
6681
+			}
5662 6682
 
5663 6683
 			if ($partDisposition == 'attachment' ||
5664 6684
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5669,23 +6689,41 @@  discard block
 block discarded – undo
5669 6689
 			{
5670 6690
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5671 6691
 				// we attempt to fetch "ourselves"
5672
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6692
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6693
+				{
6694
+					continue;
6695
+				}
5673 6696
 				$attachment = $part->getAllDispositionParameters();
5674 6697
 				$attachment['disposition'] = $part->getDisposition();
5675 6698
 				$attachment['mimeType'] = $mime_type;
5676 6699
 				$attachment['uid'] = $_uid;
5677 6700
 				$attachment['partID'] = $mime_id;
5678
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6701
+				if (!isset($attachment['name'])||empty($attachment['name']))
6702
+				{
6703
+					$attachment['name'] = $part->getName();
6704
+				}
5679 6705
 				if ($fetchTextCalendar)
5680 6706
 				{
5681 6707
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5682 6708
 					$method = $part->getContentTypeParameter('method');
5683
-					if ($method) $attachment['method'] = $method;
5684
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6709
+					if ($method)
6710
+					{
6711
+						$attachment['method'] = $method;
6712
+					}
6713
+					if (!isset($attachment['name']))
6714
+					{
6715
+						$attachment['name'] = 'event.ics';
6716
+					}
5685 6717
 				}
5686 6718
 				$attachment['size'] = $part->getBytes();
5687
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5688
-				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);
6719
+				if (($cid = $part->getContentId()))
6720
+				{
6721
+					$attachment['cid'] = $cid;
6722
+				}
6723
+				if (empty($attachment['name']))
6724
+				{
6725
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6726
+				}
5689 6727
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5690 6728
 				//typical winmail.dat attachment is
5691 6729
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5721,14 +6759,26 @@  discard block
 block discarded – undo
5721 6759
 						$attachment['uid'] = $tnp['uid'];
5722 6760
 						$attachment['partID'] = $tnp['partID'];
5723 6761
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5724
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6762
+						if (!isset($attachment['name'])||empty($attachment['name']))
6763
+						{
6764
+							$attachment['name'] = $part->getName();
6765
+						}
5725 6766
 						$attachment['size'] = $part->getBytes();
5726
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5727
-						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']);
6767
+						if (($cid = $part->getContentId()))
6768
+						{
6769
+							$attachment['cid'] = $cid;
6770
+						}
6771
+						if (empty($attachment['name']))
6772
+						{
6773
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6774
+						}
5728 6775
 						$attachments[] = $attachment;
5729 6776
 					}
5730 6777
 				}
5731
-				if ($tnefResolved===false) $attachments[]=$tnp;
6778
+				if ($tnefResolved===false)
6779
+				{
6780
+					$attachments[]=$tnp;
6781
+				}
5732 6782
 			}
5733 6783
 		}
5734 6784
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5832,8 +6882,14 @@  discard block
 block discarded – undo
5832 6882
 
5833 6883
 				$attachment = $part->getAllDispositionParameters();
5834 6884
 				$attachment['mimeType'] = $part->getType();
5835
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5836
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6885
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6886
+				{
6887
+					$attachment['filename'] = $part->getName();
6888
+				}
6889
+				if (($cid = $part->getContentId()))
6890
+				{
6891
+					$attachment['cid'] = $cid;
6892
+				}
5837 6893
 				if (empty($attachment['filename']))
5838 6894
 				{
5839 6895
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5845,7 +6901,10 @@  discard block
 block discarded – undo
5845 6901
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5846 6902
 			}
5847 6903
 		}
5848
-		if (!is_array($attachments)) return false;
6904
+		if (!is_array($attachments))
6905
+		{
6906
+			return false;
6907
+		}
5849 6908
 		return $attachments;
5850 6909
 	}
5851 6910
 
@@ -5864,10 +6923,16 @@  discard block
 block discarded – undo
5864 6923
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5865 6924
 	{
5866 6925
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5867
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6926
+		if (!isset($_folder))
6927
+		{
6928
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6929
+		}
5868 6930
 
5869 6931
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5870
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6932
+		if (!(is_object($_uid) || is_array($_uid)))
6933
+		{
6934
+			$_uid = (array)$_uid;
6935
+		}
5871 6936
 		$uidsToFetch->add($_uid);
5872 6937
 
5873 6938
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5876,8 +6941,10 @@  discard block
 block discarded – undo
5876 6941
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5877 6942
 			'ids' => $uidsToFetch,
5878 6943
 		));
5879
-		if (is_object($headersNew)) {
5880
-			foreach($headersNew as $id=>$_headerObject) {
6944
+		if (is_object($headersNew))
6945
+		{
6946
+			foreach($headersNew as $id=>$_headerObject)
6947
+			{
5881 6948
 				$body = $_headerObject->getFullMsg();
5882 6949
 				if ($_partID != '')
5883 6950
 				{
@@ -5891,7 +6958,10 @@  discard block
 block discarded – undo
5891 6958
 					}
5892 6959
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5893 6960
 					// itself is only triggered to fetch attachments
5894
-					if (empty($partDisposition)) $partDisposition='attachment';
6961
+					if (empty($partDisposition))
6962
+					{
6963
+						$partDisposition='attachment';
6964
+					}
5895 6965
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5896 6966
 					{
5897 6967
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5900,13 +6970,19 @@  discard block
 block discarded – undo
5900 6970
 						$charset = $part->getContentTypeParameter('charset');
5901 6971
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5902 6972
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5903
-						if ($_returnPart) return $part;
6973
+						if ($_returnPart)
6974
+						{
6975
+							return $part;
6976
+						}
5904 6977
 					}
5905 6978
 				}
5906 6979
 			}
5907 6980
 		}
5908 6981
 		$ext = MimeMagic::mime2ext($structure_mime);
5909
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6982
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6983
+		{
6984
+			$filename = trim($filename).'.'.$ext;
6985
+		}
5910 6986
 		if (!$part)
5911 6987
 		{
5912 6988
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5922,7 +6998,10 @@  discard block
 block discarded – undo
5922 6998
 		);
5923 6999
 
5924 7000
 		// try guessing the mimetype, if we get the application/octet-stream
5925
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
7001
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
7002
+		{
7003
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
7004
+		}
5926 7005
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5927 7006
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5928 7007
 		{
@@ -5945,9 +7024,18 @@  discard block
 block discarded – undo
5945 7024
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5946 7025
 					{
5947 7026
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5948
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5949
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5950
-						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']);
7027
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
7028
+						{
7029
+							$attachment['filename'] = $part->getName();
7030
+						}
7031
+						if (($cid = $part->getContentId()))
7032
+						{
7033
+							$attachment['cid'] = $cid;
7034
+						}
7035
+						if (empty($attachment['filename']))
7036
+						{
7037
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
7038
+						}
5951 7039
 						$wmattach = $attachment;
5952 7040
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5953 7041
 
@@ -5957,7 +7045,10 @@  discard block
 block discarded – undo
5957 7045
 			if ($tnefResolved)
5958 7046
 			{
5959 7047
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5960
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
7048
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
7049
+				{
7050
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
7051
+				}
5961 7052
 				$attachmentData = array(
5962 7053
 					'type'       => $wmattach['mimeType'],
5963 7054
 					'filename'   => $wmattach['filename'],
@@ -5987,7 +7078,10 @@  discard block
 block discarded – undo
5987 7078
 		static $uid=null, $part=null, $structure=null;
5988 7079
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5989 7080
 
5990
-		if(empty($_cid)) return false;
7081
+		if(empty($_cid))
7082
+		{
7083
+			return false;
7084
+		}
5991 7085
 
5992 7086
 		if ($_uid != $uid || $_part != $part)
5993 7087
 		{
@@ -6012,13 +7106,19 @@  discard block
 block discarded – undo
6012 7106
 					$attachment = $part;
6013 7107
 				}
6014 7108
 				// everything else we only consider after we checked all
6015
-				if (!isset($attachment)) $attachment = $part;
7109
+				if (!isset($attachment))
7110
+				{
7111
+					$attachment = $part;
7112
+				}
6016 7113
 				// do we want content fetched, can be done later, if not needed
6017 7114
 				if (isset($_stream))
6018 7115
 				{
6019 7116
 					$this->fetchPartContents($_uid, $attachment, $_stream);
6020 7117
 				}
6021
-				if (isset($attachment)) break;
7118
+				if (isset($attachment))
7119
+				{
7120
+					break;
7121
+				}
6022 7122
 			}
6023 7123
 		}
6024 7124
 		// set name as filename, if not set
@@ -6049,10 +7149,17 @@  discard block
 block discarded – undo
6049 7149
 	 */
6050 7150
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
6051 7151
 	{
6052
-		if (is_null($part)) return null;//new Horde_Mime_Part;
7152
+		if (is_null($part))
7153
+		{
7154
+			return null;
7155
+		}
7156
+		//new Horde_Mime_Part;
6053 7157
 		$encoding = null;
6054 7158
 		$fetchAsBinary = true;
6055
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
7159
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
7160
+		{
7161
+			$fetchAsBinary = false;
7162
+		}
6056 7163
 		// we need to set content on structure to decode transfer encoding
6057 7164
 		$part->setContents(
6058 7165
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -6089,7 +7196,10 @@  discard block
 block discarded – undo
6089 7196
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
6090 7197
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
6091 7198
 		// for flags at all)
6092
-		if (empty($_flags)) $_flags = '\\Recent';
7199
+		if (empty($_flags))
7200
+		{
7201
+			$_flags = '\\Recent';
7202
+		}
6093 7203
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
6094 7204
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
6095 7205
 		try
@@ -6106,18 +7216,27 @@  discard block
 block discarded – undo
6106 7216
 		}
6107 7217
 		catch (\Exception $e)
6108 7218
 		{
6109
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7219
+			if (self::$debug)
7220
+			{
7221
+				error_log("Could not append Message: ".$e->getMessage());
7222
+			}
6110 7223
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
6111 7224
 			//return false;
6112 7225
 		}
6113 7226
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
6114 7227
 		//$messageid = true; // for debug reasons only
6115
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7228
+		if ($messageid === true || empty($messageid))
7229
+		{
7230
+			// try to figure out the message uid
6116 7231
 		{
6117 7232
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7233
+		}
6118 7234
 			if ($list)
6119 7235
 			{
6120
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7236
+				if (self::$debug)
7237
+				{
7238
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7239
+				}
6121 7240
 				$messageid = $list['header'][0]['uid'];
6122 7241
 			}
6123 7242
 		}
@@ -6158,7 +7277,10 @@  discard block
 block discarded – undo
6158 7277
 	{
6159 7278
 			//echo __METHOD__." called for $uid,$partid <br>";
6160 7279
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6161
-			if (empty($headers)) return false;
7280
+			if (empty($headers))
7281
+			{
7282
+				return false;
7283
+			}
6162 7284
 			// dont force retrieval of the textpart, let mailClass preferences decide
6163 7285
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6164 7286
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6176,15 +7298,30 @@  discard block
 block discarded – undo
6176 7298
 			//error_log(array2string($bodyParts));
6177 7299
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6178 7300
 
6179
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6180
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6181
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6182
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7301
+			if ($mailClass->isSentFolder($mailbox))
7302
+			{
7303
+				$mailaddress = $headers['TO'];
7304
+			}
7305
+			elseif (isset($headers['FROM']))
7306
+			{
7307
+				$mailaddress = $headers['FROM'];
7308
+			}
7309
+			elseif (isset($headers['SENDER']))
7310
+			{
7311
+				$mailaddress = $headers['SENDER'];
7312
+			}
7313
+			if (isset($headers['CC']))
7314
+			{
7315
+				$mailaddress .= ','.$headers['CC'];
7316
+			}
6183 7317
 			//_debug_array(array($headers,$mailaddress));
6184 7318
 			$subject = $headers['SUBJECT'];
6185 7319
 
6186 7320
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6187
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7321
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7322
+			{
7323
+				$message = '<pre>'.$message.'</pre>';
7324
+			}
6188 7325
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6189 7326
 			$message = $headdata.$message;
6190 7327
 			//echo __METHOD__.'<br>';
@@ -6235,7 +7372,8 @@  discard block
 block discarded – undo
6235 7372
 							$attachments[$num]['attachment'] = $c->getContents();
6236 7373
 						}
6237 7374
 						// no attempt to convert, if we dont know about the charset
6238
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7375
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7376
+						{
6239 7377
 							// we do not try guessing the charset, if it is not set
6240 7378
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6241 7379
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6256,7 +7394,10 @@  discard block
 block discarded – undo
6256 7394
 						unset($attachments[$num]['attachment']);
6257 7395
 					}
6258 7396
 				}
6259
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7397
+				if (is_array($attachedMessages))
7398
+				{
7399
+					$attachments = array_merge($attachments,$attachedMessages);
7400
+				}
6260 7401
 			}
6261 7402
 			return array(
6262 7403
 					'mailaddress'=>$mailaddress,
@@ -6278,10 +7419,17 @@  discard block
 block discarded – undo
6278 7419
 	{
6279 7420
 		$c = 0;
6280 7421
 		// use the standardIdentity
6281
-		foreach($_identities as $key => $acc) {
6282
-			if ($c==0) $identity = $acc;
7422
+		foreach($_identities as $key => $acc)
7423
+		{
7424
+			if ($c==0)
7425
+			{
7426
+				$identity = $acc;
7427
+			}
6283 7428
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6284
-			if ($key==$_profile_id) $identity = $acc;
7429
+			if ($key==$_profile_id)
7430
+			{
7431
+				$identity = $acc;
7432
+			}
6285 7433
 			$c++;
6286 7434
 		}
6287 7435
 		return $identity;
@@ -6297,20 +7445,53 @@  discard block
 block discarded – undo
6297 7445
 	{
6298 7446
 		$headdata = null;
6299 7447
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6300
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6301
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6302
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6303
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6304
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6305
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6306
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6307
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6308
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7448
+		if ($header['SUBJECT'])
7449
+		{
7450
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7451
+		}
7452
+		if ($header['FROM'])
7453
+		{
7454
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7455
+		}
7456
+		if ($header['SENDER'])
7457
+		{
7458
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7459
+		}
7460
+		if ($header['TO'])
7461
+		{
7462
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7463
+		}
7464
+		if ($header['CC'])
7465
+		{
7466
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7467
+		}
7468
+		if ($header['BCC'])
7469
+		{
7470
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7471
+		}
7472
+		if ($header['DATE'])
7473
+		{
7474
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7475
+		}
7476
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7477
+		{
7478
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7479
+		}
7480
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7481
+		{
7482
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7483
+		}
6309 7484
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6310 7485
 		if (!empty($headdata))
6311 7486
 		{
6312
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6313
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7487
+			if (!empty($headline) && $headline != 'SUPPRESS')
7488
+			{
7489
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7490
+			}
7491
+			if (empty($headline))
7492
+			{
7493
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7494
+			}
6314 7495
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6315 7496
 		}
6316 7497
 		else
@@ -6344,12 +7525,15 @@  discard block
 block discarded – undo
6344 7525
 		$returnAddr ='';
6345 7526
 		if (is_array($rfcAddressArray))
6346 7527
 		{
6347
-			foreach((array)$rfcAddressArray as $addressData) {
7528
+			foreach((array)$rfcAddressArray as $addressData)
7529
+			{
6348 7530
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6349
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7531
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7532
+				{
6350 7533
 					continue;
6351 7534
 				}
6352
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7535
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7536
+				{
6353 7537
 					continue;
6354 7538
 				}
6355 7539
 				if ($addressData['RFC822_EMAIL'])
@@ -6363,7 +7547,10 @@  discard block
 block discarded – undo
6363 7547
 				}
6364 7548
 				$addressObject = $addressObjectA[0];
6365 7549
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6366
-				if (!$addressObject->valid) continue;
7550
+				if (!$addressObject->valid)
7551
+				{
7552
+					continue;
7553
+				}
6367 7554
 				//$mb =(string)$addressObject->mailbox;
6368 7555
 				//$h = (string)$addressObject->host;
6369 7556
 				//$p = (string)$addressObject->personal;
@@ -6380,7 +7567,10 @@  discard block
 block discarded – undo
6380 7567
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6381 7568
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6382 7569
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6383
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7570
+			if (is_string($rfcAddressArray))
7571
+			{
7572
+				return $rfcAddressArray;
7573
+			}
6384 7574
 		}
6385 7575
 		return $returnAddr;
6386 7576
 	}
@@ -6397,10 +7587,19 @@  discard block
 block discarded – undo
6397 7587
 	{
6398 7588
 		$mergeobj = new Contacts\Merge();
6399 7589
 
6400
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7590
+		if (empty($mimetype))
7591
+		{
7592
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7593
+		}
6401 7594
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6402
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6403
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7595
+		if (empty($rv) && !empty($content) && !empty($err))
7596
+		{
7597
+			$rv = $content;
7598
+		}
7599
+		if (!empty($err) && !empty($content) && !empty($ids))
7600
+		{
7601
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7602
+		}
6404 7603
 		return $rv;
6405 7604
 	}
6406 7605
 
@@ -6437,13 +7636,15 @@  discard block
 block discarded – undo
6437 7636
 			settype($bytes, 'integer');
6438 7637
 			$bytes /= 10;
6439 7638
 		}
6440
-		else
6441
-			settype($bytes, 'integer');
7639
+		else {
7640
+					settype($bytes, 'integer');
7641
+		}
6442 7642
 
6443 7643
 		return $bytes . ' ' . $type ;
6444 7644
 	}
6445 7645
 
6446
-	static function detect_qp(&$sting) {
7646
+	static function detect_qp(&$sting)
7647
+	{
6447 7648
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6448 7649
 		return preg_match("$needle",$string);
6449 7650
 	}
@@ -6460,9 +7661,15 @@  discard block
 block discarded – undo
6460 7661
 	 */
6461 7662
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6462 7663
 	{
6463
-		if (is_null($_endtime)) $_endtime = microtime(true);
7664
+		if (is_null($_endtime))
7665
+		{
7666
+			$_endtime = microtime(true);
7667
+		}
6464 7668
 		$usagetime = microtime(true) - $_starttime;
6465
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7669
+		if (self::$debugTimes)
7670
+		{
7671
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7672
+		}
6466 7673
 	}
6467 7674
 
6468 7675
 	/**
@@ -6477,7 +7684,10 @@  discard block
 block discarded – undo
6477 7684
 	 */
6478 7685
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6479 7686
 	{
6480
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7687
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7688
+		{
7689
+			return $_formData['file'];
7690
+		}
6481 7691
 
6482 7692
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6483 7693
 		$importfailed = $tmpFileName = false;
@@ -6526,8 +7736,15 @@  discard block
 block discarded – undo
6526 7736
 			{
6527 7737
 				$buff = explode('.',$_formData['name']);
6528 7738
 				$suffix = '';
6529
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6530
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7739
+				if (is_array($buff))
7740
+				{
7741
+					$suffix = array_pop($buff);
7742
+				}
7743
+				// take the last extension to check with ext2mime
7744
+				if (!empty($suffix))
7745
+				{
7746
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7747
+				}
6531 7748
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6532 7749
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6533 7750
 				{
@@ -6575,7 +7792,9 @@  discard block
 block discarded – undo
6575 7792
 			{
6576 7793
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6577 7794
 			}
6578
-		} else {
7795
+		}
7796
+		else
7797
+		{
6579 7798
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6580 7799
 			$importfailed = true;
6581 7800
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6621,21 +7840,32 @@  discard block
 block discarded – undo
6621 7840
 				if (substr($url, 0, 5) !== 'data:')
6622 7841
 				{
6623 7842
 					$filename = basename($url);
6624
-					if (($directory = dirname($url)) == '.') $directory = '';
7843
+					if (($directory = dirname($url)) == '.')
7844
+					{
7845
+						$directory = '';
7846
+					}
6625 7847
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6626 7848
 					$mimeType  = MimeMagic::ext2mime($ext);
6627
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7849
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7850
+					{
7851
+$directory .= '/'; }
6628 7852
 					$myUrl = $directory.$filename;
6629
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7853
+					if ($myUrl[0]=='/')
7854
+					{
7855
+						// local path -> we only allow path's that are available via http/https (or vfs)
6630 7856
 					{
6631 7857
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6632 7858
 					}
7859
+					}
6633 7860
 					// use vfs instead of url containing webdav.php
6634 7861
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6635 7862
 					// webdav.php urls as vfs
6636
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7863
+					if (strpos($myUrl,'/webdav.php') !== false)
7864
+					{
7865
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6637 7866
 					{
6638 7867
 						Vfs::load_wrapper('vfs');
7868
+					}
6639 7869
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6640 7870
 						$basedir = 'vfs://default';
6641 7871
 						$needTempFile = false;
@@ -6664,8 +7894,13 @@  discard block
 block discarded – undo
6664 7894
 						}
6665 7895
 					}
6666 7896
 
6667
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6668
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7897
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7898
+					{
7899
+$basedir .= '/'; }
7900
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7901
+					{
7902
+						$data = file_get_contents($basedir.urldecode($myUrl));
7903
+					}
6669 7904
 				}
6670 7905
 				if (substr($url,0,strlen('data:'))=='data:')
6671 7906
 				{
@@ -6773,7 +8008,10 @@  discard block
 block discarded – undo
6773 8008
 				$_folder = $this->getSentFolder();
6774 8009
 			}
6775 8010
 			$delimiter = $this->getHierarchyDelimiter();
6776
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
8011
+			if($_folder=='INBOX'.$delimiter)
8012
+			{
8013
+				$_folder='INBOX';
8014
+			}
6777 8015
 			if ($importfailed === false)
6778 8016
 			{
6779 8017
 				$Subject = $mailObject->getHeader('Subject');
@@ -6802,7 +8040,9 @@  discard block
 block discarded – undo
6802 8040
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6803 8041
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6804 8042
 						count($SendAndMergeTocontacts) > 1 && $val &&
6805
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
8043
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
8044
+					{
8045
+						// do the merge
6806 8046
 					{
6807 8047
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6808 8048
 
@@ -6811,6 +8051,7 @@  discard block
 block discarded – undo
6811 8051
 						{
6812 8052
 							//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));
6813 8053
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
8054
+					}
6814 8055
 							$mailObject->addAddress($merged,'',$type);
6815 8056
 							if($type == 'to')
6816 8057
 							{
@@ -6842,9 +8083,15 @@  discard block
 block discarded – undo
6842 8083
 						$mailObject->clearCustomHeaders();
6843 8084
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6844 8085
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6845
-						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));
8086
+						if($text_body)
8087
+						{
8088
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8089
+						}
6846 8090
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6847
-						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));
8091
+						if($html_body)
8092
+						{
8093
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8094
+						}
6848 8095
 
6849 8096
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6850 8097
 						// set a higher timeout for big messages
@@ -6859,9 +8106,12 @@  discard block
 block discarded – undo
6859 8106
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6860 8107
 						}
6861 8108
 					}
6862
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
8109
+					elseif (!$k)
8110
+					{
8111
+						// 1. entry, further entries will fail for apps other then addressbook
6863 8112
 					{
6864 8113
 						$openAsDraft = true;
8114
+					}
6865 8115
 						$mailObject->removeHeader('Message-ID');
6866 8116
 						$mailObject->removeHeader('Date');
6867 8117
 						$mailObject->clearCustomHeaders();
@@ -6876,9 +8126,12 @@  discard block
 block discarded – undo
6876 8126
 
6877 8127
 						// No addresses from placeholders?  Treat it as just a contact ID
6878 8128
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6879
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
8129
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
8130
+						{
8131
+							// do the merge
6880 8132
 						{
6881 8133
 							$contact = $bo_merge->contacts->read($val);
8134
+						}
6882 8135
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6883 8136
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6884 8137
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6889,9 +8142,15 @@  discard block
 block discarded – undo
6889 8142
 						}
6890 8143
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6891 8144
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6892
-						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));
8145
+						if (!empty($Body))
8146
+						{
8147
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8148
+						}
6893 8149
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6894
-						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));
8150
+						if (!empty($AltBody))
8151
+						{
8152
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8153
+						}
6895 8154
 						$_folder = $this->getDraftFolder();
6896 8155
 					}
6897 8156
 					if ($sendOK || $openAsDraft)
@@ -6899,11 +8158,15 @@  discard block
 block discarded – undo
6899 8158
 						if ($this->folderExists($_folder,true))
6900 8159
 						{
6901 8160
 						    if($this->isSentFolder($_folder))
6902
-							{
8161
+						    {
6903 8162
 						        $flags = '\\Seen';
6904
-						    } elseif($this->isDraftFolder($_folder)) {
8163
+						    }
8164
+						    elseif($this->isDraftFolder($_folder))
8165
+						    {
6905 8166
 						        $flags = '\\Draft';
6906
-						    } else {
8167
+						    }
8168
+						    else
8169
+						    {
6907 8170
 						        $flags = '';
6908 8171
 						    }
6909 8172
 							$savefailed = false;
@@ -6937,7 +8200,10 @@  discard block
 block discarded – undo
6937 8200
 						}
6938 8201
 						else
6939 8202
 						{
6940
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8203
+							if (!$openComposeWindow)
8204
+							{
8205
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8206
+							}
6941 8207
 						}
6942 8208
 					}
6943 8209
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6985,7 +8251,10 @@  discard block
 block discarded – undo
6985 8251
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6986 8252
 				break;
6987 8253
 		}
6988
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8254
+		if (!isset($message))
8255
+		{
8256
+			$message = fopen($tmpFileName, 'r');
8257
+		}
6989 8258
 
6990 8259
 		if (!$message)
6991 8260
 		{
@@ -7013,7 +8282,8 @@  discard block
 block discarded – undo
7013 8282
 		{
7014 8283
 			fseek($message, 0, SEEK_SET);
7015 8284
 			$m = '';
7016
-			while (!feof($message)) {
8285
+			while (!feof($message))
8286
+			{
7017 8287
 				$m .= fread($message, 8192);
7018 8288
 			}
7019 8289
 			$message = $m;
@@ -7035,7 +8305,8 @@  discard block
 block discarded – undo
7035 8305
 						$needsReplacement = $needsFix = true;
7036 8306
 					}
7037 8307
 				}
7038
-				if ($needsReplacement) {
8308
+				if ($needsReplacement)
8309
+				{
7039 8310
 					$headers->removeHeader($header);
7040 8311
 					$headers->addHeader($header, $value);
7041 8312
 				}
@@ -7074,7 +8345,10 @@  discard block
 block discarded – undo
7074 8345
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
7075 8346
 
7076 8347
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
7077
-			if ($length===false) $length = strlen($start);
8348
+			if ($length===false)
8349
+			{
8350
+				$length = strlen($start);
8351
+			}
7078 8352
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
7079 8353
 
7080 8354
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -7109,7 +8383,10 @@  discard block
 block discarded – undo
7109 8383
 		}
7110 8384
 		else
7111 8385
 		{
7112
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8386
+			if (($type = gettype($message)) == 'object')
8387
+			{
8388
+				$type = get_class ($message);
8389
+			}
7113 8390
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
7114 8391
 		}
7115 8392
 	}
@@ -7133,7 +8410,9 @@  discard block
 block discarded – undo
7133 8410
 			$matches = array();
7134 8411
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
7135 8412
 			//error_log(__METHOD__.__LINE__.array2string($matches));
7136
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8413
+			foreach ($matches[0] as &$match)
8414
+			{
8415
+$match = trim($match,', ');}
7137 8416
 			$addresses = implode(',',$matches[0]);
7138 8417
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
7139 8418
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -7164,7 +8443,10 @@  discard block
 block discarded – undo
7164 8443
 			}
7165 8444
 			else
7166 8445
 			{
7167
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8446
+				if ($previousFailed && $remember)
8447
+				{
8448
+					$adr->personal = $remember. ' ' . $adr->personal;
8449
+				}
7168 8450
 				$remember = '';
7169 8451
 				$previousFailed=false;
7170 8452
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -7186,7 +8468,10 @@  discard block
 block discarded – undo
7186 8468
 	{
7187 8469
 		$acc = Mail\Account::read($this->profileID);
7188 8470
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
7189
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8471
+		if (self::$debug)
8472
+		{
8473
+			error_log(__METHOD__.__LINE__.array2string($identity));
8474
+		}
7190 8475
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
7191 8476
 
7192 8477
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.
Spacing   +1157 added lines, -1158 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
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
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 134
 		// we switch the balance off because of some broken html mails contents get removed like (td in table), and let browser deal with it
135
-		'balance'=>0,//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
+		'balance'=>0, //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)
136 136
 		'direct_list_nest' => 1,
137
-		'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
+		'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
138 138
 		// tidy eats away even some wanted whitespace, so we switch it off;
139 139
 		// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
140 140
 		'tidy'=>0,
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @array
151 151
 	 */
152
-	static $aclShortCuts = array('' => array('label'=>'none','title'=>'The user has no rights whatsoever.'),
153
-		'lrs'		=> array('label'=>'readable','title'=>'Allows a user to read the contents of the mailbox.'),
154
-		'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.'),
155
-		'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.'),
156
-		'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.'),
157
-		'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.'),
158
-		'custom'	=> array('label'=>'custom','title'=>'User defined combination of rights for the ACL'),
152
+	static $aclShortCuts = array('' => array('label'=>'none', 'title'=>'The user has no rights whatsoever.'),
153
+		'lrs'		=> array('label'=>'readable', 'title'=>'Allows a user to read the contents of the mailbox.'),
154
+		'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.'),
155
+		'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.'),
156
+		'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.'),
157
+		'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.'),
158
+		'custom'	=> array('label'=>'custom', 'title'=>'User defined combination of rights for the ACL'),
159 159
 	);
160 160
 
161 161
 	/**
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
198 198
 	 * @return Mail
199 199
 	 */
200
-	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
200
+	public static function getInstance($_restoreSession = true, &$_profileID = 0, $_validate = true, $_oldImapServerObject = false, $_reuseCache = null)
201 201
 	{
202 202
 		//$_restoreSession=false;
203 203
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
204 204
 		//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());
205 205
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
206
-		self::$profileDefunct = Cache::getCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),5*1);
206
+		self::$profileDefunct = Cache::getCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 5 * 1);
207 207
 		if (isset(self::$profileDefunct[$_profileID]) && strlen(self::$profileDefunct[$_profileID]))
208 208
 		{
209 209
 			throw new Exception(__METHOD__." failed to instanciate Mail for Profile #$_profileID Reason:".self::$profileDefunct[$_profileID]);
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 		{
213 213
 			if (!is_object(self::$instances[$_profileID]))
214 214
 			{
215
-				self::$instances[$_profileID] = new Mail('utf-8',false,$_profileID,false,$_reuseCache);
215
+				self::$instances[$_profileID] = new Mail('utf-8', false, $_profileID, false, $_reuseCache);
216 216
 			}
217 217
 			self::$instances[$_profileID]->icServer = $_oldImapServerObject;
218
-			self::$instances[$_profileID]->accountid= $_oldImapServerObject->ImapServerId;
219
-			self::$instances[$_profileID]->profileID= $_oldImapServerObject->ImapServerId;
218
+			self::$instances[$_profileID]->accountid = $_oldImapServerObject->ImapServerId;
219
+			self::$instances[$_profileID]->profileID = $_oldImapServerObject->ImapServerId;
220 220
 			self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
221
-			self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
221
+			self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
222 222
 			return self::$instances[$_profileID];
223 223
 		}
224 224
 		if ($_profileID == 0)
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 			{
232 232
 				$profileID = Mail\Account::get_default_acc_id();
233 233
 			}
234
-			if ($profileID!=$_profileID) $_restoreSession==false;
235
-			$_profileID=$profileID;
234
+			if ($profileID != $_profileID) $_restoreSession == false;
235
+			$_profileID = $profileID;
236 236
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
237 237
 		}
238 238
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
239
-		if ($_oldImapServerObject===true)
239
+		if ($_oldImapServerObject === true)
240 240
 		{
241
-			return new Mail('utf-8',false,$_profileID,true,$_reuseCache);
241
+			return new Mail('utf-8', false, $_profileID, true, $_reuseCache);
242 242
 		}
243 243
 		if ($_profileID != 0 && $_validate)
244 244
 		{
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 			//Cache::setSession('mail','activeProfileID',$_profileID);
259 259
 		}
260 260
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
261
-		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession===false))
261
+		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession === false))
262 262
 		{
263
-			self::$instances[$_profileID] = new Mail('utf-8',$_restoreSession,$_profileID,false,$_reuseCache);
263
+			self::$instances[$_profileID] = new Mail('utf-8', $_restoreSession, $_profileID, false, $_reuseCache);
264 264
 		}
265 265
 		else
266 266
 		{
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 				self::$instances[$_profileID]->ogServer = Mail\Account::read($_profileID)->smtpServer();
272 272
 				// TODO: merge mailprefs into userprefs, for easy treatment
273 273
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
274
-				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
274
+				self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
275 275
 			} catch (\Exception $e)
276 276
 			{
277 277
 				$newprofileID = Mail\Account::get_default_acc_id();
@@ -279,15 +279,15 @@  discard block
 block discarded – undo
279 279
 				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());
280 280
 				if ($newprofileID)
281 281
 				{
282
-					self::$instances[$newprofileID] = new Mail('utf-8',false,$newprofileID,false,$_reuseCache);
282
+					self::$instances[$newprofileID] = new Mail('utf-8', false, $newprofileID, false, $_reuseCache);
283 283
 					$_profileID = $newprofileID;
284 284
 				}
285 285
 				else
286 286
 				{
287
-					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID with error:".$e->getMessage().($e->details?', '.$e->details:''));
287
+					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
288 288
 				}
289 289
 			}
290
-			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
290
+			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate);
291 291
 		}
292 292
 		self::$instances[$_profileID]->profileID = $_profileID;
293 293
 		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	public static function fixInvalidAliasAddress($refrence, $address)
309 309
 	{
310 310
 		$parts = explode('@', $refrence);
311
-		if (!strpos($address,'@') && !empty($parts[1])) $address .= '@'.$parts[1];
311
+		if (!strpos($address, '@') && !empty($parts[1])) $address .= '@'.$parts[1];
312 312
 		return $address;
313 313
 	}
314 314
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @param boolean $_testConnection = 0
320 320
 	 * @return mixed $_profileID or false on failed ConnectionTest
321 321
 	 */
322
-	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID=0, $_testConnection=true)
322
+	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID = 0, $_testConnection = true)
323 323
 	{
324 324
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
325 325
 		{
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 		}
341 341
 		if ($oldProfileID != $_profileID)
342 342
 		{
343
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
344
-			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
343
+			if ($oldProfileID && $_profileID == 0) $_profileID = $oldProfileID;
344
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveProfileID', $_profileID, 'user');
345 345
 			// save prefs
346 346
 			$GLOBALS['egw']->preferences->save_repository(true);
347 347
 			$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $_profileID;
348
-			Cache::setSession('mail','activeProfileID',$_profileID);
348
+			Cache::setSession('mail', 'activeProfileID', $_profileID);
349 349
 		}
350 350
 		return $_profileID;
351 351
 	}
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 * @param int $_acc_id = 0
361 361
 	 * @return int validated acc_id -> either acc_id given, or first valid one
362 362
 	 */
363
-	public static function validateProfileID($_acc_id=0)
363
+	public static function validateProfileID($_acc_id = 0)
364 364
 	{
365 365
 		if ($_acc_id)
366 366
 		{
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 		}
380 380
 		// no account specified or specified account not found or not valid
381 381
 		// --> search existing account for first valid one and return that
382
-		foreach(Mail\Account::search($only_current_user=true, 'acc_imap_host') as $acc_id => $imap_host)
382
+		foreach (Mail\Account::search($only_current_user = true, 'acc_imap_host') as $acc_id => $imap_host)
383 383
 		{
384 384
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
385 385
 			{
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 * @param boolean $_oldImapServerObject = false
402 402
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
403 403
 	 */
404
-	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
404
+	private function __construct($_displayCharset = 'utf-8', $_restoreSession = true, $_profileID = 0, $_oldImapServerObject = false, $_reuseCache = null)
405 405
 	{
406 406
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
407 407
 		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 			$firstMessage = $this->sessionData['previewMessage'];
422 422
 			$this->sessionData = array();
423 423
 		}
424
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
424
+		if (!$_reuseCache) $this->forcePrefReload($_profileID, !$_reuseCache);
425 425
 		try
426 426
 		{
427 427
 			$this->profileID = self::validateProfileID($_profileID);
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
 			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage());
436 436
 		}
437 437
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($acc->imapServer()));
438
-		$this->icServer = ($_oldImapServerObject?$acc->oldImapServer():$acc->imapServer());
438
+		$this->icServer = ($_oldImapServerObject ? $acc->oldImapServer() : $acc->imapServer());
439 439
 		$this->ogServer = $acc->smtpServer();
440 440
 		// TODO: merge mailprefs into userprefs, for easy treatment
441 441
 		$this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
442
-		$this->htmlOptions  = $this->mailPreferences['htmlOptions'];
442
+		$this->htmlOptions = $this->mailPreferences['htmlOptions'];
443 443
 		if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
444 444
 		{
445 445
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	public static function &forceEAProfileLoad($_profile_id)
458 458
 	{
459 459
 		self::unsetCachedObjects($_profile_id);
460
-		$mail = self::getInstance(false, $_profile_id,false);
460
+		$mail = self::getInstance(false, $_profile_id, false);
461 461
 		//_debug_array( $_profile_id);
462 462
 		$mail->icServer = Mail\Account::read($_profile_id)->imapServer();
463 463
 		$mail->ogServer = Mail\Account::read($_profile_id)->smtpServer();
@@ -469,11 +469,11 @@  discard block
 block discarded – undo
469 469
 	 * @param int $_profile_id
470 470
 	 * @param boolean $_resetFolderObjects
471 471
 	 */
472
-	public static function forcePrefReload($_profile_id=null,$_resetFolderObjects=true)
472
+	public static function forcePrefReload($_profile_id = null, $_resetFolderObjects = true)
473 473
 	{
474 474
 		// unset the mail_preferences session object, to force the reload/rebuild
475
-		Cache::setSession('mail','mail_preferences',serialize(array()));
476
-		Cache::setSession('emailadmin','session_data',serialize(array()));
475
+		Cache::setSession('mail', 'mail_preferences', serialize(array()));
476
+		Cache::setSession('emailadmin', 'session_data', serialize(array()));
477 477
 		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
478 478
 	}
479 479
 
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 */
483 483
 	function restoreSessionData()
484 484
 	{
485
-		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
486
-		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
485
+		$this->sessionData = array(); //Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
486
+		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
487 487
 		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
488 488
 	}
489 489
 
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 	function saveSessionData()
494 494
 	{
495 495
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
496
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
496
+		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID] = $this->sessionData['mailbox'];
497 497
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
498 498
 		{
499
-			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
499
+			Cache::setCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), self::$activeFolderCache, 60 * 60 * 10);
500 500
 		}
501 501
 		// no need to block session any longer
502 502
 		$GLOBALS['egw']->session->commit_session();
@@ -514,40 +514,40 @@  discard block
 block discarded – undo
514 514
 	 * @param int $_profileID = null default profile of user as returned by getUserDefaultProfileID
515 515
 	 * @return void
516 516
 	 */
517
-	static function unsetCachedObjects($_profileID=null)
517
+	static function unsetCachedObjects($_profileID = null)
518 518
 	{
519 519
 		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
520 520
 		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
521 521
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
522
-		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
522
+		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID, 'tracker_') === false)))
523 523
 		{
524 524
 			self::resetConnectionErrorCache($_profileID);
525
-			$rawHeadersCache = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
525
+			$rawHeadersCache = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
526 526
 			if (isset($rawHeadersCache[$_profileID]))
527 527
 			{
528 528
 				unset($rawHeadersCache[$_profileID]);
529
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$rawHeadersCache, $expiration=60*60*1);
529
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $rawHeadersCache, $expiration = 60 * 60 * 1);
530 530
 			}
531
-			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*5);
531
+			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 5);
532 532
 			if (isset($HierarchyDelimiterCache[$_profileID]))
533 533
 			{
534 534
 				unset($HierarchyDelimiterCache[$_profileID]);
535
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$HierarchyDelimiterCache, $expiration=60*60*24*5);
535
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $HierarchyDelimiterCache, $expiration = 60 * 60 * 24 * 5);
536 536
 			}
537 537
 			//reset folderObject cache, to trigger reload
538 538
 			self::resetFolderObjectCache($_profileID);
539 539
 			//reset counter of deleted messages per folder
540
-			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
540
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
541 541
 			if (isset($eMailListContainsDeletedMessages[$_profileID]))
542 542
 			{
543 543
 				unset($eMailListContainsDeletedMessages[$_profileID]);
544
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$eMailListContainsDeletedMessages, $expiration=60*60*1);
544
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $eMailListContainsDeletedMessages, $expiration = 60 * 60 * 1);
545 545
 			}
546
-			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*1);
546
+			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 1);
547 547
 			if (isset($vacationCached[$_profileID]))
548 548
 			{
549 549
 				unset($vacationCached[$_profileID]);
550
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
550
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $vacationCached, $expiration = 60 * 60 * 24 * 1);
551 551
 			}
552 552
 
553 553
 			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
@@ -555,17 +555,17 @@  discard block
 block discarded – undo
555 555
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
556 556
 		{
557 557
 			// called via hook
558
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account)
558
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account)
559 559
 			{
560 560
 				//error_log(__METHOD__.__LINE__.array2string($account));
561 561
 				$account_id = $account['account_id'];
562 562
 				$_profileID = null;
563
-				self::resetConnectionErrorCache($_profileID,$account_id);
564
-				self::resetFolderObjectCache($_profileID,$account_id);
565
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),array(), 60*60*1);
566
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),array(), 60*60*24*5);
567
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),array(), 60*60*1);
568
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),array(), 60*60*24*1);
563
+				self::resetConnectionErrorCache($_profileID, $account_id);
564
+				self::resetFolderObjectCache($_profileID, $account_id);
565
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), array(), 60 * 60 * 1);
566
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), array(), 60 * 60 * 24 * 5);
567
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), array(), 60 * 60 * 1);
568
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), array(), 60 * 60 * 24 * 1);
569 569
 			}
570 570
 		}
571 571
 	}
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 	 * @param int $_ImapServerId the profileID to look for
577 577
 	 * @param int $account_id the egw account to look for
578 578
 	 */
579
-	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
579
+	static function resetConnectionErrorCache($_ImapServerId = null, $account_id = null)
580 580
 	{
581 581
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
582 582
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -594,19 +594,19 @@  discard block
 block discarded – undo
594 594
 		}
595 595
 		else
596 596
 		{
597
-			$isConError = Cache::getCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id));
597
+			$isConError = Cache::getCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id));
598 598
 			if (isset($isConError[$_ImapServerId]))
599 599
 			{
600 600
 				unset($isConError[$_ImapServerId]);
601 601
 			}
602
-			$waitOnFailure = Cache::getCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),null,array(),60*60*2);
602
+			$waitOnFailure = Cache::getCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), null, array(), 60 * 60 * 2);
603 603
 			if (isset($waitOnFailure[$_ImapServerId]))
604 604
 			{
605 605
 				unset($waitOnFailure[$_ImapServerId]);
606 606
 			}
607 607
 		}
608
-		Cache::setCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,60*15);
609
-		Cache::setCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),$waitOnFailure,60*60*2);
608
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id), $isConError, 60 * 15);
609
+		Cache::setCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), $waitOnFailure, 60 * 60 * 2);
610 610
 	}
611 611
 
612 612
 	/**
@@ -615,13 +615,13 @@  discard block
 block discarded – undo
615 615
 	 * @param int $_ImapServerId the profileID to look for
616 616
 	 * @param int $account_id the egw account to look for
617 617
 	 */
618
-	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
618
+	static function resetFolderObjectCache($_ImapServerId = null, $account_id = null)
619 619
 	{
620 620
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
621 621
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
622 622
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
623 623
 		// or treat it as not given. we try that path
624
-		if (is_null($_ImapServerId)||is_array($_ImapServerId))
624
+		if (is_null($_ImapServerId) || is_array($_ImapServerId))
625 625
 		{
626 626
 			$folders2return = array();
627 627
 			$folderInfo = array();
@@ -630,12 +630,12 @@  discard block
 block discarded – undo
630 630
 		}
631 631
 		else
632 632
 		{
633
-			$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),null,array(),60*60*1);
633
+			$folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), null, array(), 60 * 60 * 1);
634 634
 			if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
635 635
 			{
636 636
 				unset($folders2return[$_ImapServerId]);
637 637
 			}
638
-			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),60*60*5);
638
+			$folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), null, array(), 60 * 60 * 5);
639 639
 			if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
640 640
 			{
641 641
 				unset($folderInfo[$_ImapServerId]);
@@ -647,23 +647,23 @@  discard block
 block discarded – undo
647 647
 				unset($lastFolderUsedForMove[$_ImapServerId]);
648 648
 			}
649 649
 			*/
650
-			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),60*60*1);
650
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), null, array(), 60 * 60 * 1);
651 651
 			if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
652 652
 			{
653 653
 				unset($folderBasicInfo[$_ImapServerId]);
654 654
 			}
655
-			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),60*60*12);
655
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), null, array(), 60 * 60 * 12);
656 656
 			if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
657 657
 			{
658 658
 				unset($_specialUseFolders[$_ImapServerId]);
659
-				self::$specialUseFolders=null;
659
+				self::$specialUseFolders = null;
660 660
 			}
661 661
 		}
662
-		Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),$folders2return, 60*60*1);
663
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),$folderInfo,60*60*5);
662
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), $folders2return, 60 * 60 * 1);
663
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), $folderInfo, 60 * 60 * 5);
664 664
 		//Cache::setCache(Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($account_id),$lastFolderUsedForMove,$expiration=60*60*1);
665
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),$folderBasicInfo,60*60*1);
666
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),$_specialUseFolders,60*60*12);
665
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), $folderBasicInfo, 60 * 60 * 1);
666
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), $_specialUseFolders, 60 * 60 * 12);
667 667
 	}
668 668
 
669 669
 	/**
@@ -684,15 +684,15 @@  discard block
 block discarded – undo
684 684
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
685 685
 	 * @return array - array(email=>realname)
686 686
 	 */
687
-	function getUserEMailAddresses($_profileID=null)
687
+	function getUserEMailAddresses($_profileID = null)
688 688
 	{
689
-		$acc = Mail\Account::read((!empty($_profileID)?$_profileID:$this->profileID));
689
+		$acc = Mail\Account::read((!empty($_profileID) ? $_profileID : $this->profileID));
690 690
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
691 691
 		$identities = Mail\Account::identities($acc);
692 692
 
693 693
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
694 694
 
695
-		foreach($identities as $ik => $ident) {
695
+		foreach ($identities as $ik => $ident) {
696 696
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
697 697
 			$identity = Mail\Account::read_identity($ik);
698 698
 			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
@@ -707,19 +707,19 @@  discard block
 block discarded – undo
707 707
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
708 708
 	 * @return array - array(email=>realname)
709 709
 	 */
710
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false)
710
+	static function getAllIdentities($_accountToSearch = null, $resolve_placeholders = false)
711 711
 	{
712 712
 		$userEMailAdresses = array();
713
-		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
713
+		foreach (Mail\Account::search($only_current_user = ($_accountToSearch ? $_accountToSearch : true), $just_name = true) as $acc_id => $identity_name)
714 714
 		{
715
-			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
716
-			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']);
715
+			$acc = Mail\Account::read($acc_id, ($_accountToSearch ? $_accountToSearch : null));
716
+			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']);
717 717
 
718
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
718
+			foreach (Mail\Account::identities($acc) as $ik => $ident) {
719 719
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
720
-				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
720
+				$identity = Mail\Account::read_identity($ik, $resolve_placeholders);
721 721
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
722
-				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']);
722
+				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']);
723 723
 			}
724 724
 		}
725 725
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -739,9 +739,9 @@  discard block
 block discarded – undo
739 739
 			$account = Mail\Account::read($account);
740 740
 		}
741 741
 		$userEMailAdresses = array();
742
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
742
+		foreach (Mail\Account::identities($account, true, 'params') as $ik => $ident) {
743 743
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
744
-			$identity = Mail\Account::read_identity($ik,true,null,$account);
744
+			$identity = Mail\Account::read_identity($ik, true, null, $account);
745 745
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
746 746
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
747 747
 			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
 	function getDefaultIdentity()
769 769
 	{
770 770
 		// retrieve the signature accociated with the identity
771
-		$id = $this->getIdentitiesWithAccounts($_accountData=array());
772
-		foreach(Mail\Account::identities($_accountData[$this->profileID] ?
773
-			$this->profileID : $_accountData[$id],false,'ident_id') as $accountData)
771
+		$id = $this->getIdentitiesWithAccounts($_accountData = array());
772
+		foreach (Mail\Account::identities($_accountData[$this->profileID] ?
773
+			$this->profileID : $_accountData[$id], false, 'ident_id') as $accountData)
774 774
 		{
775 775
 			return $accountData;
776 776
 		}
@@ -786,13 +786,13 @@  discard block
 block discarded – undo
786 786
 	{
787 787
 		// account select box
788 788
 		$selectedID = $this->profileID;
789
-		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
789
+		$allAccountData = Mail\Account::search($only_current_user = true, false, null);
790 790
 		if ($allAccountData) {
791
-			$rememberFirst=$selectedFound=null;
791
+			$rememberFirst = $selectedFound = null;
792 792
 			foreach ($allAccountData as $tmpkey => $icServers)
793 793
 			{
794 794
 				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
795
-				if ($tmpkey == $selectedID) $selectedFound=true;
795
+				if ($tmpkey == $selectedID) $selectedFound = true;
796 796
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
797 797
 				$host = $icServers->acc_imap_host;
798 798
 				if (empty($host)) continue;
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
801 801
 			}
802 802
 		}
803
-		return ($selectedFound?$selectedID:$rememberFirst);
803
+		return ($selectedFound ? $selectedID : $rememberFirst);
804 804
 	}
805 805
 
806 806
 	/**
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 * @var boolean $fullString full or false=NamePart only is returned
811 811
 	 * @return string - constructed of identity object data as defined in mailConfig
812 812
 	 */
813
-	static function generateIdentityString($identity, $fullString=true)
813
+	static function generateIdentityString($identity, $fullString = true)
814 814
 	{
815 815
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($identity));
816 816
 		//if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
@@ -821,16 +821,16 @@  discard block
 block discarded – undo
821 821
 		{
822 822
 			case 'email';
823 823
 				//$retData = str_replace('@',' ',$identity->emailAddress).($fullString===true?' <'.$identity->emailAddress.'>':'');
824
-				$retData = $identity['ident_email'].($fullString===true?' <'.$identity['ident_email'].'>':'');
824
+				$retData = $identity['ident_email'].($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
825 825
 				break;
826 826
 			case 'nameNemail';
827
-				$retData = (!empty($identity['ident_realname'])?$identity['ident_realname']:substr_replace($identity['ident_email'],'',strpos($identity['ident_email'],'@'))).($fullString===true?' <'.$identity['ident_email'].'>':'');
827
+				$retData = (!empty($identity['ident_realname']) ? $identity['ident_realname'] : substr_replace($identity['ident_email'], '', strpos($identity['ident_email'], '@'))).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
828 828
 				break;
829 829
 			case 'orgNemail';
830
-				$retData = (!empty($identity['ident_org'])?$identity['ident_org']:substr_replace($identity['ident_email'],'',0,strpos($identity['ident_email'],'@')+1)).($fullString===true?' <'.$identity['ident_email'].'>':'');
830
+				$retData = (!empty($identity['ident_org']) ? $identity['ident_org'] : substr_replace($identity['ident_email'], '', 0, strpos($identity['ident_email'], '@') + 1)).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
831 831
 				break;
832 832
 			default:
833
-				$retData = $identity['ident_realname'].(!empty($identity['ident_org'])?' '.$identity['ident_org']:'').($fullString===true?' <'.$identity['ident_email'].'>':'');
833
+				$retData = $identity['ident_realname'].(!empty($identity['ident_org']) ? ' '.$identity['ident_org'] : '').($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
834 834
 		}
835 835
 		return $retData;
836 836
 	}
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 	 */
856 856
 	function reopen($_foldername)
857 857
 	{
858
-		if (self::$debugTimes) $starttime = microtime (true);
858
+		if (self::$debugTimes) $starttime = microtime(true);
859 859
 
860 860
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
861 861
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 			}
871 871
 			$folderOpened = $_foldername;
872 872
 		//}
873
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
873
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'Folder:'.$_foldername, __METHOD__.' ('.__LINE__.') ');
874 874
 	}
875 875
 
876 876
 
@@ -881,15 +881,15 @@  discard block
 block discarded – undo
881 881
 	 * @throws Horde_Imap_Client_Exception on connection error or authentication failure
882 882
 	 * @throws InvalidArgumentException on missing credentials
883 883
 	 */
884
-	function openConnection($_icServerID=0)
884
+	function openConnection($_icServerID = 0)
885 885
 	{
886 886
 		//error_log( "-------------------------->open connection ".function_backtrace());
887 887
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
888
-		if (self::$debugTimes) $starttime = microtime (true);
889
-		$mailbox=null;
888
+		if (self::$debugTimes) $starttime = microtime(true);
889
+		$mailbox = null;
890 890
 		try
891 891
 		{
892
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
892
+			if (isset($this->sessionData['mailbox']) && $this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
893 893
 			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
894 894
 /*
895 895
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
917 917
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
918 918
 		}
919
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
919
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'ProfileID:'.$_icServerID, __METHOD__.' ('.__LINE__.') ');
920 920
 	}
921 921
 
922 922
 	/**
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 		try
938 938
 		{
939 939
 			$this->icServer->getCurrentMailbox();
940
-			if(!$this->icServer->hasCapability('QUOTA')) {
940
+			if (!$this->icServer->hasCapability('QUOTA')) {
941 941
 				$quota = false;
942 942
 				return false;
943 943
 			}
@@ -947,15 +947,15 @@  discard block
 block discarded – undo
947 947
 		{
948 948
 			//error_log(__METHOD__.array2string($e));
949 949
 			//error_log(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
950
-			if ($e->getCode()==102)
950
+			if ($e->getCode() == 102)
951 951
 			{
952
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
953
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
954
-				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
952
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
953
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
954
+				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
955 955
 			}
956 956
 		}
957 957
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
958
-		if(is_array($quota)) {
958
+		if (is_array($quota)) {
959 959
 			$quota = array(
960 960
 				'usage'	=> $quota['USED'],
961 961
 				'limit'	=> $quota['QMAX'],
@@ -973,10 +973,10 @@  discard block
 block discarded – undo
973 973
 	 *
974 974
 	 * @return int - timeout (either set or default 20/10)
975 975
 	 */
976
-	static function getTimeOut($_use='IMAP')
976
+	static function getTimeOut($_use = 'IMAP')
977 977
 	{
978 978
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
979
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
979
+		if (empty($timeout)) $timeout = ($_use == 'SIEVE' ? 10 : 20); // this is the default value
980 980
 		return $timeout;
981 981
 	}
982 982
 
@@ -997,18 +997,18 @@  discard block
 block discarded – undo
997 997
 		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
998 998
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
999 999
 		if (is_array($nameSpace)) {
1000
-			foreach($nameSpace as $type => $singleNameSpaceArray)
1000
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
1001 1001
 			{
1002 1002
 				foreach ($singleNameSpaceArray as $singleNameSpace)
1003 1003
 				{
1004 1004
 					$_foldersNameSpace = array();
1005
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
1005
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
1006 1006
 					{
1007 1007
 						$_foldersNameSpace['prefix_present'] = 'forced';
1008 1008
 						// uw-imap server with mailbox prefix or dovecot maybe
1009
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
1009
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
1010 1010
 					}
1011
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
1011
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
1012 1012
 					{
1013 1013
 						$_foldersNameSpace['prefix_present'] = 'forced';
1014 1014
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
1018 1018
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
1019 1019
 					}
1020
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
1020
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
1021 1021
 					$_foldersNameSpace['type'] = $type;
1022
-					$foldersNameSpace[] =$_foldersNameSpace;
1022
+					$foldersNameSpace[] = $_foldersNameSpace;
1023 1023
 				}
1024 1024
 				//echo "############## $type->".print_r($foldersNameSpace[$type],true)." ###################<br>";
1025 1025
 			}
@@ -1037,10 +1037,10 @@  discard block
 block discarded – undo
1037 1037
 	 */
1038 1038
 	function getFolderPrefixFromNamespace($nameSpace, $folderName)
1039 1039
 	{
1040
-		foreach($nameSpace as &$singleNameSpace)
1040
+		foreach ($nameSpace as &$singleNameSpace)
1041 1041
 		{
1042 1042
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1043
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1043
+			if (substr($folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1044 1044
 		}
1045 1045
 		return "";
1046 1046
 	}
@@ -1051,12 +1051,12 @@  discard block
 block discarded – undo
1051 1051
 	 * @var boolean $_useCache
1052 1052
 	 * @return string the hierarchyDelimiter
1053 1053
 	 */
1054
-	function getHierarchyDelimiter($_useCache=true)
1054
+	function getHierarchyDelimiter($_useCache = true)
1055 1055
 	{
1056 1056
 		static $HierarchyDelimiter = null;
1057
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1058
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1059
-		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1057
+		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1058
+		if ($_useCache === false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1059
+		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId]) && !empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1060 1060
 		{
1061 1061
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
1062 1062
 		}
@@ -1066,17 +1066,17 @@  discard block
 block discarded – undo
1066 1066
 			$this->icServer->getCurrentMailbox();
1067 1067
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = $this->icServer->getDelimiter();
1068 1068
 		}
1069
-		catch(\Exception $e)
1069
+		catch (\Exception $e)
1070 1070
 		{
1071
-			if ($e->getCode()==102)
1071
+			if ($e->getCode() == 102)
1072 1072
 			{
1073
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1074
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1073
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1074
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1075 1075
 			}
1076 1076
 			unset($e);
1077 1077
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1078 1078
 		}
1079
-		Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),$HierarchyDelimiter, 60*60*24*5);
1079
+		Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), $HierarchyDelimiter, 60 * 60 * 24 * 5);
1080 1080
 		return $HierarchyDelimiter[$this->icServer->ImapServerId];
1081 1081
 	}
1082 1082
 
@@ -1089,7 +1089,7 @@  discard block
 block discarded – undo
1089 1089
 	{
1090 1090
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1091 1091
 		static $_specialUseFolders = null;
1092
-		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);
1092
+		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);
1093 1093
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1094 1094
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1095 1095
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
@@ -1097,20 +1097,20 @@  discard block
 block discarded – undo
1097 1097
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1098 1098
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1099 1099
 			return $_specialUseFolders[$this->icServer->ImapServerId];
1100
-		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1100
+		$_specialUseFolders[$this->icServer->ImapServerId] = array();
1101 1101
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1102
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
1102
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash] = 'Trash';
1103 1103
 		//if (!empty($this->icServer->acc_folder_draft) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]))
1104
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]='Drafts';
1104
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft] = 'Drafts';
1105 1105
 		//if (!empty($this->icServer->acc_folder_sent) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]))
1106
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]='Sent';
1106
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent] = 'Sent';
1107 1107
 		//if (!empty($this->icServer->acc_folder_template) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]))
1108
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]='Templates';
1109
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk]='Junk';
1110
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive]='Archive';
1108
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template] = 'Templates';
1109
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk] = 'Junk';
1110
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive] = 'Archive';
1111 1111
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_specialUseFolders));//.'<->'.array2string($this->icServer));
1112 1112
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1113
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders, 60*60*24*5);
1113
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $_specialUseFolders, 60 * 60 * 24 * 5);
1114 1114
 		return $_specialUseFolders[$this->icServer->ImapServerId];
1115 1115
 	}
1116 1116
 
@@ -1124,8 +1124,8 @@  discard block
 block discarded – undo
1124 1124
 	function folderIsSelectable($folderToSelect)
1125 1125
 	{
1126 1126
 		$retval = true;
1127
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1128
-			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1127
+		if ($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect, false, true))) {
1128
+			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']), 'noselect') !== false)
1129 1129
 			{
1130 1130
 				$retval = false;
1131 1131
 			}
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
 	 *
1146 1146
 	 * @throws Exception
1147 1147
 	 */
1148
-	function _getStatus($folderName,$ignoreStatusCache=false)
1148
+	function _getStatus($folderName, $ignoreStatusCache = false)
1149 1149
 	{
1150 1150
 		static $folderStatus = null;
1151 1151
 		if (!$ignoreStatusCache && isset($folderStatus[$this->icServer->ImapServerId][$folderName]))
@@ -1155,11 +1155,11 @@  discard block
 block discarded – undo
1155 1155
 		}
1156 1156
 		try
1157 1157
 		{
1158
-			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName,$ignoreStatusCache);
1158
+			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName, $ignoreStatusCache);
1159 1159
 		}
1160 1160
 		catch (\Exception $e)
1161 1161
 		{
1162
-			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details?', '.$e->details:''));
1162
+			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
1163 1163
 		}
1164 1164
 		return $folderStatus[$this->icServer->ImapServerId][$folderName];
1165 1165
 	}
@@ -1175,10 +1175,10 @@  discard block
 block discarded – undo
1175 1175
 	 * @param fetchSubscribedInfo bool fetch Subscribed Info on folder
1176 1176
 	 * @return array
1177 1177
 	 */
1178
-	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1178
+	function getFolderStatus($_folderName, $ignoreStatusCache = false, $basicInfoOnly = false, $fetchSubscribedInfo = true)
1179 1179
 	{
1180 1180
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1181
-		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1181
+		if (!is_string($_folderName) || empty($_folderName) || (isset(self::$profileDefunct[$this->profileID]) && strlen(self::$profileDefunct[$this->profileID])))
1182 1182
 		{
1183 1183
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
1184 1184
 			return false;
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 		{
1190 1190
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1191 1191
 		}
1192
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1192
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache == false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1193 1193
 		$retValue = array();
1194 1194
 		$retValue['subscribed'] = false;
1195 1195
 /*
@@ -1210,41 +1210,41 @@  discard block
 block discarded – undo
1210 1210
 			{
1211 1211
 				//error_log(__METHOD__.array2string($e));
1212 1212
 				//error_log(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1213
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1214
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1215
-				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1213
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1214
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1215
+				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
1216 1216
 			}
1217 1217
 			//error_log(__METHOD__.' ('.__LINE__.') '.$_folderName.' '.array2string($ret));
1218 1218
 			if (is_array($ret))
1219 1219
 			{
1220 1220
 				$retkeys = array_keys($ret);
1221
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1221
+				if ($retkeys[0] == $_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1222 1222
 			}
1223 1223
 			else
1224 1224
 			{
1225
-				$folderInfoCache[$_folderName]=false;
1225
+				$folderInfoCache[$_folderName] = false;
1226 1226
 			}
1227 1227
 		}
1228 1228
 		$folderInfo = $folderInfoCache[$_folderName];
1229 1229
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1230
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1230
+		if ($ignoreStatusCache || !$folderInfo || !is_array($folderInfo)) {
1231 1231
 			try
1232 1232
 			{
1233
-				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
1233
+				$folderInfo = $this->_getStatus($_folderName, $ignoreStatusCache);
1234 1234
 			}
1235 1235
 			catch (\Exception $e)
1236 1236
 			{
1237 1237
 				//error_log(__METHOD__.array2string($e));
1238
-				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1239
-				self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
1240
-				Cache::setCache(Cache::INSTANCE,'email','profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']),self::$profileDefunct, $expiration=5*1);
1238
+				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : '')/*.function_backtrace()*/);
1239
+				self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
1240
+				Cache::setCache(Cache::INSTANCE, 'email', 'profileDefunct'.trim($GLOBALS['egw_info']['user']['account_id']), self::$profileDefunct, $expiration = 5 * 1);
1241 1241
 				//throw new Exception(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1242
-				$folderInfo=null;
1242
+				$folderInfo = null;
1243 1243
 			}
1244 1244
 			if (!is_array($folderInfo))
1245 1245
 			{
1246 1246
 				// no folder info, but there is a status returned for the folder: something is wrong, try to cope with it
1247
-				$folderInfo = is_array($folderInfo)?$folderInfo:array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1247
+				$folderInfo = is_array($folderInfo) ? $folderInfo : array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1248 1248
 					'ATTRIBUTES' => '');
1249 1249
 				if (!isset($folderInfo['HIERACHY_DELIMITER']) || empty($folderInfo['HIERACHY_DELIMITER']) || (isset($folderInfo['delimiter']) && empty($folderInfo['delimiter'])))
1250 1250
 				{
@@ -1256,24 +1256,24 @@  discard block
 block discarded – undo
1256 1256
 		#if(!is_array($folderInfo)) {
1257 1257
 		#	return false;
1258 1258
 		#}
1259
-		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER']?$folderInfo['HIERACHY_DELIMITER']:$folderInfo['delimiter']);
1260
-		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES']?$folderInfo['ATTRIBUTES']:$folderInfo['attributes']);
1261
-		$shortNameParts			= explode($retValue['delimiter'], $_folderName);
1259
+		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER'] ? $folderInfo['HIERACHY_DELIMITER'] : $folderInfo['delimiter']);
1260
+		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES'] ? $folderInfo['ATTRIBUTES'] : $folderInfo['attributes']);
1261
+		$shortNameParts = explode($retValue['delimiter'], $_folderName);
1262 1262
 		$retValue['shortName']		= array_pop($shortNameParts);
1263 1263
 		$retValue['displayName']	= $_folderName;
1264
-		$retValue['shortDisplayName']	= $retValue['shortName'];
1265
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1266
-			$retValue['displayName']	= lang('INBOX');
1267
-			$retValue['shortDisplayName']	= lang('INBOX');
1264
+		$retValue['shortDisplayName'] = $retValue['shortName'];
1265
+		if (strtoupper($retValue['shortName']) == 'INBOX') {
1266
+			$retValue['displayName'] = lang('INBOX');
1267
+			$retValue['shortDisplayName'] = lang('INBOX');
1268 1268
 		}
1269 1269
 		// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
1270
-		elseif (in_array($retValue['shortName'],self::$autoFolders))
1270
+		elseif (in_array($retValue['shortName'], self::$autoFolders))
1271 1271
 		{
1272 1272
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1273 1273
 		}
1274
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1274
+		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName] = $retValue;
1275 1275
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1276
-		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1276
+		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']), 'noselect') !== false))
1277 1277
 		{
1278 1278
 			return $retValue;
1279 1279
 		}
@@ -1286,12 +1286,12 @@  discard block
 block discarded – undo
1286 1286
 		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1287 1287
 		if (!empty($nameSpace[$this->profileID]))
1288 1288
 		{
1289
-			$nsNoPersonal=array();
1290
-			foreach($nameSpace[$this->profileID] as &$ns)
1289
+			$nsNoPersonal = array();
1290
+			foreach ($nameSpace[$this->profileID] as &$ns)
1291 1291
 			{
1292
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1292
+				if ($ns['type'] != 'personal') $nsNoPersonal[] = $ns;
1293 1293
 			}
1294
-			$nameSpace[$this->profileID]=$nsNoPersonal;
1294
+			$nameSpace[$this->profileID] = $nsNoPersonal;
1295 1295
 		}
1296 1296
 		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1297 1297
 
@@ -1300,34 +1300,34 @@  discard block
 block discarded – undo
1300 1300
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1301 1301
 		}
1302 1302
 
1303
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1303
+		if ($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName, $subscribedFolders[$this->profileID])) {
1304 1304
 			$retValue['subscribed'] = true;
1305 1305
 		}
1306 1306
 
1307 1307
 		try
1308 1308
 		{
1309 1309
 			//$folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache);
1310
-			$folderStatus = $this->getMailBoxCounters($_folderName,false);
1311
-			$retValue['messages']		= $folderStatus['MESSAGES'];
1310
+			$folderStatus = $this->getMailBoxCounters($_folderName, false);
1311
+			$retValue['messages'] = $folderStatus['MESSAGES'];
1312 1312
 			$retValue['recent']		= $folderStatus['RECENT'];
1313
-			$retValue['uidnext']		= $folderStatus['UIDNEXT'];
1314
-			$retValue['uidvalidity']	= $folderStatus['UIDVALIDITY'];
1313
+			$retValue['uidnext'] = $folderStatus['UIDNEXT'];
1314
+			$retValue['uidvalidity'] = $folderStatus['UIDVALIDITY'];
1315 1315
 			$retValue['unseen']		= $folderStatus['UNSEEN'];
1316 1316
 			if (//$retValue['unseen']==0 &&
1317 1317
 				(isset($this->mailPreferences['trustServersUnseenInfo']) && // some servers dont serve the UNSEEN information
1318
-				$this->mailPreferences['trustServersUnseenInfo']==false) ||
1318
+				$this->mailPreferences['trustServersUnseenInfo'] == false) ||
1319 1319
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1320
-				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1321
-				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1320
+				$this->mailPreferences['trustServersUnseenInfo'] == 2 &&
1321
+				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName, $prefix[$this->profileID][$_folderName]) !== false)
1322 1322
 			)
1323 1323
 			{
1324 1324
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1325 1325
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1326 1326
 				try
1327 1327
 				{
1328
-					$byUid=true;
1329
-					$_reverse=1;
1330
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse, array('status'=>array('UNSEEN','UNDELETED')),$byUid,false);
1328
+					$byUid = true;
1329
+					$_reverse = 1;
1330
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid, false);
1331 1331
 					$retValue['unseen'] = $sortResult['count'];
1332 1332
 				}
1333 1333
 				catch (\Exception $ee)
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 		}
1339 1339
 		catch (\Exception $e)
1340 1340
 		{
1341
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1341
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1342 1342
 		}
1343 1343
 
1344 1344
 		return $retValue;
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
 	 * @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))
1361 1361
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1362 1362
 	 */
1363
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1363
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true, $_fetchPreviews = false)
1364 1364
 	{
1365 1365
 		//self::$debug=true;
1366 1366
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 		$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
1374 1374
 		#print "<pre>";
1375 1375
 		#$this->icServer->setDebug(true);
1376
-		$total=0;
1376
+		$total = 0;
1377 1377
 		if ($_thisUIDOnly === null)
1378 1378
 		{
1379 1379
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1386,24 +1386,24 @@  discard block
 block discarded – undo
1386 1386
 				//$_filter['range'] ="$_startMessage:*";
1387 1387
 			}
1388 1388
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1389
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1389
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1390 1390
 			//see this example below for a 12 week datefilter (since)
1391 1391
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1392 1392
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1393 1393
 			$sortResult = $_sortResult['match']->ids;
1394 1394
 			//$modseq = $_sortResult['modseq'];
1395 1395
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1396
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1396
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1397 1397
 
1398 1398
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1399 1399
 			#$this->icServer->setDebug(false);
1400 1400
 			#print "</pre>";
1401 1401
 			// nothing found
1402
-			if(!is_array($sortResult) || empty($sortResult)) {
1402
+			if (!is_array($sortResult) || empty($sortResult)) {
1403 1403
 				$retValue = array();
1404 1404
 				$retValue['info']['total']	= 0;
1405 1405
 				$retValue['info']['first']	= 0;
1406
-				$retValue['info']['last']	= 0;
1406
+				$retValue['info']['last'] = 0;
1407 1407
 				return $retValue;
1408 1408
 			}
1409 1409
 
@@ -1411,54 +1411,54 @@  discard block
 block discarded – undo
1411 1411
 			#_debug_array($sortResult);
1412 1412
 			#_debug_array(array_slice($sortResult, -5, -2));
1413 1413
 			//error_log("REVERSE: $reverse");
1414
-			if($reverse === true) {
1415
-				if  ($_startMessage<=$total)
1414
+			if ($reverse === true) {
1415
+				if ($_startMessage <= $total)
1416 1416
 				{
1417
-					$startMessage = $_startMessage-1;
1417
+					$startMessage = $_startMessage - 1;
1418 1418
 				}
1419 1419
 				else
1420 1420
 				{
1421 1421
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1422
-					if ($_startMessage+$_numberOfMessages>$total)
1422
+					if ($_startMessage + $_numberOfMessages > $total)
1423 1423
 					{
1424
-						$numberOfMessages = $total%$_numberOfMessages;
1424
+						$numberOfMessages = $total % $_numberOfMessages;
1425 1425
 						//$numberOfMessages = abs($_startMessage-$total-1);
1426
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1426
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1427 1427
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1428 1428
 					}
1429
-					$startMessage=($total-$_numberOfMessages)-1;
1429
+					$startMessage = ($total - $_numberOfMessages) - 1;
1430 1430
 					//$retValue['info']['first'] = $startMessage;
1431 1431
 					//$retValue['info']['last'] = $total;
1432 1432
 
1433 1433
 				}
1434
-				if ($startMessage+$_numberOfMessages>$total)
1434
+				if ($startMessage + $_numberOfMessages > $total)
1435 1435
 				{
1436
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1436
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1437 1437
 					//$retValue['info']['first'] = $startMessage;
1438 1438
 					//$retValue['info']['last'] = $total;
1439 1439
 				}
1440
-				if($startMessage > 0) {
1441
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1442
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1440
+				if ($startMessage > 0) {
1441
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1442
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1443 1443
 				} else {
1444
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1445
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1444
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1445
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1446 1446
 				}
1447 1447
 				$sortResult = array_reverse($sortResult);
1448 1448
 			} else {
1449
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1450
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1449
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1450
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1451 1451
 			}
1452 1452
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1453 1453
 		}
1454 1454
 		else
1455 1455
 		{
1456
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1456
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1457 1457
 		}
1458 1458
 
1459 1459
 
1460 1460
 		// fetch the data for the selected messages
1461
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1461
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1462 1462
 		try
1463 1463
 		{
1464 1464
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1467,22 +1467,22 @@  discard block
 block discarded – undo
1467 1467
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1468 1468
 
1469 1469
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1470
-			$fquery->headers('fetchHeaders',array(
1471
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1472
-				'DATE','SUBJECT','FROM','TO','CC','REPLY-TO',
1470
+			$fquery->headers('fetchHeaders', array(
1471
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1472
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC', 'REPLY-TO',
1473 1473
 				'X-PRIORITY'
1474
-			),array(
1474
+			), array(
1475 1475
 				// Cache headers, we'll look at them below
1476
-				'cache' => true,//$_cacheResult,
1476
+				'cache' => true, //$_cacheResult,
1477 1477
 				// Set peek so messages are not flagged as read
1478 1478
 				'peek' => true
1479 1479
 			));
1480 1480
 			$fquery->size();
1481 1481
 			$fquery->structure();
1482 1482
 			$fquery->flags();
1483
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1483
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1484 1484
 			// if $_fetchPreviews is activated fetch part of the messages too
1485
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1485
+			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true, 'length'=>((int)$_fetchPreviews < 5000 ? 5000 : $_fetchPreviews), 'start'=>0));
1486 1486
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1487 1487
 				'ids' => $uidsToFetch,
1488 1488
 			));
@@ -1493,9 +1493,9 @@  discard block
 block discarded – undo
1493 1493
 			$headersNew = array();
1494 1494
 			$sortResult = array();
1495 1495
 		}
1496
-		if (self::$debug||self::$debugTimes)
1496
+		if (self::$debug || self::$debugTimes)
1497 1497
 		{
1498
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1498
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1499 1499
 			if (self::$debug)
1500 1500
 			{
1501 1501
 				$queryString = implode(',', $sortResult);
@@ -1505,27 +1505,27 @@  discard block
 block discarded – undo
1505 1505
 
1506 1506
 		$cnt = 0;
1507 1507
 
1508
-		foreach((array)$sortResult as $uid) {
1508
+		foreach ((array)$sortResult as $uid) {
1509 1509
 			$sortOrder[$uid] = $cnt++;
1510 1510
 		}
1511 1511
 
1512 1512
 		$count = 0;
1513 1513
 		if (is_object($headersNew)) {
1514
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1515
-			foreach($headersNew->ids() as $id) {
1514
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1515
+			foreach ($headersNew->ids() as $id) {
1516 1516
 				$_headerObject = $headersNew->get($id);
1517 1517
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1518 1518
 				$headerObject = array();
1519 1519
 				$bodyPreview = null;
1520
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1520
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1521 1521
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1522 1522
 				$headerObject['SIZE'] = $_headerObject->getSize();
1523 1523
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1524 1524
 
1525 1525
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1526
-				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1526
+				$headerForPrio = $_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1527 1527
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1528
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1528
+				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1529 1529
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1530 1530
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1531 1531
 				if ($_fetchPreviews)
@@ -1533,16 +1533,16 @@  discard block
 block discarded – undo
1533 1533
 					// on enabled preview $bodyPreview is needed lateron. fetched here, for fallback-reasons
1534 1534
 					// in case of failed Header-Retrieval
1535 1535
 					$bodyPreview = $_headerObject->getFullMsg();
1536
-					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1536
+					if (empty($headerForPrio) || (is_array($headerForPrio) && count($headerForPrio) === 1 && $headerForPrio['']))
1537 1537
 					{
1538 1538
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1539
-						if ($length===false) $length = strlen($bodyPreview);
1540
-						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1539
+						if ($length === false) $length = strlen($bodyPreview);
1540
+						$headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0, $length))->toArray();
1541 1541
 					}
1542 1542
 				}
1543 1543
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1544 1544
 				if (self::$debug) {
1545
-					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'));
1545
+					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'));
1546 1546
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1547 1547
 				}
1548 1548
 				// message deleted from server but cache still reporting its existence ; may happen on QRESYNC with No permanent modsequences
@@ -1551,22 +1551,22 @@  discard block
 block discarded – undo
1551 1551
 					$total--;
1552 1552
 					continue;
1553 1553
 				}
1554
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1554
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1555 1555
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1556
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1556
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1557 1557
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1558
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1558
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1559 1559
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1560 1560
 				} /*else $sent_not = "";*/
1561 1561
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1562 1562
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1563
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1564
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1563
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1564
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1565 1565
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1566
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1567
-				$headerObject['REPLY-TO'] = isset($headerForPrio['REPLY-TO'])?(array)$headerForPrio['REPLY-TO']:array();
1568
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1569
-				foreach (array('FROM','TO','CC','REPLY-TO') as $key)
1566
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1567
+				$headerObject['REPLY-TO'] = isset($headerForPrio['REPLY-TO']) ? (array)$headerForPrio['REPLY-TO'] : array();
1568
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1569
+				foreach (array('FROM', 'TO', 'CC', 'REPLY-TO') as $key)
1570 1570
 				{
1571 1571
 					$address = array();
1572 1572
 					foreach ($headerObject[$key] as $k => $ad)
@@ -1588,13 +1588,13 @@  discard block
 block discarded – undo
1588 1588
 						foreach ($rfcAddr as $_rfcAddr)
1589 1589
 						{
1590 1590
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1591
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1591
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1592 1592
 						}
1593 1593
 					}
1594 1594
 					$headerObject[$key] = $address;
1595 1595
 				}
1596 1596
 				$headerObject['FLAGS'] = $_headerObject->getFlags();
1597
-				$headerObject['BODYPREVIEW']=null;
1597
+				$headerObject['BODYPREVIEW'] = null;
1598 1598
 				// this section fetches part of the message-body (if enabled) for some kind of preview
1599 1599
 				// if we fail to succeed, we fall back to the retrieval of the message-body with
1600 1600
 				// fetchPartContents (see below, when we iterate over the structure to determine the
@@ -1606,17 +1606,17 @@  discard block
 block discarded – undo
1606 1606
 					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1607 1607
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1608 1608
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1609
-					foreach($base->partIterator() as $part)
1609
+					foreach ($base->partIterator() as $part)
1610 1610
 					{
1611 1611
 						//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
1612
-						if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
1612
+						if (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'text')
1613 1613
 						{
1614 1614
 							$charset = $part->getContentTypeParameter('charset');
1615 1615
 							$buffer = Mail\Html::convertHTMLToText($part->toString(array(
1616
-												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1616
+												'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
1617 1617
 											)), $charset, 'utf-8');
1618
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1619
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1618
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Translation::convert_jsonsafe($buffer), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1619
+						} elseif (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'multipart')
1620 1620
 						{
1621 1621
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1622 1622
 						}
@@ -1627,12 +1627,12 @@  discard block
 block discarded – undo
1627 1627
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1628 1628
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1629 1629
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1630
-				$headerObject['ATTACHMENTS']=null;
1631
-				$skipParts=array();
1632
-				$messageMimeType='';
1630
+				$headerObject['ATTACHMENTS'] = null;
1631
+				$skipParts = array();
1632
+				$messageMimeType = '';
1633 1633
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1634 1634
 				{
1635
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1635
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1636 1636
 					$part = $mailStructureObject->getPart($mime_id);
1637 1637
 					$partdisposition = $part->getDisposition();
1638 1638
 					$partPrimaryType = $part->getPrimaryType();
@@ -1640,16 +1640,16 @@  discard block
 block discarded – undo
1640 1640
 					// drawback here it is talking to the mailserver for each mail thus consuming
1641 1641
 					// more time than expected; so we call this section only when there is no
1642 1642
 					// bodypreview could be found (multipart/....)
1643
-					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1643
+					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW']) && ($partPrimaryType == 'text') &&
1644 1644
 						((intval($mime_id) === 1) || !$mime_id) &&
1645 1645
 						($partdisposition !== 'attachment')) {
1646
-							$_structure=$part;
1647
-							$this->fetchPartContents($uid, $_structure, false,true);
1648
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1649
-							$charSet=Translation::detect_encoding($headerObject['BODYPREVIEW']);
1646
+							$_structure = $part;
1647
+							$this->fetchPartContents($uid, $_structure, false, true);
1648
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1649
+							$charSet = Translation::detect_encoding($headerObject['BODYPREVIEW']);
1650 1650
 							// add line breaks to $bodyParts
1651 1651
 							//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
1652
-							$headerObject['BODYPREVIEW']  = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1652
+							$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1653 1653
 							//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
1654 1654
 					}
1655 1655
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
@@ -1659,28 +1659,28 @@  discard block
 block discarded – undo
1659 1659
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1660 1660
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1661 1661
 						// as attachment in order to not loose/miss information on our data
1662
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1662
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1663 1663
 					}
1664
-					if ($mime_type=='message/rfc822')
1664
+					if ($mime_type == 'message/rfc822')
1665 1665
 					{
1666 1666
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1667
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1667
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1668 1668
 					}
1669 1669
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1670
-					if (array_key_exists($mime_id,$skipParts)) continue;
1671
-					if ($partdisposition=='attachment' ||
1672
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1673
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1674
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1670
+					if (array_key_exists($mime_id, $skipParts)) continue;
1671
+					if ($partdisposition == 'attachment' ||
1672
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1673
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1674
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1675 1675
 					{
1676
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1677
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1678
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1676
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1677
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1678
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1679 1679
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1680
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1681
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1682
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1683
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1680
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1681
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1682
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1683
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1684 1684
 						{
1685 1685
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1686 1686
 						}
@@ -1695,57 +1695,57 @@  discard block
 block discarded – undo
1695 1695
 				if (empty($headerObject['UID'])) continue;
1696 1696
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1697 1697
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1698
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1698
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1699 1699
 					$headerObject['DATE'] .= 'C';
1700 1700
 				}
1701
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1701
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1702 1702
 					$headerObject['INTERNALDATE'] .= 'C';
1703 1703
 				}
1704 1704
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1705 1705
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1706
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1707
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1708
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1709
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1710
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1711
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1712
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1713
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1714
-				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1715
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1706
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1707
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1708
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1709
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1710
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1711
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1712
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1713
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1714
+				$retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW'];
1715
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1716 1716
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1717 1717
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1718 1718
 				if (is_array($headerObject['FLAGS'])) {
1719
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1719
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1720 1720
 				}
1721 1721
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1722
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1723
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1722
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1723
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1724 1724
 				}
1725
-				if(is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) {
1726
-					$retValue['header'][$sortOrder[$uid]]['reply_to_address'] = self::decode_header($headerObject['REPLY-TO'][0],true);
1725
+				if (is_array($headerObject['REPLY-TO']) && $headerObject['REPLY-TO'][0]) {
1726
+					$retValue['header'][$sortOrder[$uid]]['reply_to_address'] = self::decode_header($headerObject['REPLY-TO'][0], true);
1727 1727
 				}
1728
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1729
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1730
-					if (count($headerObject['TO'])>1)
1728
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1729
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1730
+					if (count($headerObject['TO']) > 1)
1731 1731
 					{
1732
-						$ki=0;
1733
-						foreach($headerObject['TO'] as $k => $add)
1732
+						$ki = 0;
1733
+						foreach ($headerObject['TO'] as $k => $add)
1734 1734
 						{
1735
-							if ($k==0) continue;
1735
+							if ($k == 0) continue;
1736 1736
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1737
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1737
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1738 1738
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1739 1739
 							$ki++;
1740 1740
 						}
1741 1741
 					}
1742 1742
 				}
1743
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1744
-					$ki=0;
1745
-					foreach($headerObject['CC'] as $k => $add)
1743
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1744
+					$ki = 0;
1745
+					foreach ($headerObject['CC'] as $k => $add)
1746 1746
 					{
1747 1747
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1748
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1748
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1749 1749
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1750 1750
 						$ki++;
1751 1751
 					}
@@ -1754,27 +1754,27 @@  discard block
 block discarded – undo
1754 1754
 
1755 1755
 				$count++;
1756 1756
 			}
1757
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1757
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1758 1758
 			//self::$debug=false;
1759 1759
 			// sort the messages to the requested displayorder
1760
-			if(is_array($retValue['header'])) {
1760
+			if (is_array($retValue['header'])) {
1761 1761
 				$countMessages = $total;
1762 1762
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1763 1763
 				ksort($retValue['header']);
1764 1764
 				$retValue['info']['total']	= $total;
1765 1765
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1766 1766
 				$retValue['info']['first']	= $_startMessage;
1767
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1767
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1768 1768
 				return $retValue;
1769 1769
 			} else {
1770 1770
 				$retValue = array();
1771 1771
 				$retValue['info']['total']	= 0;
1772 1772
 				$retValue['info']['first']	= 0;
1773
-				$retValue['info']['last']	= 0;
1773
+				$retValue['info']['last'] = 0;
1774 1774
 				return $retValue;
1775 1775
 			}
1776 1776
 		} else {
1777
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1777
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1778 1778
 			$retValue = array();
1779 1779
 			$retValue['info']['total']  = 0;
1780 1780
 			$retValue['info']['first']  = 0;
@@ -1791,17 +1791,17 @@  discard block
 block discarded – undo
1791 1791
 	 */
1792 1792
 	static function prepareFlagsArray($headerObject)
1793 1793
 	{
1794
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1794
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1795 1795
 		$retValue = array();
1796 1796
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1797 1797
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1798
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1799
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1798
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1799
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1800 1800
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1801
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1802
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1803
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1804
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1801
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1802
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1803
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1804
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1805 1805
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1806 1806
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1807 1807
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1825,12 +1825,12 @@  discard block
 block discarded – undo
1825 1825
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1826 1826
 	 * @return mixed bool/array false or array of ids
1827 1827
 	 */
1828
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1828
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1829 1829
 	{
1830 1830
 		static $cachedFolderStatus = null;
1831 1831
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1832 1832
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1833
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1833
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1834 1834
 		{
1835 1835
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1836 1836
 		}
@@ -1842,29 +1842,29 @@  discard block
 block discarded – undo
1842 1842
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1843 1843
 		$try2useCache = true;
1844 1844
 		static $eMailListContainsDeletedMessages = null;
1845
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1845
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1846 1846
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1847
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1847
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1848 1848
 		{
1849 1849
 			if (self::$debugTimes) $starttime = microtime(true);
1850
-			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);
1851
-			$five=true;
1852
-			$dReverse=1;
1853
-			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')),$five,false);
1850
+			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);
1851
+			$five = true;
1852
+			$dReverse = 1;
1853
+			$deletedMessages = $this->getSortedList($_folderName, 0, $dReverse, array('status'=>array('DELETED')), $five, false);
1854 1854
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1855
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1856
-			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1857
-			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']);
1855
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1856
+			Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1857
+			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']);
1858 1858
 		}
1859 1859
 		$try2useCache = false;
1860 1860
 		//self::$supportsORinQuery[$this->profileID]=true;
1861 1861
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1862 1862
 		{
1863
-			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1864
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1863
+			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1864
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1865 1865
 		}
1866 1866
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1867
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1867
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1868 1868
 		if (self::$debug)
1869 1869
 		{
1870 1870
 			$query_str = $filter->build();
@@ -1872,14 +1872,14 @@  discard block
 block discarded – undo
1872 1872
 		}
1873 1873
 		//_debug_array($filter);
1874 1874
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1875
-		if($this->icServer->hasCapability('SORT')) {
1875
+		if ($this->icServer->hasCapability('SORT')) {
1876 1876
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1877 1877
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1878 1878
 			// there is no messing with the dates)
1879 1879
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1880 1880
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1881 1881
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1882
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1882
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1883 1883
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1884 1884
 			try
1885 1885
 			{
@@ -1893,24 +1893,24 @@  discard block
 block discarded – undo
1893 1893
 
1894 1894
 			// if there is an Error, we assume that the server is not capable of sorting
1895 1895
 			}
1896
-			catch(\Exception $e)
1896
+			catch (\Exception $e)
1897 1897
 			{
1898 1898
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1899 1899
 				$resultByUid = false;
1900 1900
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1901
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1901
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1902 1902
 				try
1903 1903
 				{
1904 1904
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1905 1905
 						'sort' => $sortOrder));
1906 1906
 				}
1907
-				catch(\Exception $e)
1907
+				catch (\Exception $e)
1908 1908
 				{
1909 1909
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1910 1910
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1911 1911
 				}
1912 1912
 			}
1913
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1913
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1914 1914
 		} else {
1915 1915
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1916 1916
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1920,12 +1920,12 @@  discard block
 block discarded – undo
1920 1920
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1921 1921
 					'sort' => $sortOrder)*/);
1922 1922
 			}
1923
-			catch(\Exception $e)
1923
+			catch (\Exception $e)
1924 1924
 			{
1925 1925
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1926 1926
 				// possible error OR Query. But Horde gives no detailed Info :-(
1927
-				self::$supportsORinQuery[$this->profileID]=false;
1928
-				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1927
+				self::$supportsORinQuery[$this->profileID] = false;
1928
+				Cache::setCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1929 1929
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1930 1930
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1931 1931
 				try
@@ -1933,25 +1933,25 @@  discard block
 block discarded – undo
1933 1933
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1934 1934
 						'sort' => $sortOrder)*/);
1935 1935
 				}
1936
-				catch(\Exception $e)
1936
+				catch (\Exception $e)
1937 1937
 				{
1938 1938
 				}
1939 1939
 			}
1940
-			if(is_array($sortResult['match'])) {
1940
+			if (is_array($sortResult['match'])) {
1941 1941
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1942 1942
 					sort($sortResult['match'], SORT_NUMERIC);
1943 1943
 			}
1944
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1944
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1945 1945
 		}
1946 1946
 		if ($setSession)
1947 1947
 		{
1948 1948
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1949
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1949
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1950 1950
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1951 1951
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1952
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1952
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1953 1953
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1954
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1954
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1955 1955
 		}
1956 1956
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1957 1957
 		//_debug_array($sortResult['match']->ids);
@@ -1965,12 +1965,12 @@  discard block
 block discarded – undo
1965 1965
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1966 1966
 	 * @return the sort sequence for horde search
1967 1967
 	 */
1968
-	function _getSortString($_sort, $_reverse=false)
1968
+	function _getSortString($_sort, $_reverse = false)
1969 1969
 	{
1970
-		$_reverse=false;
1970
+		$_reverse = false;
1971 1971
 		if (is_numeric($_sort))
1972 1972
 		{
1973
-			switch($_sort) {
1973
+			switch ($_sort) {
1974 1974
 				case 2:
1975 1975
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1976 1976
 					break;
@@ -1992,7 +1992,7 @@  discard block
 block discarded – undo
1992 1992
 		}
1993 1993
 		else
1994 1994
 		{
1995
-			switch(strtoupper($_sort)) {
1995
+			switch (strtoupper($_sort)) {
1996 1996
 				case 'FROMADDRESS':
1997 1997
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1998 1998
 					break;
@@ -2018,7 +2018,7 @@  discard block
 block discarded – undo
2018 2018
 					break;
2019 2019
 			}
2020 2020
 		}
2021
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2021
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
2022 2022
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
2023 2023
 		return $retValue;
2024 2024
 	}
@@ -2031,28 +2031,28 @@  discard block
 block discarded – undo
2031 2031
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
2032 2032
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
2033 2033
 	 */
2034
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
2034
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
2035 2035
 	{
2036 2036
 		$imapFilter = new Horde_Imap_Client_Search_Query();
2037 2037
 		$imapFilter->charset('UTF-8');
2038 2038
 
2039 2039
 		//_debug_array($_criterias);
2040
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2041
-		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2040
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
2041
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') &&
2042 2042
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2043
-			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
2044
-			( !empty($_criterias['range'])&& ($_criterias['range']!='BETWEEN' && empty($_criterias['date'])||
2045
-			($_criterias['range']=='BETWEEN' && empty($_criterias['since'])&& empty($_criterias['before']))))))
2043
+			(!isset($_criterias['range']) || empty($_criterias['range']) ||
2044
+			(!empty($_criterias['range']) && ($_criterias['range'] != 'BETWEEN' && empty($_criterias['date']) ||
2045
+			($_criterias['range'] == 'BETWEEN' && empty($_criterias['since']) && empty($_criterias['before']))))))
2046 2046
 		{
2047 2047
 			//error_log(__METHOD__.' ('.__LINE__.') returning early Criterias:'.print_r($_criterias, true));
2048
-			$imapFilter->flag('DELETED', $set=false);
2048
+			$imapFilter->flag('DELETED', $set = false);
2049 2049
 			return $imapFilter;
2050 2050
 		}
2051 2051
 		$queryValid = false;
2052 2052
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2053 2053
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2054 2054
 		$statusQueryValid = false;
2055
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2055
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
2056 2056
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2057 2057
 			$imapStatusFilter->charset('UTF-8');
2058 2058
 			$criteria = strtoupper($criteria);
@@ -2062,12 +2062,12 @@  discard block
 block discarded – undo
2062 2062
 				case 'FLAGGED':
2063 2063
 				case 'RECENT':
2064 2064
 				case 'SEEN':
2065
-					$imapStatusFilter->flag($criteria, $set=true);
2066
-					$queryValid = $statusQueryValid =true;
2065
+					$imapStatusFilter->flag($criteria, $set = true);
2066
+					$queryValid = $statusQueryValid = true;
2067 2067
 					break;
2068 2068
 				case 'READ':
2069
-					$imapStatusFilter->flag('SEEN', $set=true);
2070
-					$queryValid = $statusQueryValid =true;
2069
+					$imapStatusFilter->flag('SEEN', $set = true);
2070
+					$queryValid = $statusQueryValid = true;
2071 2071
 					break;
2072 2072
 				case 'LABEL1':
2073 2073
 				case 'KEYWORD1':
@@ -2079,38 +2079,38 @@  discard block
 block discarded – undo
2079 2079
 				case 'KEYWORD4':
2080 2080
 				case 'LABEL5':
2081 2081
 				case 'KEYWORD5':
2082
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
2083
-					$queryValid = $statusQueryValid =true;
2082
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
2083
+					$queryValid = $statusQueryValid = true;
2084 2084
 					break;
2085 2085
 				case 'NEW':
2086
-					$imapStatusFilter->flag('RECENT', $set=true);
2087
-					$imapStatusFilter->flag('SEEN', $set=false);
2088
-					$queryValid = $statusQueryValid =true;
2086
+					$imapStatusFilter->flag('RECENT', $set = true);
2087
+					$imapStatusFilter->flag('SEEN', $set = false);
2088
+					$queryValid = $statusQueryValid = true;
2089 2089
 					break;
2090 2090
 				case 'OLD':
2091
-					$imapStatusFilter->flag('RECENT', $set=false);
2092
-					$queryValid = $statusQueryValid =true;
2091
+					$imapStatusFilter->flag('RECENT', $set = false);
2092
+					$queryValid = $statusQueryValid = true;
2093 2093
 					break;
2094 2094
 // operate only on system flags
2095 2095
 //        $systemflags = array(
2096 2096
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
2097 2097
 //        );
2098 2098
 				case 'UNANSWERED':
2099
-					$imapStatusFilter->flag('ANSWERED', $set=false);
2100
-					$queryValid = $statusQueryValid =true;
2099
+					$imapStatusFilter->flag('ANSWERED', $set = false);
2100
+					$queryValid = $statusQueryValid = true;
2101 2101
 					break;
2102 2102
 				case 'UNDELETED':
2103
-					$imapFilter->flag('DELETED', $set=false);
2103
+					$imapFilter->flag('DELETED', $set = false);
2104 2104
 					$queryValid = true;
2105 2105
 					break;
2106 2106
 				case 'UNFLAGGED':
2107
-					$imapStatusFilter->flag('FLAGGED', $set=false);
2108
-					$queryValid = $statusQueryValid =true;
2107
+					$imapStatusFilter->flag('FLAGGED', $set = false);
2108
+					$queryValid = $statusQueryValid = true;
2109 2109
 					break;
2110 2110
 				case 'UNREAD':
2111 2111
 				case 'UNSEEN':
2112
-					$imapStatusFilter->flag('SEEN', $set=false);
2113
-					$queryValid = $statusQueryValid =true;
2112
+					$imapStatusFilter->flag('SEEN', $set = false);
2113
+					$queryValid = $statusQueryValid = true;
2114 2114
 					break;
2115 2115
 				case 'UNLABEL1':
2116 2116
 				case 'UNKEYWORD1':
@@ -2122,8 +2122,8 @@  discard block
 block discarded – undo
2122 2122
 				case 'UNKEYWORD4':
2123 2123
 				case 'UNLABEL5':
2124 2124
 				case 'UNKEYWORD5':
2125
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
2126
-					$queryValid = $statusQueryValid =true;
2125
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
2126
+					$queryValid = $statusQueryValid = true;
2127 2127
 					break;
2128 2128
 				default:
2129 2129
 					$statusQueryValid = false;
@@ -2139,20 +2139,20 @@  discard block
 block discarded – undo
2139 2139
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2140 2140
 		$imapSearchFilter->charset('UTF-8');
2141 2141
 
2142
-		if(!empty($_criterias['string'])) {
2142
+		if (!empty($_criterias['string'])) {
2143 2143
 			$criteria = strtoupper($_criterias['type']);
2144 2144
 			switch ($criteria) {
2145 2145
 				case 'BYDATE':
2146 2146
 				case 'QUICK':
2147 2147
 				case 'QUICKWITHCC':
2148
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
2148
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
2149 2149
 					//$imapSearchFilter->charset('UTF-8');
2150 2150
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2151 2151
 					$imapFilter2->charset('UTF-8');
2152
-					if($this->isSentFolder($_folder)) {
2153
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2152
+					if ($this->isSentFolder($_folder)) {
2153
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
2154 2154
 					} else {
2155
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2155
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
2156 2156
 					}
2157 2157
 					if ($_supportsOrInQuery)
2158 2158
 					{
@@ -2162,31 +2162,31 @@  discard block
 block discarded – undo
2162 2162
 					{
2163 2163
 						$imapSearchFilter->andSearch($imapFilter2);
2164 2164
 					}
2165
-					if ($_supportsOrInQuery && $criteria=='QUICKWITHCC')
2165
+					if ($_supportsOrInQuery && $criteria == 'QUICKWITHCC')
2166 2166
 					{
2167 2167
 						$imapFilter3 = new Horde_Imap_Client_Search_Query();
2168 2168
 						$imapFilter3->charset('UTF-8');
2169
-						$imapFilter3->headerText('CC', $_criterias['string'], $not=false);
2169
+						$imapFilter3->headerText('CC', $_criterias['string'], $not = false);
2170 2170
 						$imapSearchFilter->orSearch($imapFilter3);
2171 2171
 					}
2172 2172
 					$queryValid = true;
2173 2173
 					break;
2174 2174
 				case 'LARGER':
2175 2175
 				case 'SMALLER':
2176
-					if (strlen(trim($_criterias['string'])) != strlen((float) trim($_criterias['string'])))
2176
+					if (strlen(trim($_criterias['string'])) != strlen((float)trim($_criterias['string'])))
2177 2177
 					{
2178 2178
 						//examine string to evaluate size
2179
-						$unit = strtoupper(trim(substr(trim($_criterias['string']),strlen((float) trim($_criterias['string'])))));
2180
-						$multipleBy = array('KB'=>1024,'K'=>1024,
2181
-											'MB'=>1024*1000,'M'=>1024*1000,
2182
-											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2183
-											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2184
-						$numberinBytes=(float)$_criterias['string'];
2185
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2179
+						$unit = strtoupper(trim(substr(trim($_criterias['string']), strlen((float)trim($_criterias['string'])))));
2180
+						$multipleBy = array('KB'=>1024, 'K'=>1024,
2181
+											'MB'=>1024 * 1000, 'M'=>1024 * 1000,
2182
+											'GB'=>1024 * 1000 * 1000, 'G'=>1024 * 1000 * 1000,
2183
+											'TB'=>1024 * 1000 * 1000 * 1000, 'T'=>1024 * 1000 * 1000 * 1000);
2184
+						$numberinBytes = (float)$_criterias['string'];
2185
+						if (isset($multipleBy[$unit])) $numberinBytes = (float)$_criterias['string'] * $multipleBy[$unit];
2186 2186
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2187
-						$_criterias['string']=$numberinBytes;
2187
+						$_criterias['string'] = $numberinBytes;
2188 2188
 					}
2189
-					$imapSearchFilter->size( $_criterias['string'], ($criteria=='LARGER'?true:false), $not=false);
2189
+					$imapSearchFilter->size($_criterias['string'], ($criteria == 'LARGER' ?true:false), $not = false);
2190 2190
 					//$imapSearchFilter->charset('UTF-8');
2191 2191
 					$queryValid = true;
2192 2192
 					break;
@@ -2195,31 +2195,31 @@  discard block
 block discarded – undo
2195 2195
 				case 'CC':
2196 2196
 				case 'BCC':
2197 2197
 				case 'SUBJECT':
2198
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
2198
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
2199 2199
 					//$imapSearchFilter->charset('UTF-8');
2200 2200
 					$queryValid = true;
2201 2201
 					break;
2202 2202
 				case 'BODY':
2203 2203
 				case 'TEXT':
2204
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2204
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ?true:false), $not = false);
2205 2205
 					//$imapSearchFilter->charset('UTF-8');
2206 2206
 					$queryValid = true;
2207 2207
 					break;
2208 2208
 				case 'SINCE':
2209
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2209
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2210 2210
 					$queryValid = true;
2211 2211
 					break;
2212 2212
 				case 'BEFORE':
2213
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2213
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2214 2214
 					$queryValid = true;
2215 2215
 					break;
2216 2216
 				case 'ON':
2217
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2217
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2218 2218
 					$queryValid = true;
2219 2219
 					break;
2220 2220
 			}
2221 2221
 		}
2222
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2222
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2223 2223
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2224 2224
 
2225 2225
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2228,12 +2228,12 @@  discard block
 block discarded – undo
2228 2228
 			$imapRangeFilter = new Horde_Imap_Client_Search_Query();
2229 2229
 			$imapRangeFilter->charset('UTF-8');
2230 2230
 			$criteria = strtoupper($_criterias['range']);
2231
-			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since']==$_criterias['before'])
2231
+			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since'] == $_criterias['before'])
2232 2232
 			{
2233
-				$_criterias['date']=$_criterias['since'];
2233
+				$_criterias['date'] = $_criterias['since'];
2234 2234
 				unset($_criterias['since']);
2235 2235
 				unset($_criterias['before']);
2236
-				$criteria=$_criterias['range']='ON';
2236
+				$criteria = $_criterias['range'] = 'ON';
2237 2237
 			}
2238 2238
 			switch ($criteria) {
2239 2239
 				case 'BETWEEN':
@@ -2241,7 +2241,7 @@  discard block
 block discarded – undo
2241 2241
 					//enddate
2242 2242
 					if ($_criterias['since'])
2243 2243
 					{
2244
-						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2244
+						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2245 2245
 						$rangeValid = true;
2246 2246
 					}
2247 2247
 					//startdate
@@ -2250,28 +2250,28 @@  discard block
 block discarded – undo
2250 2250
 						$imapRangeFilter2 = new Horde_Imap_Client_Search_Query();
2251 2251
 						$imapRangeFilter2->charset('UTF-8');
2252 2252
 						//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2253
-						$_criterias['before'] = date("d-M-Y",DateTime::to($_criterias['before'],'ts')+(3600*24));
2254
-						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2253
+						$_criterias['before'] = date("d-M-Y", DateTime::to($_criterias['before'], 'ts') + (3600 * 24));
2254
+						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2255 2255
 						$imapRangeFilter->andSearch($imapRangeFilter2);
2256 2256
 						$rangeValid = true;
2257 2257
 					}
2258 2258
 					break;
2259 2259
 				case 'SINCE'://enddate
2260
-					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since']?$_criterias['since']:$_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2260
+					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since'] ? $_criterias['since'] : $_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2261 2261
 					$rangeValid = true;
2262 2262
 					break;
2263 2263
 				case 'BEFORE'://startdate
2264 2264
 					//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2265
-					$_criterias['before'] = date("d-M-Y",DateTime::to(($_criterias['before']?$_criterias['before']:$_criterias['date']),'ts')+(3600*24));
2266
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2265
+					$_criterias['before'] = date("d-M-Y", DateTime::to(($_criterias['before'] ? $_criterias['before'] : $_criterias['date']), 'ts') + (3600 * 24));
2266
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2267 2267
 					$rangeValid = true;
2268 2268
 					break;
2269 2269
 				case 'ON':
2270
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2270
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2271 2271
 					$rangeValid = true;
2272 2272
 					break;
2273 2273
 			}
2274
-			if ($rangeValid && !$queryValid) $queryValid=true;
2274
+			if ($rangeValid && !$queryValid) $queryValid = true;
2275 2275
 			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2276 2276
 		}
2277 2277
 		if (self::$debug)
@@ -2280,8 +2280,8 @@  discard block
 block discarded – undo
2280 2280
 			$query_str = $imapFilter->build();
2281 2281
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2282 2282
 		}
2283
-		if($queryValid==false) {
2284
-			$imapFilter->flag('DELETED', $set=false);
2283
+		if ($queryValid == false) {
2284
+			$imapFilter->flag('DELETED', $set = false);
2285 2285
 			return $imapFilter;
2286 2286
 		} else {
2287 2287
 			return $imapFilter;
@@ -2295,11 +2295,11 @@  discard block
 block discarded – undo
2295 2295
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2296 2296
 	 * @return mixed - based on the input type
2297 2297
 	 */
2298
-	static function decode_header($_string, $_tryIDNConversion=false)
2298
+	static function decode_header($_string, $_tryIDNConversion = false)
2299 2299
 	{
2300 2300
 		if (is_array($_string))
2301 2301
 		{
2302
-			foreach($_string as $k=>$v)
2302
+			foreach ($_string as $k=>$v)
2303 2303
 			{
2304 2304
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2305 2305
 			}
@@ -2307,18 +2307,18 @@  discard block
 block discarded – undo
2307 2307
 		}
2308 2308
 		else
2309 2309
 		{
2310
-			$_string = Mail\Html::decodeMailHeader($_string,self::$displayCharset);
2310
+			$_string = Mail\Html::decodeMailHeader($_string, self::$displayCharset);
2311 2311
 			$test = @json_encode($_string);
2312 2312
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2313
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2313
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2314 2314
 			{
2315 2315
 				// try to fix broken utf8
2316 2316
 				$x = utf8_encode($_string);
2317 2317
 				$test = @json_encode($x);
2318
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2318
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2319 2319
 				{
2320 2320
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2321
-					$_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));
2321
+					$_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));
2322 2322
 				}
2323 2323
 				else
2324 2324
 				{
@@ -2326,7 +2326,7 @@  discard block
 block discarded – undo
2326 2326
 				}
2327 2327
 			}
2328 2328
 
2329
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2329
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2330 2330
 			{
2331 2331
 				$rfcAddr = self::parseAddressList($_string);
2332 2332
 				$stringA = array();
@@ -2338,11 +2338,11 @@  discard block
 block discarded – undo
2338 2338
 						$stringA = array();
2339 2339
 						break; // skip idna conversion if we encounter an error here
2340 2340
 					}
2341
-					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2341
+					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, Horde_Idna::decode($_rfcAddr->host), $_rfcAddr->personal);
2342 2342
 				}
2343
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2343
+				if (!empty($stringA)) $_string = implode(',', $stringA);
2344 2344
 			}
2345
-			if ($_tryIDNConversion==='FORCE')
2345
+			if ($_tryIDNConversion === 'FORCE')
2346 2346
 			{
2347 2347
 				//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.Horde_Idna::decode($_string));
2348 2348
 				$_string = Horde_Idna::decode($_string);
@@ -2358,17 +2358,17 @@  discard block
 block discarded – undo
2358 2358
 	 * @param  boolean $decode try decoding
2359 2359
 	 * @return mixed - based on the input type
2360 2360
 	 */
2361
-	function decode_subject($_string,$decode=true)
2361
+	function decode_subject($_string, $decode = true)
2362 2362
 	{
2363 2363
 		#$string = $_string;
2364
-		if($_string=='NIL')
2364
+		if ($_string == 'NIL')
2365 2365
 		{
2366 2366
 			return 'No Subject';
2367 2367
 		}
2368 2368
 		if ($decode) $_string = self::decode_header($_string);
2369 2369
 		// make sure its utf-8
2370 2370
 		$test = @json_encode($_string);
2371
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2371
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2372 2372
 		{
2373 2373
 			$_string = utf8_encode($_string);
2374 2374
 		}
@@ -2420,18 +2420,18 @@  discard block
 block discarded – undo
2420 2420
 	function createFolder($_parent, $_folderName, &$_error)
2421 2421
 	{
2422 2422
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2423
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2424
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2423
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2424
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2425 2425
 
2426
-		if(empty($parent)) {
2426
+		if (empty($parent)) {
2427 2427
 			$newFolderName = $folderName;
2428 2428
 		} else {
2429 2429
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2430
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2430
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2431 2431
 		}
2432 2432
 		if (empty($newFolderName)) return false;
2433 2433
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2434
-		if ($this->folderExists($newFolderName,true))
2434
+		if ($this->folderExists($newFolderName, true))
2435 2435
 		{
2436 2436
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2437 2437
 			return $newFolderName;
@@ -2448,7 +2448,7 @@  discard block
 block discarded – undo
2448 2448
 		}
2449 2449
 		catch (\Exception $e)
2450 2450
 		{
2451
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2451
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2452 2452
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2453 2453
 			return false;
2454 2454
 		}
@@ -2477,15 +2477,15 @@  discard block
 block discarded – undo
2477 2477
 	 */
2478 2478
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2479 2479
 	{
2480
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2481
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2482
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2480
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2481
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2482
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2483 2483
 
2484
-		if(empty($parent)) {
2484
+		if (empty($parent)) {
2485 2485
 			$newFolderName = $folderName;
2486 2486
 		} else {
2487 2487
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2488
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2488
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2489 2489
 		}
2490 2490
 		if (self::$debug) error_log("create folder: $newFolderName");
2491 2491
 		try
@@ -2494,10 +2494,10 @@  discard block
 block discarded – undo
2494 2494
 		}
2495 2495
 		catch (\Exception $e)
2496 2496
 		{
2497
-			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2497
+			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2498 2498
 		}
2499 2499
 		// clear FolderExistsInfoCache
2500
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2500
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2501 2501
 
2502 2502
 		return $newFolderName;
2503 2503
 
@@ -2516,15 +2516,15 @@  discard block
 block discarded – undo
2516 2516
 		//$folderName = $this->_encodeFolderName($_folderName);
2517 2517
 		try
2518 2518
 		{
2519
-			$this->icServer->subscribeMailbox($_folderName,false);
2519
+			$this->icServer->subscribeMailbox($_folderName, false);
2520 2520
 			$this->icServer->deleteMailbox($_folderName);
2521 2521
 		}
2522 2522
 		catch (\Exception $e)
2523 2523
 		{
2524
-			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2524
+			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2525 2525
 		}
2526 2526
 		// clear FolderExistsInfoCache
2527
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2527
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2528 2528
 
2529 2529
 		return true;
2530 2530
 	}
@@ -2559,10 +2559,10 @@  discard block
 block discarded – undo
2559 2559
 	 *
2560 2560
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2561 2561
 	 */
2562
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2562
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2563 2563
 	{
2564 2564
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2565
-		if (self::$debugTimes) $starttime = microtime (true);
2565
+		if (self::$debugTimes) $starttime = microtime(true);
2566 2566
 		static $folders2return;
2567 2567
 		//$_subscribedOnly=false;
2568 2568
 		// always use static on single request if info is available;
@@ -2570,42 +2570,42 @@  discard block
 block discarded – undo
2570 2570
 		// set $_useCacheIfPossible to false !
2571 2571
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2572 2572
 		{
2573
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2573
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2574 2574
 			return $folders2return[$this->icServer->ImapServerId];
2575 2575
 		}
2576 2576
 
2577
-		if ($_subscribedOnly && $_getCounters===false)
2577
+		if ($_subscribedOnly && $_getCounters === false)
2578 2578
 		{
2579
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2579
+			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2580 2580
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2581 2581
 			{
2582 2582
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2583
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2583
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2584 2584
 				return $folders2return[$this->icServer->ImapServerId];
2585 2585
 			}
2586 2586
 		}
2587 2587
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2588 2588
 		static $folderBasicInfo;
2589
-		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);
2589
+		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);
2590 2590
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2591 2591
 
2592 2592
 		$delimiter = $this->getHierarchyDelimiter();
2593 2593
 
2594 2594
 		$inboxData = new \stdClass;
2595
-		$inboxData->name 		= 'INBOX';
2595
+		$inboxData->name = 'INBOX';
2596 2596
 		$inboxData->folderName		= 'INBOX';
2597
-		$inboxData->displayName		= lang('INBOX');
2597
+		$inboxData->displayName = lang('INBOX');
2598 2598
 		$inboxData->delimiter 		= $delimiter;
2599
-		$inboxData->shortFolderName	= 'INBOX';
2600
-		$inboxData->shortDisplayName	= lang('INBOX');
2599
+		$inboxData->shortFolderName = 'INBOX';
2600
+		$inboxData->shortDisplayName = lang('INBOX');
2601 2601
 		$inboxData->subscribed = true;
2602
-		if($_getCounters == true) {
2602
+		if ($_getCounters == true) {
2603 2603
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2604 2604
 		}
2605 2605
 		// force unsubscribed by preference showAllFoldersInFolderPane
2606 2606
 		if ($_subscribedOnly == true &&
2607 2607
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2608
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2608
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2609 2609
 		{
2610 2610
 			$_subscribedOnly = false;
2611 2611
 		}
@@ -2618,12 +2618,12 @@  discard block
 block discarded – undo
2618 2618
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2619 2619
 		if (is_array($nameSpace))
2620 2620
 		{
2621
-			foreach($nameSpace as $k => $singleNameSpace) {
2621
+			foreach ($nameSpace as $k => $singleNameSpace) {
2622 2622
 				$type = $singleNameSpace['type'];
2623 2623
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2624
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2624
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2625 2625
 
2626
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2626
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2627 2627
 					// fetch and sort the subscribed folders
2628 2628
 					// we alway fetch the subscribed, as this provides the only way to tell
2629 2629
 					// if a folder is subscribed or not
@@ -2631,22 +2631,22 @@  discard block
 block discarded – undo
2631 2631
 					{
2632 2632
 						try
2633 2633
 						{
2634
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2634
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2635 2635
 							if (!empty($subscribedMailboxes))
2636 2636
 							{
2637 2637
 								$fetchedAllInOneGo = true;
2638 2638
 							}
2639 2639
 							else
2640 2640
 							{
2641
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2641
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2642 2642
 							}
2643 2643
 						}
2644
-						catch(Exception $e)
2644
+						catch (Exception $e)
2645 2645
 						{
2646 2646
 							continue;
2647 2647
 						}
2648 2648
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2649
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2649
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ?array_keys($subscribedMailboxes) : array());
2650 2650
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2651 2651
 						//_debug_array($foldersNameSpace);
2652 2652
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2656,18 +2656,18 @@  discard block
 block discarded – undo
2656 2656
 							foreach ($subscribedMailboxes as $k => $finfo)
2657 2657
 							{
2658 2658
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2659
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2660
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2659
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2660
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2661 2661
 									'MAILBOX'=>$finfo['MAILBOX'],
2662 2662
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2663
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2664
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2663
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2664
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2665 2665
 								);
2666
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2666
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2667 2667
 								{
2668 2668
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2669 2669
 								}
2670
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2670
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2671 2671
 								{
2672 2672
 									$foldersNameSpace[$type]['all'][] = $k;
2673 2673
 								}
@@ -2690,7 +2690,7 @@  discard block
 block discarded – undo
2690 2690
 						// that may produce problems, when encountering recursions probably
2691 2691
 						// horde is handling that, so we do not; keep that in mind!
2692 2692
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2693
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2693
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2694 2694
 					}
2695 2695
 					catch (\Exception $e)
2696 2696
 					{
@@ -2708,26 +2708,26 @@  discard block
 block discarded – undo
2708 2708
 					foreach ($allMailboxesExt as $mbx) {
2709 2709
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2710 2710
 						{
2711
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2711
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2712 2712
 								'MAILBOX'=>$mbx['MAILBOX'],
2713 2713
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2714
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2715
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2714
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2715
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2716 2716
 							);
2717 2717
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2718 2718
 							{
2719 2719
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2720 2720
 							}
2721 2721
 						}
2722
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2722
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2723 2723
 						{
2724 2724
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2725 2725
 						}
2726 2726
 						//echo __METHOD__;_debug_array($mbx);
2727 2727
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2728
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2729
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2730
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2728
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2729
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2730
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2731 2731
 						) continue;
2732 2732
 
2733 2733
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2737,7 +2737,7 @@  discard block
 block discarded – undo
2737 2737
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2738 2738
 					$allMailboxes = array();
2739 2739
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2740
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2740
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2741 2741
 						//echo "Result:";_debug_array($allMailboxes);
2742 2742
 					}
2743 2743
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2746,57 +2746,57 @@  discard block
 block discarded – undo
2746 2746
 			}
2747 2747
 		}
2748 2748
 		//subscribed folders may be used in getFolderStatus
2749
-		Cache::setCache(Cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2749
+		Cache::setCache(Cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2750 2750
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2751 2751
 		$autoFolderObjects = $folders = array();
2752 2752
 		$autofolder_exists = array();
2753
-		foreach( array('personal', 'others', 'shared') as $type) {
2754
-			if(isset($foldersNameSpace[$type])) {
2755
-				if($_subscribedOnly) {
2756
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2753
+		foreach (array('personal', 'others', 'shared') as $type) {
2754
+			if (isset($foldersNameSpace[$type])) {
2755
+				if ($_subscribedOnly) {
2756
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2757 2757
 				} else {
2758
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2758
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2759 2759
 				}
2760
-				foreach((array)$listOfFolders as $folderName) {
2760
+				foreach ((array)$listOfFolders as $folderName) {
2761 2761
 					//echo "<br>FolderToCheck:$folderName<br>";
2762 2762
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2763
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2764
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2763
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2764
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2765 2765
 						#echo "$folderName failed to be here <br>";
2766 2766
 						continue;
2767 2767
 					}
2768 2768
 					if (isset($folders[$folderName])) continue;
2769 2769
 					if (isset($autoFolderObjects[$folderName])) continue;
2770
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2770
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2771 2771
 					$folderParts = explode($delimiter, $folderName);
2772 2772
 					$shortName = array_pop($folderParts);
2773 2773
 
2774 2774
 					$folderObject = new \stdClass;
2775
-					$folderObject->delimiter	= $delimiter;
2776
-					$folderObject->folderName	= $folderName;
2777
-					$folderObject->shortFolderName	= $shortName;
2778
-					if(!$_subscribedOnly) {
2775
+					$folderObject->delimiter = $delimiter;
2776
+					$folderObject->folderName = $folderName;
2777
+					$folderObject->shortFolderName = $shortName;
2778
+					if (!$_subscribedOnly) {
2779 2779
 						#echo $folderName."->".$type."<br>";
2780 2780
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2781 2781
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2782 2782
 					}
2783 2783
 
2784
-					if($_getCounters == true) {
2784
+					if ($_getCounters == true) {
2785 2785
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2786 2786
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2787 2787
 					}
2788
-					if(strtoupper($folderName) == 'INBOX') {
2788
+					if (strtoupper($folderName) == 'INBOX') {
2789 2789
 						$folderName = 'INBOX';
2790
-						$folderObject->folderName	= 'INBOX';
2791
-						$folderObject->shortFolderName	= 'INBOX';
2792
-						$folderObject->displayName	= lang('INBOX');
2790
+						$folderObject->folderName = 'INBOX';
2791
+						$folderObject->shortFolderName = 'INBOX';
2792
+						$folderObject->displayName = lang('INBOX');
2793 2793
 						$folderObject->shortDisplayName = lang('INBOX');
2794
-						$folderObject->subscribed	= true;
2794
+						$folderObject->subscribed = true;
2795 2795
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2796
-					} elseif (in_array($shortName,self::$autoFolders)) {
2797
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2796
+					} elseif (in_array($shortName, self::$autoFolders)) {
2797
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2798 2798
 						array_pop($tmpfolderparts);
2799
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2799
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2800 2800
 						$folderObject->shortDisplayName = lang($shortName);
2801 2801
 						unset($tmpfolderparts);
2802 2802
 					} else {
@@ -2804,13 +2804,13 @@  discard block
 block discarded – undo
2804 2804
 						$folderObject->shortDisplayName = $shortName;
2805 2805
 					}
2806 2806
 					//$folderName = $folderName;
2807
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2807
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2808 2808
 						$autoFolderObjects[$folderName] = $folderObject;
2809 2809
 					} else {
2810 2810
 						$folders[$folderName] = $folderObject;
2811 2811
 					}
2812 2812
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2813
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2813
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2814 2814
 					if (isset(self::$specialUseFolders[$folderName]))
2815 2815
 					{
2816 2816
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2819,27 +2819,27 @@  discard block
 block discarded – undo
2819 2819
 			}
2820 2820
 		}
2821 2821
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2822
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2822
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2823 2823
 		}
2824 2824
 		// check if some standard folders are missing and need to be created
2825 2825
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2826 2826
 		{
2827 2827
 			// if new folders have been created, re-read folders ignoring the cache
2828
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2828
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2829 2829
 		}
2830
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2830
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2831 2831
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2832 2832
 		//_debug_array($folders2return); #exit;
2833
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2834
-		if (($_subscribedOnly && $_getCounters===false) ||
2835
-			($_subscribedOnly == false && $_getCounters===false &&
2833
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2834
+		if (($_subscribedOnly && $_getCounters === false) ||
2835
+			($_subscribedOnly == false && $_getCounters === false &&
2836 2836
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2837
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2837
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2838 2838
 		{
2839
-			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2839
+			Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2840 2840
 		}
2841
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2842
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2841
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2842
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2843 2843
 		return $folders2return[$this->icServer->ImapServerId];
2844 2844
 	}
2845 2845
 
@@ -2860,21 +2860,21 @@  discard block
 block discarded – undo
2860 2860
 	 *
2861 2861
 	 * @return array arrays of folders
2862 2862
 	 */
2863
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2863
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2864 2864
 	{
2865 2865
 		// delimiter
2866 2866
 		$delimiter = $this->getHierarchyDelimiter();
2867 2867
 
2868
-		$folders = $nameSpace =  array();
2868
+		$folders = $nameSpace = array();
2869 2869
 		$nameSpaceTmp = $this->_getNameSpaces();
2870
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2871
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2870
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2871
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2872 2872
 		}
2873 2873
 		unset($nameSpaceTmp);
2874 2874
 
2875 2875
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2876 2876
 		// Get special use folders
2877
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2877
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2878 2878
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2879 2879
 		if ($_onlyTopLevel) // top level leaves
2880 2880
 		{
@@ -2885,20 +2885,20 @@  discard block
 block discarded – undo
2885 2885
 			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
2886 2886
 			if (self::$mailConfig['examineNamespace'])
2887 2887
 			{
2888
-				$prefixes=array();
2888
+				$prefixes = array();
2889 2889
 				if (is_array($nameSpace))
2890 2890
 				{
2891
-					foreach($nameSpace as $k => $singleNameSpace) {
2891
+					foreach ($nameSpace as $k => $singleNameSpace) {
2892 2892
 						$type = $singleNameSpace['type'];
2893 2893
 
2894
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2894
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2895 2895
 							$prefixes[$type] = $singleNameSpace['prefix'];
2896 2896
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2897
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2897
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2898 2898
 							if (is_array($result))
2899 2899
 							{
2900 2900
 								ksort($result);
2901
-								$topFolders = array_merge($topFolders,$result);
2901
+								$topFolders = array_merge($topFolders, $result);
2902 2902
 							}
2903 2903
 						}
2904 2904
 					}
@@ -2907,7 +2907,7 @@  discard block
 block discarded – undo
2907 2907
 
2908 2908
 			$autofolders = array();
2909 2909
 
2910
-			foreach(self::$specialUseFolders as $path => $folder)
2910
+			foreach (self::$specialUseFolders as $path => $folder)
2911 2911
 			{
2912 2912
 				if ($this->folderExists($path))
2913 2913
 				{
@@ -2915,9 +2915,9 @@  discard block
 block discarded – undo
2915 2915
 				}
2916 2916
 			}
2917 2917
 			// Check if the special use folders are there, otherwise try to create them
2918
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2918
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2919 2919
 			{
2920
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2920
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2921 2921
 			}
2922 2922
 
2923 2923
 			// now process topFolders for next level
@@ -2925,13 +2925,13 @@  discard block
 block discarded – undo
2925 2925
 			{
2926 2926
 				$pattern = "/\\".$delimiter."/";
2927 2927
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2928
-				if(!empty($prefixes))
2928
+				if (!empty($prefixes))
2929 2929
 				{
2930 2930
 					$reference = '';
2931
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2932
-					foreach($tmpArray as $p)
2931
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2932
+					foreach ($tmpArray as $p)
2933 2933
 					{
2934
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2934
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2935 2935
 					}
2936 2936
 				}
2937 2937
 				$mainFolder = $subFolders = array();
@@ -2967,19 +2967,19 @@  discard block
 block discarded – undo
2967 2967
 							$nFolders [$path] = $folder;
2968 2968
 						}
2969 2969
 					}
2970
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2970
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2971 2971
 					//ksort($aFolders);
2972 2972
 
2973 2973
 					// Sort none auto folders base on mailbox name
2974
-					uasort($nFolders,array($this,'sortByMailbox'));
2974
+					uasort($nFolders, array($this, 'sortByMailbox'));
2975 2975
 
2976
-					$subFolders = array_merge($aFolders,$nFolders);
2976
+					$subFolders = array_merge($aFolders, $nFolders);
2977 2977
 				}
2978 2978
 				else
2979 2979
 				{
2980 2980
 					if (is_array($subFolders)) ksort($subFolders);
2981 2981
 				}
2982
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2982
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2983 2983
 			}
2984 2984
 		}
2985 2985
 		elseif ($_nodePath) // single node
@@ -3006,9 +3006,9 @@  discard block
 block discarded – undo
3006 3006
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
3007 3007
 			}
3008 3008
 
3009
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
3009
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
3010 3010
 		}
3011
-		elseif(!$_nodePath) // all
3011
+		elseif (!$_nodePath) // all
3012 3012
 		{
3013 3013
 			if ($_subscribedOnly)
3014 3014
 			{
@@ -3024,101 +3024,101 @@  discard block
 block discarded – undo
3024 3024
 		{
3025 3025
 			// SORTING FOLDERS
3026 3026
 			//self::$debugTimes=true;
3027
-			if (self::$debugTimes) $starttime = microtime (true);
3027
+			if (self::$debugTimes) $starttime = microtime(true);
3028 3028
 			// Merge of all auto folders and specialusefolders
3029 3029
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
3030
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
3030
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
3031 3031
 			$tmpFolders = $folders;
3032
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
3033
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
3034
-			$isGoogleMail=false;
3035
-			foreach($autoFoldersTmp as $afk=>$aF)
3032
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
3033
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
3034
+			$isGoogleMail = false;
3035
+			foreach ($autoFoldersTmp as $afk=>$aF)
3036 3036
 			{
3037
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3037
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
3038 3038
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3039 3039
 			}
3040 3040
 			//error_log(array2string($mySpecialUseFolders));
3041 3041
 			foreach ($tmpFolders as $k => $f) {
3042
-				$sorted=false;
3043
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3044
-					if (strtoupper($k)=='INBOX') {
3042
+				$sorted = false;
3043
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
3044
+					if (strtoupper($k) == 'INBOX') {
3045 3045
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3046
-						$inboxFolderObject[$k]=$f;
3046
+						$inboxFolderObject[$k] = $f;
3047 3047
 						unset($folders[$k]);
3048
-						$sorted=true;
3048
+						$sorted = true;
3049 3049
 					} else {
3050
-						$isAutoFolder=false;
3051
-						foreach($autoFoldersTmp as $afk=>$aF)
3050
+						$isAutoFolder = false;
3051
+						foreach ($autoFoldersTmp as $afk=>$aF)
3052 3052
 						{
3053 3053
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3054
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3055
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3056
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3054
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3055
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3056
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3057 3057
 							{
3058 3058
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3059
-								$isAutoFolder=true;
3060
-								$autoFolderObjects[$k]=$f;
3059
+								$isAutoFolder = true;
3060
+								$autoFolderObjects[$k] = $f;
3061 3061
 								break;
3062 3062
 							}
3063 3063
 						}
3064
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3064
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
3065 3065
 						unset($folders[$k]);
3066
-						$sorted=true;
3066
+						$sorted = true;
3067 3067
 					}
3068
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3069
-					$isGoogleMail=true;
3070
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3071
-						$googleMailFolderObject[$k]=$f;
3068
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
3069
+					$isGoogleMail = true;
3070
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
3071
+						$googleMailFolderObject[$k] = $f;
3072 3072
 						unset($folders[$k]);
3073
-						$sorted=true;
3073
+						$sorted = true;
3074 3074
 					} else {
3075
-						$isAutoFolder=false;
3076
-						foreach($autoFoldersTmp as $afk=>$aF)
3075
+						$isAutoFolder = false;
3076
+						foreach ($autoFoldersTmp as $afk=>$aF)
3077 3077
 						{
3078 3078
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3079
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3080
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3081
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3079
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3080
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3081
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3082 3082
 							{
3083 3083
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3084
-								$isAutoFolder=true;
3085
-								$googleAutoFolderObjects[$k]=$f;
3084
+								$isAutoFolder = true;
3085
+								$googleAutoFolderObjects[$k] = $f;
3086 3086
 								break;
3087 3087
 							}
3088 3088
 						}
3089
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3089
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
3090 3090
 						unset($folders[$k]);
3091
-						$sorted=true;
3091
+						$sorted = true;
3092 3092
 					}
3093 3093
 				} else {
3094
-					$isAutoFolder=false;
3095
-					foreach($autoFoldersTmp as $afk=>$aF)
3094
+					$isAutoFolder = false;
3095
+					foreach ($autoFoldersTmp as $afk=>$aF)
3096 3096
 					{
3097 3097
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3098
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3099
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3100
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3098
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3099
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3100
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3101 3101
 						{
3102 3102
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3103
-							$isAutoFolder=true;
3104
-							$autoFolderObjects[$k]=$f;
3103
+							$isAutoFolder = true;
3104
+							$autoFolderObjects[$k] = $f;
3105 3105
 							unset($folders[$k]);
3106
-							$sorted=true;
3106
+							$sorted = true;
3107 3107
 							break;
3108 3108
 						}
3109 3109
 					}
3110 3110
 				}
3111 3111
 
3112
-				if ($sorted==false)
3112
+				if ($sorted == false)
3113 3113
 				{
3114
-					foreach(array('others','shared') as $type)
3114
+					foreach (array('others', 'shared') as $type)
3115 3115
 					{
3116
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3116
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
3117 3117
 						{
3118
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3119
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3118
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
3119
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
3120 3120
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3121
-								$typeFolderObject[$type][$k]=$f;
3121
+								$typeFolderObject[$type][$k] = $f;
3122 3122
 								unset($folders[$k]);
3123 3123
 							}
3124 3124
 						}
@@ -3129,40 +3129,40 @@  discard block
 block discarded – undo
3129 3129
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
3130 3130
 			$autoFolderObjectsTmp = $autoFolderObjects;
3131 3131
 			unset($autoFolderObjects);
3132
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
3133
-			foreach($autoFoldersTmp as $afk=>$aF)
3132
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
3133
+			foreach ($autoFoldersTmp as $afk=>$aF)
3134 3134
 			{
3135
-				foreach($autoFolderObjectsTmp as $k => $f)
3135
+				foreach ($autoFolderObjectsTmp as $k => $f)
3136 3136
 				{
3137
-					if($aF && ($mySpecialUseFolders[$aF]==$k ||
3138
-						substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter ||
3139
-						stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3137
+					if ($aF && ($mySpecialUseFolders[$aF] == $k ||
3138
+						substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter ||
3139
+						stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false))
3140 3140
 					{
3141
-						$autoFolderObjects[$k]=$f;
3141
+						$autoFolderObjects[$k] = $f;
3142 3142
 					}
3143 3143
 				}
3144 3144
 			}
3145 3145
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3146 3146
 			if (!$isGoogleMail) {
3147
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3147
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3148 3148
 			} else {
3149 3149
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3150 3150
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3151 3151
 				unset($googleAutoFolderObjects);
3152
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
3153
-				foreach($autoFoldersTmp as $afk=>$aF)
3152
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
3153
+				foreach ($autoFoldersTmp as $afk=>$aF)
3154 3154
 				{
3155
-					foreach($gAutoFolderObjectsTmp as $k => $f)
3155
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
3156 3156
 					{
3157
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
3157
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
3158 3158
 						{
3159
-							$googleAutoFolderObjects[$k]=$f;
3159
+							$googleAutoFolderObjects[$k] = $f;
3160 3160
 						}
3161 3161
 					}
3162 3162
 				}
3163
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3163
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3164 3164
 			}
3165
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3165
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
3166 3166
 			//self::$debugTimes=false;
3167 3167
 		}
3168 3168
 		// Get counter information and add them to each fetched folders array
@@ -3184,10 +3184,10 @@  discard block
 block discarded – undo
3184 3184
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
3185 3185
 	 * @return int number of new folders created
3186 3186
 	 */
3187
-	function check_create_autofolders(array $autofolders_exists=array())
3187
+	function check_create_autofolders(array $autofolders_exists = array())
3188 3188
 	{
3189 3189
 		$num_created = 0;
3190
-		foreach(self::$autoFolders as $folder)
3190
+		foreach (self::$autoFolders as $folder)
3191 3191
 		{
3192 3192
 			$created = false;
3193 3193
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -3212,7 +3212,7 @@  discard block
 block discarded – undo
3212 3212
 		$rv = false;
3213 3213
 		foreach ($haystack as $k => $v)
3214 3214
 		{
3215
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3215
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
3216 3216
 		}
3217 3217
 		return $rv;
3218 3218
 	}
@@ -3225,9 +3225,9 @@  discard block
 block discarded – undo
3225 3225
 	 * @param array $b array of folders
3226 3226
 	 * @return int expect values (0, 1 or -1)
3227 3227
 	 */
3228
-	function sortByMailbox($a,$b)
3228
+	function sortByMailbox($a, $b)
3229 3229
 	{
3230
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
3230
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
3231 3231
 	}
3232 3232
 
3233 3233
 	/**
@@ -3237,13 +3237,13 @@  discard block
 block discarded – undo
3237 3237
 	 * @param string $_hDelimiter hierarchy delimiter
3238 3238
 	 * @return array returns an array of data extracted from given node path
3239 3239
 	 */
3240
-	static function pathToFolderData ($_path, $_hDelimiter)
3240
+	static function pathToFolderData($_path, $_hDelimiter)
3241 3241
 	{
3242 3242
 		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3243 3243
 		list(,$path) = explode(self::DELIMITER, $_path);
3244 3244
 		$path_chain = $parts = explode($_hDelimiter, $path);
3245 3245
 		$name = array_pop($parts);
3246
-		return array (
3246
+		return array(
3247 3247
 			'name' => $name,
3248 3248
 			'mailbox' => $path,
3249 3249
 			'parent' => implode($_hDelimiter, $parts),
@@ -3266,8 +3266,8 @@  discard block
 block discarded – undo
3266 3266
 		// 0, 1 und -1
3267 3267
 		$a = self::pathToFolderData($_a['MAILBOX'], $_a['delimiter']);
3268 3268
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3269
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3270
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3269
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
3270
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3271 3271
 		if ($pos1 == $pos2) return 0;
3272 3272
 		return ($pos1 < $pos2) ? -1 : 1;
3273 3273
 	}
@@ -3280,10 +3280,10 @@  discard block
 block discarded – undo
3280 3280
 	 * @param object $b array of folderobjects
3281 3281
 	 * @return int expect values (0, 1 or -1)
3282 3282
 	 */
3283
-	function sortByDisplayName($a,$b)
3283
+	function sortByDisplayName($a, $b)
3284 3284
 	{
3285 3285
 		// 0, 1 und -1
3286
-		return strcasecmp($a->displayName,$b->displayName);
3286
+		return strcasecmp($a->displayName, $b->displayName);
3287 3287
 	}
3288 3288
 
3289 3289
 	/**
@@ -3294,11 +3294,11 @@  discard block
 block discarded – undo
3294 3294
 	 * @param object $b array of folderobjects
3295 3295
 	 * @return int expect values (0, 1 or -1)
3296 3296
 	 */
3297
-	function sortByAutoFolderPos($a,$b)
3297
+	function sortByAutoFolderPos($a, $b)
3298 3298
 	{
3299 3299
 		// 0, 1 und -1
3300
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3301
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3300
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3301
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3302 3302
 		if ($pos1 == $pos2) return 0;
3303 3303
 		return ($pos1 < $pos2) ? -1 : 1;
3304 3304
 	}
@@ -3311,7 +3311,7 @@  discard block
 block discarded – undo
3311 3311
 	 * @param boolean $_returnObject return the counters as object rather than an array
3312 3312
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3313 3313
 	 */
3314
-	function getMailBoxCounters($folderName,$_returnObject=true)
3314
+	function getMailBoxCounters($folderName, $_returnObject = true)
3315 3315
 	{
3316 3316
 		try
3317 3317
 		{
@@ -3323,9 +3323,9 @@  discard block
 block discarded – undo
3323 3323
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3324 3324
 			return false;
3325 3325
 		}
3326
-		if(is_array($folderStatus)) {
3327
-			if ($_returnObject===false) return $folderStatus;
3328
-			$status =  new \stdClass;
3326
+		if (is_array($folderStatus)) {
3327
+			if ($_returnObject === false) return $folderStatus;
3328
+			$status = new \stdClass;
3329 3329
 			$status->messages   = $folderStatus['MESSAGES'];
3330 3330
 			$status->unseen     = $folderStatus['UNSEEN'];
3331 3331
 			$status->recent     = $folderStatus['RECENT'];
@@ -3347,42 +3347,42 @@  discard block
 block discarded – undo
3347 3347
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3348 3348
 	 * @return array of mailboxes
3349 3349
 	 */
3350
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3350
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3351 3351
 	{
3352 3352
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3353
-		$maxreclevel=25;
3353
+		$maxreclevel = 25;
3354 3354
 		if ($reclevel > $maxreclevel) {
3355
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3355
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3356 3356
 			return array();
3357 3357
 		}
3358 3358
 		$reclevel++;
3359 3359
 		// clean up double delimiters
3360
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3360
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3361 3361
 		//get that mailbox in question
3362
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3362
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3363 3363
 		$mbxkeys = array_keys($mbx);
3364 3364
 		#_debug_array($mbx);
3365 3365
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3366 3366
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3367 3367
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3368
-		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"]))) {
3368
+		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"]))) {
3369 3369
 			// if there are children fetch them
3370 3370
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3371 3371
 
3372
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3372
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3373 3373
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3374 3374
 			//_debug_array($buff);
3375 3375
 			$allMailboxes = array();
3376 3376
 			foreach ($buff as $mbxname) {
3377 3377
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3378
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3378
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3379 3379
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3380
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3380
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3381 3381
 				{
3382 3382
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3383 3383
 				}
3384 3384
 			}
3385
-			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'];
3385
+			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'];
3386 3386
 			return $allMailboxes;
3387 3387
 		} else {
3388 3388
 			return array($_mailbox);
@@ -3397,18 +3397,18 @@  discard block
 block discarded – undo
3397 3397
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3398 3398
 	 * @return mixed string or false
3399 3399
 	 */
3400
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3400
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3401 3401
 	{
3402 3402
 		static $types = array(
3403
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3404
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3405
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3406
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3407
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3408
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3409
-			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3403
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3404
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3405
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3406
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3407
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3408
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3409
+			'Archive'   => array('profileKey'=>'acc_folder_archive', 'autoFolderName'=>'Archive'),
3410 3410
 		);
3411
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3411
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3412 3412
 		$created = false;
3413 3413
 		if (!isset($types[$_type]))
3414 3414
 		{
@@ -3430,7 +3430,7 @@  discard block
 block discarded – undo
3430 3430
 		}
3431 3431
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3432 3432
 		if ($_type == 'Archive') {
3433
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3433
+			if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3434 3434
 				return false;
3435 3435
 			} else {
3436 3436
 				return $_folderName;
@@ -3438,38 +3438,38 @@  discard block
 block discarded – undo
3438 3438
 
3439 3439
 		}
3440 3440
 		// does the folder exist??? (is configured/preset, but non-existent)
3441
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3441
+		if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3442 3442
 			try
3443 3443
 			{
3444 3444
 				$error = null;
3445 3445
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3446 3446
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3447 3447
 			}
3448
-			catch(Exception $e)
3448
+			catch (Exception $e)
3449 3449
 			{
3450 3450
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3451 3451
 				$_folderName = false;
3452 3452
 			}
3453 3453
 		}
3454 3454
 		// not sure yet if false is the correct behavior on none
3455
-		if ($_folderName =='none') return 'none' ; //false;
3455
+		if ($_folderName == 'none') return 'none'; //false;
3456 3456
 		//no (valid) folder found yet; try specialUseFolders
3457
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3457
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3458 3458
 		//no specialUseFolder; try some Defaults
3459 3459
 		if (empty($_folderName) && isset($types[$_type]))
3460 3460
 		{
3461 3461
 			$nameSpace = $this->_getNameSpaces();
3462
-			$prefix='';
3462
+			$prefix = '';
3463 3463
 			foreach ($nameSpace as $nSp)
3464 3464
 			{
3465
-				if ($nSp['type']=='personal')
3465
+				if ($nSp['type'] == 'personal')
3466 3466
 				{
3467 3467
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3468 3468
 					$prefix = $nSp['prefix'];
3469 3469
 					break;
3470 3470
 				}
3471 3471
 			}
3472
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3472
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3473 3473
 			{
3474 3474
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3475 3475
 			}
@@ -3478,11 +3478,11 @@  discard block
 block discarded – undo
3478 3478
 				try
3479 3479
 				{
3480 3480
 					$error = null;
3481
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3481
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3482 3482
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3483 3483
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3484 3484
 				}
3485
-				catch(Exception $e)
3485
+				catch (Exception $e)
3486 3486
 				{
3487 3487
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3488 3488
 					$_folderName = false;
@@ -3498,7 +3498,7 @@  discard block
 block discarded – undo
3498 3498
 	 * @param boolean $_checkexistance trigger check for existance
3499 3499
 	 * @return mixed string or false
3500 3500
 	 */
3501
-	function getFolderByType($type, $_checkexistance=false)
3501
+	function getFolderByType($type, $_checkexistance = false)
3502 3502
 	{
3503 3503
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3504 3504
 	}
@@ -3508,7 +3508,7 @@  discard block
 block discarded – undo
3508 3508
 	 * @param boolean $_checkexistance trigger check for existance
3509 3509
 	 * @return mixed string or false
3510 3510
 	 */
3511
-	function getJunkFolder($_checkexistance=TRUE)
3511
+	function getJunkFolder($_checkexistance = TRUE)
3512 3512
 	{
3513 3513
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3514 3514
 	}
@@ -3518,7 +3518,7 @@  discard block
 block discarded – undo
3518 3518
 	 * @param boolean $_checkexistance trigger check for existance
3519 3519
 	 * @return mixed string or false
3520 3520
 	 */
3521
-	function getDraftFolder($_checkexistance=TRUE)
3521
+	function getDraftFolder($_checkexistance = TRUE)
3522 3522
 	{
3523 3523
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3524 3524
 	}
@@ -3528,7 +3528,7 @@  discard block
 block discarded – undo
3528 3528
 	 * @param boolean $_checkexistance trigger check for existance
3529 3529
 	 * @return mixed string or false
3530 3530
 	 */
3531
-	function getTemplateFolder($_checkexistance=TRUE)
3531
+	function getTemplateFolder($_checkexistance = TRUE)
3532 3532
 	{
3533 3533
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3534 3534
 	}
@@ -3538,7 +3538,7 @@  discard block
 block discarded – undo
3538 3538
 	 * @param boolean $_checkexistance trigger check for existance
3539 3539
 	 * @return mixed string or false
3540 3540
 	 */
3541
-	function getTrashFolder($_checkexistance=TRUE)
3541
+	function getTrashFolder($_checkexistance = TRUE)
3542 3542
 	{
3543 3543
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3544 3544
 	}
@@ -3548,7 +3548,7 @@  discard block
 block discarded – undo
3548 3548
 	 * @param boolean $_checkexistance trigger check for existance
3549 3549
 	 * @return mixed string or false
3550 3550
 	 */
3551
-	function getSentFolder($_checkexistance=TRUE)
3551
+	function getSentFolder($_checkexistance = TRUE)
3552 3552
 	{
3553 3553
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3554 3554
 	}
@@ -3558,7 +3558,7 @@  discard block
 block discarded – undo
3558 3558
 	 * @param boolean $_checkexistance trigger check for existance
3559 3559
 	 * @return mixed string or false
3560 3560
 	 */
3561
-	function getOutboxFolder($_checkexistance=TRUE)
3561
+	function getOutboxFolder($_checkexistance = TRUE)
3562 3562
 	{
3563 3563
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3564 3564
 	}
@@ -3568,7 +3568,7 @@  discard block
 block discarded – undo
3568 3568
 	 * @param boolean $_checkexistance trigger check for existance . We do no autocreation for configured Archive folder
3569 3569
 	 * @return mixed string or false
3570 3570
 	 */
3571
-	function getArchiveFolder($_checkexistance=TRUE)
3571
+	function getArchiveFolder($_checkexistance = TRUE)
3572 3572
 	{
3573 3573
 		return $this->_getSpecialUseFolder('Archive', $_checkexistance);
3574 3574
 	}
@@ -3580,10 +3580,10 @@  discard block
 block discarded – undo
3580 3580
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3581 3581
 	 * @return boolean
3582 3582
 	 */
3583
-	function isSentFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3583
+	function isSentFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3584 3584
 	{
3585 3585
 		$sentFolder = $this->getSentFolder($_checkexistance);
3586
-		if(empty($sentFolder)) {
3586
+		if (empty($sentFolder)) {
3587 3587
 			return false;
3588 3588
 		}
3589 3589
 		// does the folder exist???
@@ -3593,13 +3593,13 @@  discard block
 block discarded – undo
3593 3593
 
3594 3594
 		if ($_exactMatch)
3595 3595
 		{
3596
-			if(false !== stripos($_folderName, $sentFolder)&& strlen($_folderName)==strlen($sentFolder)) {
3596
+			if (false !== stripos($_folderName, $sentFolder) && strlen($_folderName) == strlen($sentFolder)) {
3597 3597
 				return true;
3598 3598
 			} else {
3599 3599
 				return false;
3600 3600
 			}
3601 3601
 		} else {
3602
-			if(false !== stripos($_folderName, $sentFolder)) {
3602
+			if (false !== stripos($_folderName, $sentFolder)) {
3603 3603
 				return true;
3604 3604
 			} else {
3605 3605
 				return false;
@@ -3614,9 +3614,9 @@  discard block
 block discarded – undo
3614 3614
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3615 3615
 	 * @return boolean
3616 3616
 	 */
3617
-	function isOutbox($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3617
+	function isOutbox($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3618 3618
 	{
3619
-		if (stripos($_folderName, 'Outbox')===false) {
3619
+		if (stripos($_folderName, 'Outbox') === false) {
3620 3620
 			return false;
3621 3621
 		}
3622 3622
 		// does the folder exist???
@@ -3624,13 +3624,13 @@  discard block
 block discarded – undo
3624 3624
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3625 3625
 			if ($_exactMatch)
3626 3626
 			{
3627
-				if(false !== stripos($_folderName, $outboxFolder)&& strlen($_folderName)==strlen($outboxFolder)) {
3627
+				if (false !== stripos($_folderName, $outboxFolder) && strlen($_folderName) == strlen($outboxFolder)) {
3628 3628
 					return true;
3629 3629
 				} else {
3630 3630
 					return false;
3631 3631
 				}
3632 3632
 			} else {
3633
-				if(false !== stripos($_folderName, $outboxFolder)) {
3633
+				if (false !== stripos($_folderName, $outboxFolder)) {
3634 3634
 					return true;
3635 3635
 				} else {
3636 3636
 					return false;
@@ -3647,26 +3647,26 @@  discard block
 block discarded – undo
3647 3647
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3648 3648
 	 * @return boolean
3649 3649
 	 */
3650
-	function isDraftFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3650
+	function isDraftFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3651 3651
 	{
3652 3652
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3653
-		if(empty($draftFolder)) {
3653
+		if (empty($draftFolder)) {
3654 3654
 			return false;
3655 3655
 		}
3656 3656
 		// does the folder exist???
3657 3657
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3658 3658
 			return false;
3659 3659
 		}
3660
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3660
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3661 3661
 		if ($_exactMatch)
3662 3662
 		{
3663
-			if(false !== stripos($_folderName, $draftFolder)&& strlen($_folderName)==strlen($draftFolder)) {
3663
+			if (false !== stripos($_folderName, $draftFolder) && strlen($_folderName) == strlen($draftFolder)) {
3664 3664
 				return true;
3665 3665
 			} else {
3666 3666
 				return false;
3667 3667
 			}
3668 3668
 		} else {
3669
-			if(false !== stripos($_folderName, $draftFolder)) {
3669
+			if (false !== stripos($_folderName, $draftFolder)) {
3670 3670
 				return true;
3671 3671
 			} else {
3672 3672
 				return false;
@@ -3681,10 +3681,10 @@  discard block
 block discarded – undo
3681 3681
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3682 3682
 	 * @return boolean
3683 3683
 	 */
3684
-	function isTrashFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3684
+	function isTrashFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3685 3685
 	{
3686 3686
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3687
-		if(empty($trashFolder)) {
3687
+		if (empty($trashFolder)) {
3688 3688
 			return false;
3689 3689
 		}
3690 3690
 		// does the folder exist???
@@ -3694,13 +3694,13 @@  discard block
 block discarded – undo
3694 3694
 
3695 3695
 		if ($_exactMatch)
3696 3696
 		{
3697
-			if(false !== stripos($_folderName, $trashFolder)&& strlen($_folderName)==strlen($trashFolder)) {
3697
+			if (false !== stripos($_folderName, $trashFolder) && strlen($_folderName) == strlen($trashFolder)) {
3698 3698
 				return true;
3699 3699
 			} else {
3700 3700
 				return false;
3701 3701
 			}
3702 3702
 		} else {
3703
-			if(false !== stripos($_folderName, $trashFolder)) {
3703
+			if (false !== stripos($_folderName, $trashFolder)) {
3704 3704
 				return true;
3705 3705
 			} else {
3706 3706
 				return false;
@@ -3715,10 +3715,10 @@  discard block
 block discarded – undo
3715 3715
 	 * @param boolean $_exactMatch make the check more strict. return false if folder is subfolder only
3716 3716
 	 * @return boolean
3717 3717
 	 */
3718
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE, $_exactMatch=false)
3718
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE, $_exactMatch = false)
3719 3719
 	{
3720 3720
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3721
-		if(empty($templateFolder)) {
3721
+		if (empty($templateFolder)) {
3722 3722
 			return false;
3723 3723
 		}
3724 3724
 		// does the folder exist???
@@ -3727,13 +3727,13 @@  discard block
 block discarded – undo
3727 3727
 		}
3728 3728
 		if ($_exactMatch)
3729 3729
 		{
3730
-			if(false !== stripos($_folderName, $templateFolder)&& strlen($_folderName)==strlen($templateFolder)) {
3730
+			if (false !== stripos($_folderName, $templateFolder) && strlen($_folderName) == strlen($templateFolder)) {
3731 3731
 				return true;
3732 3732
 			} else {
3733 3733
 				return false;
3734 3734
 			}
3735 3735
 		} else {
3736
-			if(false !== stripos($_folderName, $templateFolder)) {
3736
+			if (false !== stripos($_folderName, $templateFolder)) {
3737 3737
 				return true;
3738 3738
 			} else {
3739 3739
 				return false;
@@ -3747,24 +3747,24 @@  discard block
 block discarded – undo
3747 3747
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3748 3748
 	 * @return mixed string or false
3749 3749
 	 */
3750
-	function folderExists($_folder, $_forceCheck=false)
3750
+	function folderExists($_folder, $_forceCheck = false)
3751 3751
 	{
3752 3752
 		static $folderInfo;
3753 3753
 		$forceCheck = $_forceCheck;
3754 3754
 		if (empty($_folder))
3755 3755
 		{
3756 3756
 			// this error is more or less without significance, unless we force the check
3757
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3757
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3758 3758
 			return false;
3759 3759
 		}
3760 3760
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3761
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3762
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3761
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3762
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3763 3763
 		// reduce traffic within the Instance per User; Expire every 5 hours
3764 3764
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3765
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3765
+		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3766 3766
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3767
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3767
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3768 3768
 		{
3769 3769
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3770 3770
 			return $folderInfo[$this->profileID][$_folder];
@@ -3780,7 +3780,7 @@  discard block
 block discarded – undo
3780 3780
 
3781 3781
 		// does the folder exist???
3782 3782
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3783
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3783
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3784 3784
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3785 3785
 			//return false;
3786 3786
 			//try to connect
@@ -3791,18 +3791,18 @@  discard block
 block discarded – undo
3791 3791
 		}
3792 3792
 		catch (\Exception $e)
3793 3793
 		{
3794
-			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:''));
3795
-			self::$profileDefunct[$this->profileID]=$e->getMessage().($e->details?', '.$e->details:'');
3794
+			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details ? ', '.$e->details : ''));
3795
+			self::$profileDefunct[$this->profileID] = $e->getMessage().($e->details ? ', '.$e->details : '');
3796 3796
 			$folderInfo[$this->profileID][$_folder] = false;
3797 3797
 		}
3798 3798
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3799 3799
 
3800
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3800
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3801 3801
 			$folderInfo[$this->profileID][$_folder] !== true)
3802 3802
 		{
3803 3803
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3804 3804
 		}
3805
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3805
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3806 3806
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3807 3807
 	}
3808 3808
 
@@ -3815,14 +3815,14 @@  discard block
 block discarded – undo
3815 3815
 	 */
3816 3816
 	function compressFolder($_folderName = false)
3817 3817
 	{
3818
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3819
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3820
-		$trashFolder	= $this->getTrashFolder();
3818
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3819
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3820
+		$trashFolder = $this->getTrashFolder();
3821 3821
 
3822 3822
 		$this->icServer->openMailbox($folderName);
3823 3823
 
3824
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3825
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3824
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3825
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3826 3826
 		} else {
3827 3827
 			$this->icServer->expunge($folderName);
3828 3828
 		}
@@ -3838,19 +3838,19 @@  discard block
 block discarded – undo
3838 3838
 	 * @return bool true, as we do not handle return values yet
3839 3839
 	 * @throws Exception
3840 3840
 	 */
3841
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3841
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3842 3842
 	{
3843 3843
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3844 3844
 		$oldMailbox = '';
3845 3845
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3846 3846
 		if (empty($_messageUID))
3847 3847
 		{
3848
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3848
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3849 3849
 			return false;
3850 3850
 		}
3851
-		elseif ($_messageUID==='all')
3851
+		elseif ($_messageUID === 'all')
3852 3852
 		{
3853
-			$_messageUID= null;
3853
+			$_messageUID = null;
3854 3854
 		}
3855 3855
 		else
3856 3856
 		{
@@ -3859,32 +3859,32 @@  discard block
 block discarded – undo
3859 3859
 			$uidsToDelete->add($_messageUID);
3860 3860
 		}
3861 3861
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3862
-		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");
3862
+		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");
3863 3863
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3864 3864
 		$trashFolder    = $this->getTrashFolder();
3865
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3865
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3866 3866
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3867
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3867
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3868 3868
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3869 3869
 			$deleteOptions = "remove_immediately";
3870 3870
 		}
3871
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3871
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3872 3872
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3873 3873
 			$this->icServer->openMailbox($_folder);
3874 3874
 		}
3875 3875
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3876 3876
 		$updateCache = false;
3877
-		switch($deleteOptions) {
3877
+		switch ($deleteOptions) {
3878 3878
 			case "move_to_trash":
3879 3879
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3880 3880
 				$updateCache = true;
3881
-				if(!empty($trashFolder)) {
3881
+				if (!empty($trashFolder)) {
3882 3882
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3883
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3883
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3884 3884
 					// copy messages
3885 3885
 					try
3886 3886
 					{
3887
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3887
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3888 3888
 					}
3889 3889
 					catch (\Exception $e)
3890 3890
 					{
@@ -3896,18 +3896,18 @@  discard block
 block discarded – undo
3896 3896
 			case "mark_as_deleted":
3897 3897
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3898 3898
 				// mark messages as deleted
3899
-				if (is_null($_messageUID)) $_messageUID='all';
3900
-				foreach((array)$_messageUID as $key =>$uid)
3899
+				if (is_null($_messageUID)) $_messageUID = 'all';
3900
+				foreach ((array)$_messageUID as $key =>$uid)
3901 3901
 				{
3902 3902
 					//flag messages, that are flagged for deletion as seen too
3903 3903
 					$this->flagMessages('read', $uid, $_folder);
3904 3904
 					$flags = $this->getFlags($uid);
3905 3905
 					$this->flagMessages('delete', $uid, $_folder);
3906 3906
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3907
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3907
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3908 3908
 					unset($flags);
3909 3909
 				}
3910
-				foreach((array)$undelete as $key =>$uid)
3910
+				foreach ((array)$undelete as $key =>$uid)
3911 3911
 				{
3912 3912
 					$this->flagMessages('undelete', $uid, $_folder);
3913 3913
 				}
@@ -3916,14 +3916,14 @@  discard block
 block discarded – undo
3916 3916
 			case "remove_immediately":
3917 3917
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3918 3918
 				$updateCache = true;
3919
-				if (is_null($_messageUID)) $_messageUID='all';
3919
+				if (is_null($_messageUID)) $_messageUID = 'all';
3920 3920
 				if (is_object($_messageUID))
3921 3921
 				{
3922 3922
 					$this->flagMessages('delete', $_messageUID, $_folder);
3923 3923
 				}
3924 3924
 				else
3925 3925
 				{
3926
-					foreach((array)$_messageUID as $key =>$uid)
3926
+					foreach ((array)$_messageUID as $key =>$uid)
3927 3927
 					{
3928 3928
 						//flag messages, that are flagged for deletion as seen too
3929 3929
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3933,7 +3933,7 @@  discard block
 block discarded – undo
3933 3933
 				$this->icServer->expunge($_folder);
3934 3934
 				break;
3935 3935
 		}
3936
-		if($oldMailbox != '') {
3936
+		if ($oldMailbox != '') {
3937 3937
 			$this->icServer->openMailbox($oldMailbox);
3938 3938
 		}
3939 3939
 
@@ -3947,7 +3947,7 @@  discard block
 block discarded – undo
3947 3947
 	 *
3948 3948
 	 * @return null/array flags
3949 3949
 	 */
3950
-	function getFlags ($_messageUID) {
3950
+	function getFlags($_messageUID) {
3951 3951
 		try
3952 3952
 		{
3953 3953
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3960,7 +3960,7 @@  discard block
 block discarded – undo
3960 3960
 				'ids' => $uidsToFetch,
3961 3961
 			));
3962 3962
 			if (is_object($headersNew)) {
3963
-				foreach($headersNew->ids() as $id) {
3963
+				foreach ($headersNew->ids() as $id) {
3964 3964
 					$_headerObject = $headersNew->get($id);
3965 3965
 					$flags = $_headerObject->getFlags();
3966 3966
 				}
@@ -3983,22 +3983,22 @@  discard block
 block discarded – undo
3983 3983
 	 *
3984 3984
 	 * @return null/boolean
3985 3985
 	 */
3986
-	function getNotifyFlags ($_messageUID, $flags=null)
3986
+	function getNotifyFlags($_messageUID, $flags = null)
3987 3987
 	{
3988 3988
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3989 3989
 		try
3990 3990
 		{
3991
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3991
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3992 3992
 		}
3993 3993
 		catch (\Exception $e)
3994 3994
 		{
3995 3995
 			return null;
3996 3996
 		}
3997 3997
 
3998
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3998
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3999 3999
 			return true;
4000 4000
 
4001
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
4001
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
4002 4002
 			return false;
4003 4003
 
4004 4004
 		return null;
@@ -4015,45 +4015,45 @@  discard block
 block discarded – undo
4015 4015
 	 *
4016 4016
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
4017 4017
 	 */
4018
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
4018
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
4019 4019
 	{
4020 4020
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
4021 4021
 		if (empty($_messageUID))
4022 4022
 		{
4023
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4023
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
4024 4024
 			return false;
4025 4025
 		}
4026
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
4026
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
4027 4027
 		$folder = $this->icServer->getCurrentMailbox();
4028
-		if (is_array($_messageUID)&& count($_messageUID)>50)
4028
+		if (is_array($_messageUID) && count($_messageUID) > 50)
4029 4029
 		{
4030
-			$count = $this->getMailBoxCounters($folder,true);
4031
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4030
+			$count = $this->getMailBoxCounters($folder, true);
4031
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
4032 4032
 		}
4033 4033
 
4034
-		if ($_messageUID==='all')
4034
+		if ($_messageUID === 'all')
4035 4035
 		{
4036 4036
 			$messageUIDs = array('all');
4037 4037
 		}
4038 4038
 		else
4039 4039
 		{
4040 4040
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4041
-			$messageUIDs = array_chunk($_messageUID,50,true);
4041
+			$messageUIDs = array_chunk($_messageUID, 50, true);
4042 4042
 		}
4043 4043
 		try
4044 4044
 		{
4045
-			foreach($messageUIDs as &$uids)
4045
+			foreach ($messageUIDs as &$uids)
4046 4046
 			{
4047
-				if ($uids==='all')
4047
+				if ($uids === 'all')
4048 4048
 				{
4049
-					$uidsToModify=null;
4049
+					$uidsToModify = null;
4050 4050
 				}
4051 4051
 				else
4052 4052
 				{
4053 4053
 					$uidsToModify = new Horde_Imap_Client_Ids();
4054 4054
 					$uidsToModify->add($uids);
4055 4055
 				}
4056
-				switch($_flag) {
4056
+				switch ($_flag) {
4057 4057
 					case "delete":
4058 4058
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
4059 4059
 						break;
@@ -4077,7 +4077,7 @@  discard block
 block discarded – undo
4077 4077
 						break;
4078 4078
 					case "unread":
4079 4079
 					case "unseen":
4080
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
4080
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
4081 4081
 						break;
4082 4082
 					case "mdnsent":
4083 4083
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -4135,13 +4135,13 @@  discard block
 block discarded – undo
4135 4135
 				}
4136 4136
 			}
4137 4137
 		}
4138
-		catch(Exception $e)
4138
+		catch (Exception $e)
4139 4139
 		{
4140 4140
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4141 4141
 		}
4142 4142
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4143 4143
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4144
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4144
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
4145 4145
 
4146 4146
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
4147 4147
 		return true; // as we do not catch/examine setFlags returnValue
@@ -4162,19 +4162,19 @@  discard block
 block discarded – undo
4162 4162
 	 * @return mixed/bool true,false or new uid
4163 4163
 	 * @throws Exception
4164 4164
 	 */
4165
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4165
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4166 4166
 	{
4167
-		$source = Mail\Account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
4167
+		$source = Mail\Account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
4168 4168
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4169 4169
 		if (empty($_messageUID))
4170 4170
 		{
4171
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4171
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
4172 4172
 			return false;
4173 4173
 		}
4174
-		elseif ($_messageUID==='all')
4174
+		elseif ($_messageUID === 'all')
4175 4175
 		{
4176 4176
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
4177
-			$uidsToMove= null;
4177
+			$uidsToMove = null;
4178 4178
 		}
4179 4179
 		else
4180 4180
 		{
@@ -4183,7 +4183,7 @@  discard block
 block discarded – undo
4183 4183
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4184 4184
 			$uidsToMove->add($_messageUID);
4185 4185
 		}
4186
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
4186
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
4187 4187
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
4188 4188
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
4189 4189
 		{
@@ -4203,19 +4203,19 @@  discard block
 block discarded – undo
4203 4203
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4204 4204
 
4205 4205
 			if (is_object($headersNew)) {
4206
-				$c=0;
4206
+				$c = 0;
4207 4207
 				$retUid = new Horde_Imap_Client_Ids();
4208 4208
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4209 4209
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4210
-				foreach($headersNew as &$_headerObject) {
4210
+				foreach ($headersNew as &$_headerObject) {
4211 4211
 					$c++;
4212 4212
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4213 4213
 					$date = $_headerObject->getImapDate();
4214
-					$currentDate =  new Horde_Imap_Client_DateTime();
4214
+					$currentDate = new Horde_Imap_Client_DateTime();
4215 4215
 					// if the internal Date of the message equals the current date; try using the header date
4216
-					if ($date==$currentDate)
4216
+					if ($date == $currentDate)
4217 4217
 					{
4218
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4218
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4219 4219
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
4220 4220
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
4221 4221
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -4224,20 +4224,20 @@  discard block
 block discarded – undo
4224 4224
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
4225 4225
 					$body = $_headerObject->getFullMsg();
4226 4226
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
4227
-					if ($c==1)
4227
+					if ($c == 1)
4228 4228
 					{
4229 4229
 						$target = Mail\Account::read($_targetProfileID)->imapServer();
4230 4230
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
4231 4231
 						$foldername = $target->getMailbox($_foldername);
4232 4232
 						// make sure the target folder is open and ready
4233 4233
 						$target->openMailbox($foldername);
4234
-						$ret = $target->append($foldername,$dataNflags);
4234
+						$ret = $target->append($foldername, $dataNflags);
4235 4235
 						$retUid->add($ret);
4236 4236
 						unset($dataNflags);
4237 4237
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
4238 4238
 						// inflicting in them. they "reply" with an unspecific IMAP Error
4239
-						time_nanosleep(0,500000);
4240
-						$c=0;
4239
+						time_nanosleep(0, 500000);
4240
+						$c = 0;
4241 4241
 					}
4242 4242
 				}
4243 4243
 				if (isset($dataNflags))
@@ -4247,7 +4247,7 @@  discard block
 block discarded – undo
4247 4247
 					$foldername = $target->getMailbox($_foldername);
4248 4248
 					// make sure the target folder is open and ready
4249 4249
 					$target->openMailbox($foldername);
4250
-					$ret = $target->append($foldername,$dataNflags);
4250
+					$ret = $target->append($foldername, $dataNflags);
4251 4251
 					$retUid->add($ret);
4252 4252
 					unset($dataNflags);
4253 4253
 				}
@@ -4258,7 +4258,7 @@  discard block
 block discarded – undo
4258 4258
 				{
4259 4259
 					$remember = $this->icServer;
4260 4260
 					$this->icServer = $source;
4261
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
4261
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
4262 4262
 					$this->icServer = $remember;
4263 4263
 				}
4264 4264
 			}
@@ -4267,7 +4267,7 @@  discard block
 block discarded – undo
4267 4267
 		{
4268 4268
 			try
4269 4269
 			{
4270
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
4270
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
4271 4271
 			}
4272 4272
 			catch (exception $e)
4273 4273
 			{
@@ -4287,22 +4287,22 @@  discard block
 block discarded – undo
4287 4287
 	 * @param string $format ='' if none is passed, use user prefs
4288 4288
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
4289 4289
 	 */
4290
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
4290
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
4291 4291
 	{
4292 4292
 		try {
4293
-			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4294
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4293
+			$date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable)
4294
+			if ($convert2usertime) $date->setUser(); // convert to user-time
4295 4295
 			$date2return = $date->format($format);
4296 4296
 		}
4297
-		catch(\Exception $e)
4297
+		catch (\Exception $e)
4298 4298
 		{
4299
-			unset($e);	// not used
4299
+			unset($e); // not used
4300 4300
 
4301 4301
 			// remove last space-separated part and retry
4302
-			$parts = explode(' ',$_date);
4302
+			$parts = explode(' ', $_date);
4303 4303
 			// try only 10 times to prevent of causing error by reaching
4304 4304
 			// maximum function nesting level.
4305
-			if (count($parts) > 1 && count($parts)<10)
4305
+			if (count($parts) > 1 && count($parts) < 10)
4306 4306
 			{
4307 4307
 				array_pop($parts);
4308 4308
 				$date2return = self::_strtotime(implode(' ', $parts), $format, $convert2usertime);
@@ -4322,12 +4322,12 @@  discard block
 block discarded – undo
4322 4322
 	 * @param mixed $_charset false or string -> Target charset, if false Mail displayCharset will be used
4323 4323
 	 * @return string
4324 4324
 	 */
4325
-	static function htmlentities($_string, $_charset=false)
4325
+	static function htmlentities($_string, $_charset = false)
4326 4326
 	{
4327 4327
 		//setting the charset (if not given)
4328
-		if ($_charset===false) $_charset = self::$displayCharset;
4328
+		if ($_charset === false) $_charset = self::$displayCharset;
4329 4329
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4330
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4330
+		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string, Translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
4331 4331
 		return $string;
4332 4332
 	}
4333 4333
 
@@ -4344,21 +4344,21 @@  discard block
 block discarded – undo
4344 4344
 		//$_html = str_replace("\t",' ',$_html);
4345 4345
 		//error_log(__METHOD__.__LINE__.':'.$_html);
4346 4346
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4347
-		$_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>'),
4348
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4347
+		$_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>'),
4348
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4349 4349
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4350
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4351
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4350
+		if (stripos($_html, 'style') !== false) Mail\Html::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4351
+		if (stripos($_html, 'head') !== false) Mail\Html::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4352 4352
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4353 4353
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4354 4354
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4355 4355
 
4356 4356
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4357 4357
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4358
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4359
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4360
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4361
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4358
+		if (stripos($_html, '!doctype') !== false) Mail\Html::replaceTagsCompletley($_html, '!doctype');
4359
+		if (stripos($_html, '?xml:namespace') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4360
+		if (stripos($_html, '?xml version') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4361
+		if (strpos($_html, '!CURSOR') !== false) Mail\Html::replaceTagsCompletley($_html, '!CURSOR');
4362 4362
 		// htmLawed filter only the 'body'
4363 4363
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4364 4364
 		//if ($matches[2])
@@ -4369,16 +4369,16 @@  discard block
 block discarded – undo
4369 4369
 		// purify got switched to htmLawed
4370 4370
 		// some testcode to test purifying / htmlawed
4371 4371
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4372
-		$_html = Html\HtmLawed::purify($_html,self::$htmLawed_config,array(),true);
4372
+		$_html = Html\HtmLawed::purify($_html, self::$htmLawed_config, array(), true);
4373 4373
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4374 4374
 		// clean out comments , should not be needed as purify should do the job.
4375 4375
 		$search = array(
4376
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4377
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4376
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4377
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4378 4378
 		);
4379
-		$_html = preg_replace($search,"",$_html);
4379
+		$_html = preg_replace($search, "", $_html);
4380 4380
 		// remove non printable chars
4381
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4381
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4382 4382
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4383 4383
 	}
4384 4384
 
@@ -4395,12 +4395,12 @@  discard block
 block discarded – undo
4395 4395
 	function getMimePartCharset($_mimePartObject)
4396 4396
 	{
4397 4397
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4398
-		$CharsetFound=false;
4398
+		$CharsetFound = false;
4399 4399
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4400
-		if(is_array($_mimePartObject->parameters)) {
4401
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4400
+		if (is_array($_mimePartObject->parameters)) {
4401
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4402 4402
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4403
-				$CharsetFound=true;
4403
+				$CharsetFound = true;
4404 4404
 			}
4405 4405
 		}
4406 4406
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4419,7 +4419,7 @@  discard block
 block discarded – undo
4419 4419
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4420 4420
 	{
4421 4421
 		// decode the part
4422
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4422
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4423 4423
 		switch (strtoupper($_encoding))
4424 4424
 		{
4425 4425
 			case 'BASE64':
@@ -4454,16 +4454,16 @@  discard block
 block discarded – undo
4454 4454
 	 * @param Horde_Mime_Part& $partCalendar =null on return text/calendar part, if one was contained or false
4455 4455
 	 * @return array containing the desired part
4456 4456
 	 */
4457
-	function getMultipartAlternative($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$partCalendar=null)
4457
+	function getMultipartAlternative($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$partCalendar = null)
4458 4458
 	{
4459 4459
 		// a multipart/alternative has exactly 2 parts (text and html  OR  text and something else)
4460 4460
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4461 4461
 		// as attachment AND as abstracted ical information (we use our notification style here).
4462 4462
 		$partText = $partCalendar = $partHTML = null;
4463
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4463
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4464 4464
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4465 4465
 		$ignore_first_part = true;
4466
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4466
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4467 4467
 		{
4468 4468
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4469 4469
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4471,15 +4471,15 @@  discard block
 block discarded – undo
4471 4471
 			if ($ignore_first_part)
4472 4472
 			{
4473 4473
 				$ignore_first_part = false;
4474
-				continue;	// ignore multipart/alternative itself
4474
+				continue; // ignore multipart/alternative itself
4475 4475
 			}
4476 4476
 
4477 4477
 			$mimePart = $_structure->getPart($mime_id);
4478 4478
 
4479
-			switch($mimePart->getPrimaryType())
4479
+			switch ($mimePart->getPrimaryType())
4480 4480
 			{
4481 4481
 				case 'text':
4482
-					switch($mimePart->getSubType())
4482
+					switch ($mimePart->getSubType())
4483 4483
 					{
4484 4484
 						case 'plain':
4485 4485
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4496,7 +4496,7 @@  discard block
 block discarded – undo
4496 4496
 					break;
4497 4497
 
4498 4498
 				case 'multipart':
4499
-					switch($mimePart->getSubType())
4499
+					switch ($mimePart->getSubType())
4500 4500
 					{
4501 4501
 						case 'related':
4502 4502
 						case 'mixed':
@@ -4518,13 +4518,13 @@  discard block
 block discarded – undo
4518 4518
 			}
4519 4519
 		}
4520 4520
 
4521
-		switch($_htmlMode)
4521
+		switch ($_htmlMode)
4522 4522
 		{
4523 4523
 			case 'html_only':
4524 4524
 			case 'always_display':
4525 4525
 				if ($partHTML)
4526 4526
 				{
4527
-					switch($partHTML->getSubType())
4527
+					switch ($partHTML->getSubType())
4528 4528
 					{
4529 4529
 						case 'related':
4530 4530
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4536,7 +4536,7 @@  discard block
 block discarded – undo
4536 4536
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4537 4537
 					}
4538 4538
 				}
4539
-				elseif ($partText && $_htmlMode=='always_display')
4539
+				elseif ($partText && $_htmlMode == 'always_display')
4540 4540
 				{
4541 4541
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4542 4542
 				}
@@ -4583,7 +4583,7 @@  discard block
 block discarded – undo
4583 4583
 	 * @param Horde_Mime_Part& $partCalendar =null on return text/calendar part, if one was contained or false
4584 4584
 	 * @return array containing the desired part
4585 4585
 	 */
4586
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array(), &$partCalendar=null)
4586
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array(), &$partCalendar = null)
4587 4587
 	{
4588 4588
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4589 4589
 		$bodyPart = array();
@@ -4592,7 +4592,7 @@  discard block
 block discarded – undo
4592 4592
 		$ignore_first_part = true;
4593 4593
 		//$skipParts = array();
4594 4594
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4595
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4595
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4596 4596
 		{
4597 4597
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4598 4598
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4600,9 +4600,9 @@  discard block
 block discarded – undo
4600 4600
 			{
4601 4601
 				$ignore_first_part = false;
4602 4602
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4603
-				continue;	// ignore multipart/mixed itself
4603
+				continue; // ignore multipart/mixed itself
4604 4604
 			}
4605
-			if (array_key_exists($mime_id,$skipParts))
4605
+			if (array_key_exists($mime_id, $skipParts))
4606 4606
 			{
4607 4607
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4608 4608
 				continue;
@@ -4610,11 +4610,11 @@  discard block
 block discarded – undo
4610 4610
 
4611 4611
 			$part = $_structure->getPart($mime_id);
4612 4612
 
4613
-			switch($part->getPrimaryType())
4613
+			switch ($part->getPrimaryType())
4614 4614
 			{
4615 4615
 				case 'multipart':
4616 4616
 					if ($part->getDisposition() == 'attachment') continue;
4617
-					switch($part->getSubType())
4617
+					switch ($part->getSubType())
4618 4618
 					{
4619 4619
 						case 'alternative':
4620 4620
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen, $partCalendar));
@@ -4630,15 +4630,15 @@  discard block
 block discarded – undo
4630 4630
 					}
4631 4631
 					break;
4632 4632
 				case 'application':
4633
-					switch($part->getSubType())
4633
+					switch ($part->getSubType())
4634 4634
 					{
4635 4635
 						case 'pgp-encrypted':
4636
-							if (($part = $_structure->getPart($mime_id+1)) &&
4636
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4637 4637
 								$part->getType() == 'application/octet-stream')
4638 4638
 							{
4639 4639
 								$this->fetchPartContents($_uid, $part);
4640
-								$skipParts[$mime_id]=$mime_type;
4641
-								$skipParts[$mime_id+1]=$part->getType();
4640
+								$skipParts[$mime_id] = $mime_type;
4641
+								$skipParts[$mime_id + 1] = $part->getType();
4642 4642
 								$bodyPart[] = array(
4643 4643
 									'body'		=> $part->getContents(array(
4644 4644
 										'stream' => false,
@@ -4652,15 +4652,15 @@  discard block
 block discarded – undo
4652 4652
 					break;
4653 4653
 
4654 4654
 				case 'text':
4655
-					switch($part->getSubType())
4655
+					switch ($part->getSubType())
4656 4656
 					{
4657 4657
 						case 'plain':
4658 4658
 						case 'html':
4659 4659
 						case 'calendar': // inline ics/ical files
4660
-							if($part->getDisposition() != 'attachment')
4660
+							if ($part->getDisposition() != 'attachment')
4661 4661
 							{
4662 4662
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4663
-								$skipParts[$mime_id]=$mime_type;
4663
+								$skipParts[$mime_id] = $mime_type;
4664 4664
 							}
4665 4665
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4666 4666
 							break;
@@ -4669,16 +4669,16 @@  discard block
 block discarded – undo
4669 4669
 
4670 4670
 				case 'message':
4671 4671
 					//skip attachments
4672
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4672
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4673 4673
 					{
4674 4674
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4675
-						$skipParts[$mime_id]=$mime_type;
4675
+						$skipParts[$mime_id] = $mime_type;
4676 4676
 					}
4677 4677
 					// do not descend into attached Messages
4678
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4678
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4679 4679
 					{
4680 4680
 						$skipParts[$mime_id.'.0'] = $mime_type;
4681
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4681
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4682 4682
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4683 4683
 						//break 2;
4684 4684
 					}
@@ -4719,13 +4719,13 @@  discard block
 block discarded – undo
4719 4719
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4720 4720
 	 * @return string|resource
4721 4721
 	 */
4722
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4722
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4723 4723
 	{
4724
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4724
+		if (self::$debug) error_log(__METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4725 4725
 
4726 4726
 		if (empty($_folder))
4727 4727
 		{
4728
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4728
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4729 4729
 		}
4730 4730
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4731 4731
 		// querying contents of body part
@@ -4736,11 +4736,11 @@  discard block
 block discarded – undo
4736 4736
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4737 4737
 		$fetchParams = array(
4738 4738
 			'peek' => $_preserveSeen,
4739
-			'decode' => true,	// try decode on server, does NOT neccessary work
4739
+			'decode' => true, // try decode on server, does NOT neccessary work
4740 4740
 		);
4741
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4741
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4742 4742
 		{
4743
-			$_tryDecodingServerside=false;
4743
+			$_tryDecodingServerside = false;
4744 4744
 			$fetchParams = array(
4745 4745
 				'peek' => $_preserveSeen,
4746 4746
 			);
@@ -4760,12 +4760,12 @@  discard block
 block discarded – undo
4760 4760
 		}
4761 4761
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4762 4762
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4763
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4763
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4764 4764
 		{
4765 4765
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4766 4766
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4767 4767
 		}
4768
-		return ($partToReturn?$partToReturn:null);
4768
+		return ($partToReturn ? $partToReturn : null);
4769 4769
 	}
4770 4770
 
4771 4771
 	/**
@@ -4778,13 +4778,13 @@  discard block
 block discarded – undo
4778 4778
 	 * @param boolean $_stream = false true return a stream, false return string
4779 4779
 	 * @return array containing the desired text part, mimeType and charset
4780 4780
 	 */
4781
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4781
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4782 4782
 	{
4783 4783
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4784 4784
 		$bodyPart = array();
4785
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4785
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4786 4786
 
4787
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4787
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4788 4788
 		{
4789 4789
 			$bodyPart = array(
4790 4790
 				'error'		=> 1,
@@ -4831,10 +4831,10 @@  discard block
 block discarded – undo
4831 4831
 	 * @param Horde_Mime_part& $calendar_part =null on return calendar-part or null, if there is none
4832 4832
 	 * @return array containing the message body, mimeType and charset
4833 4833
 	 */
4834
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '', &$calendar_part=null)
4834
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '', &$calendar_part = null)
4835 4835
 	{
4836 4836
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4837
-		if($_htmlOptions != '') {
4837
+		if ($_htmlOptions != '') {
4838 4838
 			$this->htmlOptions = $_htmlOptions;
4839 4839
 		}
4840 4840
 		if (empty($_folder))
@@ -4855,7 +4855,7 @@  discard block
 block discarded – undo
4855 4855
 			return array(
4856 4856
 				array(
4857 4857
 					'error'		=> 1,
4858
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4858
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4859 4859
 					'mimeType'	=> 'text/plain',
4860 4860
 					'charSet'	=> self::$displayCharset,
4861 4861
 				)
@@ -4868,7 +4868,7 @@  discard block
 block discarded – undo
4868 4868
 			//_debug_array($_structure->getMimeId()); exit;
4869 4869
 		}
4870 4870
 
4871
-		switch($_structure->getPrimaryType())
4871
+		switch ($_structure->getPrimaryType())
4872 4872
 		{
4873 4873
 			case 'application':
4874 4874
 				return array(
@@ -4880,7 +4880,7 @@  discard block
 block discarded – undo
4880 4880
 				);
4881 4881
 
4882 4882
 			case 'multipart':
4883
-				switch($_structure->getSubType())
4883
+				switch ($_structure->getSubType())
4884 4884
 				{
4885 4885
 					case 'alternative':
4886 4886
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen, $calendar_part));
@@ -4915,7 +4915,7 @@  discard block
 block discarded – undo
4915 4915
 				$bodyPart = array();
4916 4916
 				if ($_structure->getDisposition() != 'attachment')
4917 4917
 				{
4918
-					switch($_structure->getSubType())
4918
+					switch ($_structure->getSubType())
4919 4919
 					{
4920 4920
 						case 'calendar':
4921 4921
 							$calendar_part = $_structure;
@@ -4932,11 +4932,11 @@  discard block
 block discarded – undo
4932 4932
 
4933 4933
 			case 'attachment':
4934 4934
 			case 'message':
4935
-				switch($_structure->getSubType())
4935
+				switch ($_structure->getSubType())
4936 4936
 				{
4937 4937
 					case 'rfc822':
4938 4938
 						$newStructure = $_structure->getParts();
4939
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4939
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4940 4940
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4941 4941
 				}
4942 4942
 				break;
@@ -4964,11 +4964,11 @@  discard block
 block discarded – undo
4964 4964
 	{
4965 4965
 		if (is_array($_bodyParts))
4966 4966
 		{
4967
-			foreach($_bodyParts as $singleBodyPart)
4967
+			foreach ($_bodyParts as $singleBodyPart)
4968 4968
 			{
4969 4969
 				if (!isset($singleBodyPart['body'])) {
4970 4970
 					$buff = self::normalizeBodyParts($singleBodyPart);
4971
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4971
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4972 4972
 					continue;
4973 4973
 				}
4974 4974
 				$body2return[] = $singleBodyPart;
@@ -4989,14 +4989,14 @@  discard block
 block discarded – undo
4989 4989
 	 * @param boolean $useTidy  switch to use tidy
4990 4990
 	 * @return string a preformatted string with the mails converted to text
4991 4991
 	 */
4992
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4992
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4993 4993
 	{
4994
-		$message='';
4995
-		for($i=0; $i<count($bodyParts); $i++)
4994
+		$message = '';
4995
+		for ($i = 0; $i < count($bodyParts); $i++)
4996 4996
 		{
4997 4997
 			if (!isset($bodyParts[$i]['body'])) {
4998 4998
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4999
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4999
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
5000 5000
 				continue;
5001 5001
 			}
5002 5002
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -5021,32 +5021,32 @@  discard block
 block discarded – undo
5021 5021
 				'(R)',
5022 5022
 			);
5023 5023
 
5024
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
5024
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
5025 5025
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
5026 5026
 			{
5027
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
5027
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
5028 5028
 			}
5029 5029
 
5030
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5030
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5031 5031
 			// add line breaks to $bodyParts
5032 5032
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
5033
-			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
5033
+			$newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
5034 5034
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
5035 5035
 			$mailClass->activeMimeType = 'text/plain';
5036 5036
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5037 5037
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
5038 5038
 				if (!$preserveHTML)
5039 5039
 				{
5040
-					$alreadyHtmlLawed=false;
5040
+					$alreadyHtmlLawed = false;
5041 5041
 					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
5042
-					$newBody = str_replace("\n"," ",$newBody);
5042
+					$newBody = str_replace("\n", " ", $newBody);
5043 5043
 					// convert HTML to text, as we dont want HTML in infologs
5044 5044
 					if ($useTidy && extension_loaded('tidy'))
5045 5045
 					{
5046 5046
 						$tidy = new tidy();
5047
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
5047
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
5048 5048
 						// Found errors. Strip it all so there's some output
5049
-						if($tidy->getStatus() == 2)
5049
+						if ($tidy->getStatus() == 2)
5050 5050
 						{
5051 5051
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
5052 5052
 						}
@@ -5057,7 +5057,7 @@  discard block
 block discarded – undo
5057 5057
 						if (!$preserveHTML)
5058 5058
 						{
5059 5059
 							// filter only the 'body', as we only want that part, if we throw away the html
5060
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5060
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
5061 5061
 							if ($matches[2])
5062 5062
 							{
5063 5063
 								$hasOther = true;
@@ -5068,7 +5068,7 @@  discard block
 block discarded – undo
5068 5068
 					else
5069 5069
 					{
5070 5070
 						// htmLawed filter only the 'body'
5071
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
5071
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
5072 5072
 						if ($matches[2])
5073 5073
 						{
5074 5074
 							$hasOther = true;
@@ -5077,17 +5077,17 @@  discard block
 block discarded – undo
5077 5077
 						$htmLawed = new Html\HtmLawed();
5078 5078
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
5079 5079
 						// as we switched off HTMLaweds tidy functionality
5080
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
5081
-						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
5082
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5083
-						$alreadyHtmlLawed=true;
5080
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
5081
+						$newBody = $htmLawed->run($newBody, self::$htmLawed_config);
5082
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
5083
+						$alreadyHtmlLawed = true;
5084 5084
 					}
5085 5085
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
5086
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5086
+					if ($preserveHTML == false) $newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, true, true);
5087 5087
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
5088
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5088
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5089 5089
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
5090
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5090
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
5091 5091
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
5092 5092
 				}
5093 5093
 				$message .= $newBody;
@@ -5096,9 +5096,9 @@  discard block
 block discarded – undo
5096 5096
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
5097 5097
 			//use Mail\Html::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
5098 5098
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
5099
-			$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,false,false);
5099
+			$newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, false, false);
5100 5100
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
5101
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
5101
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
5102 5102
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
5103 5103
 			$message .= $newBody;
5104 5104
 			//continue;
@@ -5106,27 +5106,27 @@  discard block
 block discarded – undo
5106 5106
 		return $message;
5107 5107
 	}
5108 5108
 
5109
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
5109
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
5110 5110
 	{
5111 5111
 		$lines = explode("\n", $str);
5112 5112
 		$newStr = '';
5113
-		foreach($lines as $line)
5113
+		foreach ($lines as $line)
5114 5114
 		{
5115 5115
 			// replace tabs by 8 space chars, or any tab only counts one char
5116 5116
 			//$line = str_replace("\t","        ",$line);
5117 5117
 			//$newStr .= wordwrap($line, $cols, $cut);
5118
-			$allowedLength = $cols-strlen($cut);
5118
+			$allowedLength = $cols - strlen($cut);
5119 5119
 			//dont try to break lines with links, chance is we mess up the text is way too big
5120
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
5121
-				($dontbreaklinesstartingwith==false ||
5120
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
5121
+				($dontbreaklinesstartingwith == false ||
5122 5122
 				 ($dontbreaklinesstartingwith &&
5123
-				  strlen($dontbreaklinesstartingwith)>=1 &&
5124
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5123
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
5124
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5125 5125
 				 )
5126 5126
 				)
5127 5127
 			   )
5128 5128
 			{
5129
-				$s=explode(" ", $line);
5129
+				$s = explode(" ", $line);
5130 5130
 				$line = "";
5131 5131
 				$linecnt = 0;
5132 5132
 				foreach ($s as &$v) {
@@ -5134,22 +5134,22 @@  discard block
 block discarded – undo
5134 5134
 					// only break long words within the wordboundaries,
5135 5135
 					// but it may destroy links, so we check for href and dont do it if we find one
5136 5136
 					// we check for any html within the word, because we do not want to break html by accident
5137
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
5137
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
5138 5138
 					{
5139
-						$v=wordwrap($v, $allowedLength, $cut, true);
5139
+						$v = wordwrap($v, $allowedLength, $cut, true);
5140 5140
 					}
5141 5141
 					// the rest should be broken at the start of the new word that exceeds the limit
5142
-					if ($linecnt+$cnt > $allowedLength) {
5143
-						$v=$cut.$v;
5142
+					if ($linecnt + $cnt > $allowedLength) {
5143
+						$v = $cut.$v;
5144 5144
 						#$linecnt = 0;
5145
-						$linecnt =strlen($v)-strlen($cut);
5145
+						$linecnt = strlen($v) - strlen($cut);
5146 5146
 					} else {
5147 5147
 						$linecnt += $cnt;
5148 5148
 					}
5149 5149
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5150 5150
 				}
5151 5151
 			}
5152
-			$newStr .= $line . "\n";
5152
+			$newStr .= $line."\n";
5153 5153
 		}
5154 5154
 		return $newStr;
5155 5155
 	}
@@ -5164,12 +5164,12 @@  discard block
 block discarded – undo
5164 5164
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
5165 5165
 	 * @return array the message header
5166 5166
 	 */
5167
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5167
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
5168 5168
 	{
5169 5169
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5170
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5170
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5171 5171
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5172
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5172
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
5173 5173
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5174 5174
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5175 5175
 			$uidsToFetch->add($_uid);
@@ -5182,7 +5182,7 @@  discard block
 block discarded – undo
5182 5182
 				'ids' => $uidsToFetch,
5183 5183
 			));
5184 5184
 			if (is_object($headersNew)) {
5185
-				foreach($headersNew as &$_headerObject) {
5185
+				foreach ($headersNew as &$_headerObject) {
5186 5186
 					$env = $_headerObject->getEnvelope();
5187 5187
 					//_debug_array($envFields->singleFields());
5188 5188
 					$singleFields = $envFields->singleFields();
@@ -5197,34 +5197,34 @@  discard block
 block discarded – undo
5197 5197
 							case 'bcc':
5198 5198
 							case 'sender':
5199 5199
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5200
-								$envelope[$v]=$env->$v->addresses;
5200
+								$envelope[$v] = $env->$v->addresses;
5201 5201
 								$address = array();
5202 5202
 								if (!is_array($envelope[$v])) break;
5203 5203
 								foreach ($envelope[$v] as $k => $ad)
5204 5204
 								{
5205
-									if (stripos($ad,'@')===false)
5205
+									if (stripos($ad, '@') === false)
5206 5206
 									{
5207
-										$remember=$k;
5207
+										$remember = $k;
5208 5208
 									}
5209 5209
 									else
5210 5210
 									{
5211
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
5212
-										$remember=null;
5211
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
5212
+										$remember = null;
5213 5213
 									}
5214 5214
 								}
5215 5215
 								$envelope[$v] = $address;
5216 5216
 								break;
5217 5217
 							case 'date':
5218
-								$envelope[$v]=DateTime::to($env->$v);
5218
+								$envelope[$v] = DateTime::to($env->$v);
5219 5219
 								break;
5220 5220
 							default:
5221
-								$envelope[$v]=$env->$v;
5221
+								$envelope[$v] = $env->$v;
5222 5222
 						}
5223 5223
 					}
5224
-					$envelope['size']=$_headerObject->getSize();
5224
+					$envelope['size'] = $_headerObject->getSize();
5225 5225
 				}
5226 5226
 			}
5227
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
5227
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
5228 5228
 			//if ($decode) _debug_array($envelope);
5229 5229
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
5230 5230
 			if ($decode)
@@ -5232,19 +5232,19 @@  discard block
 block discarded – undo
5232 5232
 				foreach ($envelope as $key => $rvV)
5233 5233
 				{
5234 5234
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5235
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5235
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5236 5236
 				}
5237 5237
 			}
5238 5238
 			return $envelope;
5239 5239
 		} else {
5240 5240
 
5241
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5241
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
5242 5242
 
5243 5243
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
5244 5244
 			//_debug_array($headers);
5245 5245
 			$newData = array(
5246 5246
 				'DATE'		=> $headers['DATE'],
5247
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5247
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
5248 5248
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5249 5249
 			);
5250 5250
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -5255,11 +5255,11 @@  discard block
 block discarded – undo
5255 5255
 			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5256 5256
 			//_debug_array($newData);
5257 5257
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5258
-			foreach($recepientList as $recepientType) {
5259
-				if(isset($headers[$recepientType])) {
5260
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5258
+			foreach ($recepientList as $recepientType) {
5259
+				if (isset($headers[$recepientType])) {
5260
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
5261 5261
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5262
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5262
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5263 5263
 						$addressData = array(
5264 5264
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5265 5265
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5267,15 +5267,15 @@  discard block
 block discarded – undo
5267 5267
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5268 5268
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5269 5269
 						);
5270
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5270
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
5271 5271
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5272 5272
 						} else {
5273 5273
 							$addressData['RFC822_EMAIL'] = 'NIL';
5274 5274
 						}
5275
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5275
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
5276 5276
 					}
5277 5277
 				} else {
5278
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5278
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5279 5279
 						$newData[$recepientType] = $newData['FROM'];
5280 5280
 					} else {
5281 5281
 						$newData[$recepientType] = array();
@@ -5297,10 +5297,10 @@  discard block
 block discarded – undo
5297 5297
 	 * @param string $_folder folder to work on
5298 5298
 	 * @return array|Horde_Mime_Headers message header as array or object
5299 5299
 	 */
5300
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5300
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
5301 5301
 	{
5302 5302
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5303
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5303
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5304 5304
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5305 5305
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5306 5306
 		$uidsToFetch->add($_uid);
@@ -5308,7 +5308,7 @@  discard block
 block discarded – undo
5308 5308
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5309 5309
 		if ($_partID != '')
5310 5310
 		{
5311
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
5311
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
5312 5312
 			$fquery->structure();
5313 5313
 		}
5314 5314
 		else
@@ -5321,18 +5321,18 @@  discard block
 block discarded – undo
5321 5321
 			'ids' => $uidsToFetch,
5322 5322
 		));
5323 5323
 		if (is_object($headersNew)) {
5324
-			foreach($headersNew as $_fetchObject)
5324
+			foreach ($headersNew as $_fetchObject)
5325 5325
 			{
5326
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5326
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5327 5327
 				if ($_partID != '')
5328 5328
 				{
5329 5329
 					$mailStructureObject = $_fetchObject->getStructure();
5330 5330
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5331 5331
 					{
5332
-						if ($mime_id==$_partID)
5332
+						if ($mime_id == $_partID)
5333 5333
 						{
5334 5334
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
5335
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5335
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5336 5336
 							break;
5337 5337
 						}
5338 5338
 					}
@@ -5345,15 +5345,15 @@  discard block
 block discarded – undo
5345 5345
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5346 5346
 				return $headers;
5347 5347
 			}
5348
-			$retValue = is_object($headers) ? $headers->toArray():array();
5348
+			$retValue = is_object($headers) ? $headers->toArray() : array();
5349 5349
 			if ($size) $retValue['size'] = $size;
5350 5350
 		}
5351
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
5351
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
5352 5352
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
5353 5353
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
5354 5354
 		if (is_array($retValue['SUBJECT']))
5355 5355
 		{
5356
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
5356
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
5357 5357
 		}
5358 5358
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
5359 5359
 		if ($decode)
@@ -5361,7 +5361,7 @@  discard block
 block discarded – undo
5361 5361
 			foreach ($retValue as $key => $rvV)
5362 5362
 			{
5363 5363
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5364
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5364
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5365 5365
 			}
5366 5366
 		}
5367 5367
 		return $retValue;
@@ -5378,14 +5378,14 @@  discard block
 block discarded – undo
5378 5378
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5379 5379
 	{
5380 5380
 		static $rawHeaders;
5381
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5381
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5382 5382
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5383 5383
 
5384
-		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);
5385
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5384
+		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);
5385
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5386 5386
 		{
5387 5387
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5388
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5388
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5389 5389
 		}
5390 5390
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5391 5391
 		$uid = $_uid;
@@ -5395,7 +5395,7 @@  discard block
 block discarded – undo
5395 5395
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5396 5396
 		if ($_partID != '')
5397 5397
 		{
5398
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5398
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5399 5399
 			$fquery->structure();
5400 5400
 		}
5401 5401
 		else
@@ -5406,14 +5406,14 @@  discard block
 block discarded – undo
5406 5406
 			'ids' => $uidsToFetch,
5407 5407
 		));
5408 5408
 		if (is_object($headersNew)) {
5409
-			foreach($headersNew as &$_headerObject) {
5409
+			foreach ($headersNew as &$_headerObject) {
5410 5410
 				$retValue = $_headerObject->getHeaderText();
5411 5411
 				if ($_partID != '')
5412 5412
 				{
5413 5413
 					$mailStructureObject = $_headerObject->getStructure();
5414 5414
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5415 5415
 					{
5416
-						if ($mime_id==$_partID)
5416
+						if ($mime_id == $_partID)
5417 5417
 						{
5418 5418
 							$retValue = $_headerObject->getHeaderText($mime_id);
5419 5419
 						}
@@ -5421,8 +5421,8 @@  discard block
 block discarded – undo
5421 5421
 				}
5422 5422
 			}
5423 5423
 		}
5424
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5425
-		Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5424
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5425
+		Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5426 5426
 		return $retValue;
5427 5427
 	}
5428 5428
 
@@ -5435,25 +5435,25 @@  discard block
 block discarded – undo
5435 5435
 	{
5436 5436
 		$style = '';
5437 5437
 		if (empty($_bodyParts)) return "";
5438
-		foreach((array)$_bodyParts as $singleBodyPart) {
5438
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5439 5439
 			if (!isset($singleBodyPart['body'])) {
5440 5440
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5441 5441
 				$style .= $singleBodyPart['body'];
5442 5442
 				continue;
5443 5443
 			}
5444 5444
 
5445
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5445
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5446 5446
 			$singleBodyPart['body'] = Translation::convert(
5447 5447
 				$singleBodyPart['body'],
5448 5448
 				strtolower($singleBodyPart['charSet'])
5449 5449
 			);
5450 5450
 			$ct = 0;
5451
-			$newStyle=array();
5452
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5453
-			if ($ct>0)
5451
+			$newStyle = array();
5452
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5453
+			if ($ct > 0)
5454 5454
 			{
5455 5455
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5456
-				$style2buffer = implode('',$newStyle[0]);
5456
+				$style2buffer = implode('', $newStyle[0]);
5457 5457
 			}
5458 5458
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5459 5459
 			{
@@ -5461,7 +5461,7 @@  discard block
 block discarded – undo
5461 5461
 				$test = json_encode($style2buffer);
5462 5462
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5463 5463
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5464
-				if ($test=="null" && strlen($style2buffer)>0)
5464
+				if ($test == "null" && strlen($style2buffer) > 0)
5465 5465
 				{
5466 5466
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5467 5467
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.Translation::detect_encoding($style2buffer));
@@ -5472,19 +5472,19 @@  discard block
 block discarded – undo
5472 5472
 		}
5473 5473
 		// clean out comments and stuff
5474 5474
 		$search = array(
5475
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5475
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5476 5476
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5477 5477
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5478 5478
 		);
5479
-		$style = preg_replace($search,"",$style);
5479
+		$style = preg_replace($search, "", $style);
5480 5480
 
5481 5481
 		// CSS Security
5482 5482
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5483
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5484
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5483
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5484
+		if (stripos($css, 'script') !== false) Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5485 5485
 		// 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
5486 5486
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5487
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5487
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5488 5488
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5489 5489
 		// TODO: we may have to strip urls and maybe comments and ifs
5490 5490
 		return $css;
@@ -5499,16 +5499,16 @@  discard block
 block discarded – undo
5499 5499
 	 * @param boolean $_stream =false true: return a stream, false: return string, stream suppresses any caching
5500 5500
 	 * @return string the message body
5501 5501
 	 */
5502
-	function getMessageRawBody($_uid, $_partID = '', $_folder='', $_stream=false)
5502
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '', $_stream = false)
5503 5503
 	{
5504 5504
 		//TODO: caching einbauen static!
5505 5505
 		static $rawBody;
5506 5506
 		if (is_null($rawBody)) $rawBody = array();
5507
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5508
-		if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5507
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5508
+		if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5509 5509
 		{
5510 5510
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5511
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5511
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5512 5512
 		}
5513 5513
 
5514 5514
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5521,13 +5521,13 @@  discard block
 block discarded – undo
5521 5521
 		if ($_partID != '')
5522 5522
 		{
5523 5523
 			$fquery->structure();
5524
-			$fquery->bodyPart($_partID,array('peek'=>true));
5524
+			$fquery->bodyPart($_partID, array('peek'=>true));
5525 5525
 		}
5526 5526
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5527 5527
 			'ids' => $uidsToFetch,
5528 5528
 		));
5529 5529
 		if (is_object($headersNew)) {
5530
-			foreach($headersNew as &$_headerObject) {
5530
+			foreach ($headersNew as &$_headerObject) {
5531 5531
 				$body = $_headerObject->getFullMsg($_stream);
5532 5532
 				if ($_partID != '')
5533 5533
 				{
@@ -5535,7 +5535,7 @@  discard block
 block discarded – undo
5535 5535
 					//_debug_array($mailStructureObject->contentTypeMap());
5536 5536
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5537 5537
 					{
5538
-						if ($mime_id==$_partID)
5538
+						if ($mime_id == $_partID)
5539 5539
 						{
5540 5540
 							$body = $_headerObject->getBodyPart($mime_id, $_stream);
5541 5541
 						}
@@ -5546,7 +5546,7 @@  discard block
 block discarded – undo
5546 5546
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5547 5547
 		if (!$_stream)
5548 5548
 		{
5549
-			$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5549
+			$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5550 5550
 		}
5551 5551
 		return $body;
5552 5552
 	}
@@ -5561,13 +5561,13 @@  discard block
 block discarded – undo
5561 5561
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5562 5562
 	 * @return Horde_Mime_Part
5563 5563
 	 */
5564
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5564
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5565 5565
 	{
5566
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5566
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5567 5567
 
5568 5568
 		if (empty($_folder))
5569 5569
 		{
5570
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5570
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5571 5571
 		}
5572 5572
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5573 5573
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5585,7 +5585,7 @@  discard block
 block discarded – undo
5585 5585
 				'ids' => $uidsToFetch,
5586 5586
 			))->first();
5587 5587
 
5588
-			return is_object($mail)?$mail->getStructure():null;
5588
+			return is_object($mail) ? $mail->getStructure() : null;
5589 5589
 		}
5590 5590
 		catch (\Exception $e)
5591 5591
 		{
@@ -5608,14 +5608,14 @@  discard block
 block discarded – undo
5608 5608
 	 * @param string $_folder folder to work on
5609 5609
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5610 5610
 	 */
5611
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5611
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5612 5612
 	{
5613
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5614
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5613
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5614
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5615 5615
 		$attachments = array();
5616 5616
 		if (!isset($_structure))
5617 5617
 		{
5618
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5618
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5619 5619
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5620 5620
 		}
5621 5621
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5623,7 +5623,7 @@  discard block
 block discarded – undo
5623 5623
 		$skipParts = array();
5624 5624
 		$tnefParts = array();
5625 5625
 		$skip = 0;
5626
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5626
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5627 5627
 		{
5628 5628
 			// skip multipart/encrypted incl. its two sub-parts, as we show 2. sub-part as body to be decrypted client-side
5629 5629
 			if ($mime_type == 'multipart/encrypted')
@@ -5631,7 +5631,7 @@  discard block
 block discarded – undo
5631 5631
 				$skip = 2;
5632 5632
 				continue;
5633 5633
 			}
5634
-			elseif($skip)
5634
+			elseif ($skip)
5635 5635
 			{
5636 5636
 				$skip--;
5637 5637
 				continue;
@@ -5645,10 +5645,10 @@  discard block
 block discarded – undo
5645 5645
 			$partPrimaryType = $part->getPrimaryType();
5646 5646
 			// we only want to retrieve the attachments of the current mail, not those of possible
5647 5647
 			// attached mails
5648
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5648
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5649 5649
 			{
5650 5650
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5651
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5651
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5652 5652
 			}
5653 5653
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5654 5654
 			{
@@ -5656,27 +5656,27 @@  discard block
 block discarded – undo
5656 5656
 				// attachment with no link to show the attachment inline.
5657 5657
 				// Considering this: we "list" everything that matches the above criteria
5658 5658
 				// as attachment in order to not loose/miss information on our data
5659
-				$partDisposition='attachment';
5659
+				$partDisposition = 'attachment';
5660 5660
 			}
5661 5661
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5662
-			if (array_key_exists($mime_id,$skipParts)) continue;
5662
+			if (array_key_exists($mime_id, $skipParts)) continue;
5663 5663
 
5664 5664
 			if ($partDisposition == 'attachment' ||
5665
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5665
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5666 5666
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5667
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5667
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5668 5668
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5669 5669
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5670 5670
 			{
5671 5671
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5672 5672
 				// we attempt to fetch "ourselves"
5673
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5673
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5674 5674
 				$attachment = $part->getAllDispositionParameters();
5675 5675
 				$attachment['disposition'] = $part->getDisposition();
5676 5676
 				$attachment['mimeType'] = $mime_type;
5677 5677
 				$attachment['uid'] = $_uid;
5678 5678
 				$attachment['partID'] = $mime_id;
5679
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5679
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5680 5680
 				if ($fetchTextCalendar)
5681 5681
 				{
5682 5682
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5686,11 +5686,11 @@  discard block
 block discarded – undo
5686 5686
 				}
5687 5687
 				$attachment['size'] = $part->getBytes();
5688 5688
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5689
-				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);
5689
+				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);
5690 5690
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5691 5691
 				//typical winmail.dat attachment is
5692 5692
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5693
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5693
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5694 5694
 				{
5695 5695
 					$tnefParts[] = $attachment;
5696 5696
 				}
@@ -5705,31 +5705,31 @@  discard block
 block discarded – undo
5705 5705
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5706 5706
 			foreach ($tnefParts as $k => $tnp)
5707 5707
 			{
5708
-				$tnefResolved=false;
5709
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5708
+				$tnefResolved = false;
5709
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5710 5710
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5711 5711
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5712 5712
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5713 5713
 				// we need to build Something that meets the needs
5714 5714
 				if ($myTnef)
5715 5715
 				{
5716
-					foreach($myTnef->getParts() as $mime_id => $part)
5716
+					foreach ($myTnef->getParts() as $mime_id => $part)
5717 5717
 					{
5718
-						$tnefResolved=true;
5718
+						$tnefResolved = true;
5719 5719
 						$attachment = $part->getAllDispositionParameters();
5720 5720
 						$attachment['disposition'] = $part->getDisposition();
5721 5721
 						$attachment['mimeType'] = $part->getType();
5722 5722
 						$attachment['uid'] = $tnp['uid'];
5723 5723
 						$attachment['partID'] = $tnp['partID'];
5724 5724
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5725
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5725
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5726 5726
 						$attachment['size'] = $part->getBytes();
5727 5727
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5728
-						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']);
5728
+						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']);
5729 5729
 						$attachments[] = $attachment;
5730 5730
 					}
5731 5731
 				}
5732
-				if ($tnefResolved===false) $attachments[]=$tnp;
5732
+				if ($tnefResolved === false) $attachments[] = $tnp;
5733 5733
 			}
5734 5734
 		}
5735 5735
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5744,9 +5744,9 @@  discard block
 block discarded – undo
5744 5744
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5745 5745
 	 *	return false if there's no attachments or failure
5746 5746
 	 */
5747
-	public function tnef_decoder( $data )
5747
+	public function tnef_decoder($data)
5748 5748
 	{
5749
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5749
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5750 5750
 		{
5751 5751
 			if (!class_exists($class))
5752 5752
 			{
@@ -5778,7 +5778,7 @@  discard block
 block discarded – undo
5778 5778
 				$tmp_part->setContents($data['stream']);
5779 5779
 				$tmp_part->setDescription($data['name']);
5780 5780
 
5781
-				$type = $data['type'] . '/' . $data['subtype'];
5781
+				$type = $data['type'].'/'.$data['subtype'];
5782 5782
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5783 5783
 				{
5784 5784
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5821,24 +5821,24 @@  discard block
 block discarded – undo
5821 5821
 	 *
5822 5822
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5823 5823
 	 */
5824
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5824
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5825 5825
 	{
5826
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5826
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5827 5827
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5828 5828
 		$attachments = array();
5829 5829
 		if ($tnef_parts)
5830 5830
 		{
5831
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5831
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5832 5832
 			{
5833 5833
 
5834 5834
 				$attachment = $part->getAllDispositionParameters();
5835 5835
 				$attachment['mimeType'] = $part->getType();
5836
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5836
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5837 5837
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5838 5838
 				if (empty($attachment['filename']))
5839 5839
 				{
5840
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5841
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5840
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5841
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5842 5842
 				}
5843 5843
 
5844 5844
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5862,10 +5862,10 @@  discard block
 block discarded – undo
5862 5862
 	 *
5863 5863
 	 * @return array
5864 5864
 	 */
5865
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5865
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5866 5866
 	{
5867 5867
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5868
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5868
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5869 5869
 
5870 5870
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5871 5871
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5878,36 +5878,36 @@  discard block
 block discarded – undo
5878 5878
 			'ids' => $uidsToFetch,
5879 5879
 		));
5880 5880
 		if (is_object($headersNew)) {
5881
-			foreach($headersNew as $id=>$_headerObject) {
5881
+			foreach ($headersNew as $id=>$_headerObject) {
5882 5882
 				$body = $_headerObject->getFullMsg();
5883 5883
 				if ($_partID != '')
5884 5884
 				{
5885 5885
 					$mailStructureObject = $_headerObject->getStructure();
5886 5886
 					$mailStructureObject->contentTypeMap();
5887 5887
 					$part = $mailStructureObject->getPart($_partID);
5888
-					$partDisposition = ($part?$part->getDisposition():'failed');
5889
-					if ($partDisposition=='failed')
5888
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5889
+					if ($partDisposition == 'failed')
5890 5890
 					{
5891 5891
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5892 5892
 					}
5893 5893
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5894 5894
 					// itself is only triggered to fetch attachments
5895
-					if (empty($partDisposition)) $partDisposition='attachment';
5896
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5895
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5896
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5897 5897
 					{
5898 5898
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5899 5899
 						$structure_mime = $part->getType();
5900 5900
 						$filename = $part->getName();
5901 5901
 						$charset = $part->getContentTypeParameter('charset');
5902 5902
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5903
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5903
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5904 5904
 						if ($_returnPart) return $part;
5905 5905
 					}
5906 5906
 				}
5907 5907
 			}
5908 5908
 		}
5909 5909
 		$ext = MimeMagic::mime2ext($structure_mime);
5910
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5910
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5911 5911
 		if (!$part)
5912 5912
 		{
5913 5913
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5925,20 +5925,20 @@  discard block
 block discarded – undo
5925 5925
 		// try guessing the mimetype, if we get the application/octet-stream
5926 5926
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
5927 5927
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5928
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5928
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5929 5929
 		{
5930 5930
 			//by now _uid is of type array
5931
-			$tnefResolved=false;
5932
-			$wantedPart=$_uid[0].'@'.$_partID;
5931
+			$tnefResolved = false;
5932
+			$wantedPart = $_uid[0].'@'.$_partID;
5933 5933
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5934 5934
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5935 5935
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5936 5936
 			// we need to build Something that meets the needs
5937 5937
 			if ($myTnef)
5938 5938
 			{
5939
-				foreach($myTnef->getParts() as $mime_id => $part)
5939
+				foreach ($myTnef->getParts() as $mime_id => $part)
5940 5940
 				{
5941
-					$tnefResolved=true;
5941
+					$tnefResolved = true;
5942 5942
 					$attachment = $part->getAllDispositionParameters();
5943 5943
 					$attachment['mimeType'] = $part->getType();
5944 5944
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5946,9 +5946,9 @@  discard block
 block discarded – undo
5946 5946
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5947 5947
 					{
5948 5948
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5949
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5949
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5950 5950
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5951
-						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']);
5951
+						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']);
5952 5952
 						$wmattach = $attachment;
5953 5953
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5954 5954
 
@@ -5958,7 +5958,7 @@  discard block
 block discarded – undo
5958 5958
 			if ($tnefResolved)
5959 5959
 			{
5960 5960
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5961
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5961
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5962 5962
 				$attachmentData = array(
5963 5963
 					'type'       => $wmattach['mimeType'],
5964 5964
 					'filename'   => $wmattach['filename'],
@@ -5982,21 +5982,21 @@  discard block
 block discarded – undo
5982 5982
 	 *	true:
5983 5983
 	 * @return Horde_Mime_Part
5984 5984
 	 */
5985
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5985
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5986 5986
 	{
5987 5987
 		// some static variables to avoid fetching the same mail multiple times
5988
-		static $uid=null, $part=null, $structure=null;
5988
+		static $uid = null, $part = null, $structure = null;
5989 5989
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5990 5990
 
5991
-		if(empty($_cid)) return false;
5991
+		if (empty($_cid)) return false;
5992 5992
 
5993 5993
 		if ($_uid != $uid || $_part != $part)
5994 5994
 		{
5995
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5995
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5996 5996
 		}
5997 5997
 		/** @var Horde_Mime_Part */
5998 5998
 		$attachment = null;
5999
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5999
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
6000 6000
 		{
6001 6001
 			$part = $structure->getPart($mime_id);
6002 6002
 
@@ -6048,16 +6048,16 @@  discard block
 block discarded – undo
6048 6048
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
6049 6049
 	 * @return Horde_Mime_Part
6050 6050
 	 */
6051
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
6051
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
6052 6052
 	{
6053
-		if (is_null($part)) return null;//new Horde_Mime_Part;
6053
+		if (is_null($part)) return null; //new Horde_Mime_Part;
6054 6054
 		$encoding = null;
6055 6055
 		$fetchAsBinary = true;
6056
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
6056
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
6057 6057
 		// we need to set content on structure to decode transfer encoding
6058 6058
 		$part->setContents(
6059 6059
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
6060
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
6060
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
6061 6061
 
6062 6062
 		return $part;
6063 6063
 	}
@@ -6075,17 +6075,17 @@  discard block
 block discarded – undo
6075 6075
 	 * @return the id of the message appended or exception
6076 6076
 	 * @throws Exception\WrongUserinput
6077 6077
 	 */
6078
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
6078
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
6079 6079
 	{
6080 6080
 		if (!is_resource($_header))
6081 6081
 		{
6082
-			if (stripos($_header,'message-id:')===false)
6082
+			if (stripos($_header, 'message-id:') === false)
6083 6083
 			{
6084 6084
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
6085 6085
 			}
6086 6086
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
6087
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
6088
-			$_header .= str_replace("\n","\r\n",$_body);
6087
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
6088
+			$_header .= str_replace("\n", "\r\n", $_body);
6089 6089
 		}
6090 6090
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
6091 6091
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -6103,7 +6103,7 @@  discard block
 block discarded – undo
6103 6103
 			// searched for the message-id then returning the uid found
6104 6104
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
6105 6105
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
6106
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
6106
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
6107 6107
 		}
6108 6108
 		catch (\Exception $e)
6109 6109
 		{
@@ -6115,7 +6115,7 @@  discard block
 block discarded – undo
6115 6115
 		//$messageid = true; // for debug reasons only
6116 6116
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
6117 6117
 		{
6118
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
6118
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
6119 6119
 			if ($list)
6120 6120
 			{
6121 6121
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -6155,27 +6155,27 @@  discard block
 block discarded – undo
6155 6155
 	 *				'attachments'=>$attachments,
6156 6156
 	 *				'headers'=>$headers,; boolean false on failure
6157 6157
 	 */
6158
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
6158
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
6159 6159
 	{
6160 6160
 			//echo __METHOD__." called for $uid,$partid <br>";
6161
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6161
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
6162 6162
 			if (empty($headers)) return false;
6163 6163
 			// dont force retrieval of the textpart, let mailClass preferences decide
6164
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6164
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
6165 6165
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
6166
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
6166
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
6167 6167
 			{
6168
-				foreach($bodyParts as $i => $part)
6168
+				foreach ($bodyParts as $i => $part)
6169 6169
 				{
6170
-					if ($bodyParts[$i]['mimeType']=='text/html')
6170
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
6171 6171
 					{
6172
-						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
6173
-						$bodyParts[$i]['mimeType']='text/plain';
6172
+						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
6173
+						$bodyParts[$i]['mimeType'] = 'text/plain';
6174 6174
 					}
6175 6175
 				}
6176 6176
 			}
6177 6177
 			//error_log(array2string($bodyParts));
6178
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6178
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
6179 6179
 
6180 6180
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6181 6181
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -6186,7 +6186,7 @@  discard block
 block discarded – undo
6186 6186
 
6187 6187
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6188 6188
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6189
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6189
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
6190 6190
 			$message = $headdata.$message;
6191 6191
 			//echo __METHOD__.'<br>';
6192 6192
 			//_debug_array($attachments);
@@ -6202,25 +6202,25 @@  discard block
 block discarded – undo
6202 6202
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
6203 6203
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
6204 6204
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
6205
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
6206
-						$headdata ='';
6205
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
6206
+						$headdata = '';
6207 6207
 						if ($mailcontent['headers'])
6208 6208
 						{
6209
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
6209
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
6210 6210
 						}
6211 6211
 						if ($mailcontent['message'])
6212 6212
 						{
6213
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6213
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6214 6214
 							$attachedMessages[] = array(
6215 6215
 								'type' => 'TEXT/PLAIN',
6216 6216
 								'name' => $mailcontent['subject'].'.txt',
6217 6217
 								'tmp_name' => $tempname,
6218 6218
 							);
6219
-							$tmpfile = fopen($tempname,'w');
6220
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
6219
+							$tmpfile = fopen($tempname, 'w');
6220
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
6221 6221
 							fclose($tmpfile);
6222 6222
 						}
6223
-						foreach($mailcontent['attachments'] as &$tmpval)
6223
+						foreach ($mailcontent['attachments'] as &$tmpval)
6224 6224
 						{
6225 6225
 							$attachedMessages[] = $tmpval;
6226 6226
 						}
@@ -6228,36 +6228,36 @@  discard block
 block discarded – undo
6228 6228
 					}
6229 6229
 					else
6230 6230
 					{
6231
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
6231
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
6232 6232
 
6233
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
6233
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
6234 6234
 						{
6235
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
6235
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
6236 6236
 							$attachments[$num]['attachment'] = $c->getContents();
6237 6237
 						}
6238 6238
 						// no attempt to convert, if we dont know about the charset
6239
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6239
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
6240 6240
 							// we do not try guessing the charset, if it is not set
6241 6241
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6242
-							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
6242
+							Translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
6243 6243
 						}
6244
-						if(in_array($attachments[$num]['name'], $file_list))
6244
+						if (in_array($attachments[$num]['name'], $file_list))
6245 6245
 						{
6246 6246
 							$dupe_count[$attachments[$num]['name']]++;
6247
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
6248
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
6247
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
6248
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
6249 6249
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
6250 6250
 						}
6251 6251
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
6252
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6253
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
6254
-						fwrite($tmpfile,$attachments[$num]['attachment']);
6252
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6253
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
6254
+						fwrite($tmpfile, $attachments[$num]['attachment']);
6255 6255
 						fclose($tmpfile);
6256 6256
 						$file_list[] = $attachments[$num]['name'];
6257 6257
 						unset($attachments[$num]['attachment']);
6258 6258
 					}
6259 6259
 				}
6260
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6260
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
6261 6261
 			}
6262 6262
 			return array(
6263 6263
 					'mailaddress'=>$mailaddress,
@@ -6279,10 +6279,10 @@  discard block
 block discarded – undo
6279 6279
 	{
6280 6280
 		$c = 0;
6281 6281
 		// use the standardIdentity
6282
-		foreach($_identities as $key => $acc) {
6283
-			if ($c==0) $identity = $acc;
6282
+		foreach ($_identities as $key => $acc) {
6283
+			if ($c == 0) $identity = $acc;
6284 6284
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6285
-			if ($key==$_profile_id) $identity = $acc;
6285
+			if ($key == $_profile_id) $identity = $acc;
6286 6286
 			$c++;
6287 6287
 		}
6288 6288
 		return $identity;
@@ -6294,29 +6294,29 @@  discard block
 block discarded – undo
6294 6294
 	 * @param bool createHTML do it with HTML breaks
6295 6295
 	 * @return string a preformatted string with the information of the header worked into it
6296 6296
 	 */
6297
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
6297
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
6298 6298
 	{
6299 6299
 		$headdata = null;
6300 6300
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6301
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6302
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6303
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6304
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6305
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6306
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6307
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6308
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6309
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
6301
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
6302
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
6303
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
6304
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
6305
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
6306
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
6307
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
6308
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
6309
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
6310 6310
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6311 6311
 		if (!empty($headdata))
6312 6312
 		{
6313
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6314
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
6315
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6313
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
6314
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
6315
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6316 6316
 		}
6317 6317
 		else
6318 6318
 		{
6319
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6319
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6320 6320
 		}
6321 6321
 		return $headdata;
6322 6322
 	}
@@ -6329,8 +6329,8 @@  discard block
 block discarded – undo
6329 6329
 	 */
6330 6330
 	static function adaptSubjectForImport($subject)
6331 6331
 	{
6332
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
6333
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
6332
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
6333
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
6334 6334
 		return $subject;
6335 6335
 	}
6336 6336
 
@@ -6342,15 +6342,15 @@  discard block
 block discarded – undo
6342 6342
 	static function convertAddressArrayToString($rfcAddressArray)
6343 6343
 	{
6344 6344
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
6345
-		$returnAddr ='';
6345
+		$returnAddr = '';
6346 6346
 		if (is_array($rfcAddressArray))
6347 6347
 		{
6348
-			foreach((array)$rfcAddressArray as $addressData) {
6348
+			foreach ((array)$rfcAddressArray as $addressData) {
6349 6349
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6350
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
6350
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
6351 6351
 					continue;
6352 6352
 				}
6353
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6353
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6354 6354
 					continue;
6355 6355
 				}
6356 6356
 				if ($addressData['RFC822_EMAIL'])
@@ -6359,7 +6359,7 @@  discard block
 block discarded – undo
6359 6359
 				}
6360 6360
 				else
6361 6361
 				{
6362
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
6362
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
6363 6363
 					$addressObjectA = self::parseAddressList($emailaddress);
6364 6364
 				}
6365 6365
 				$addressObject = $addressObjectA[0];
@@ -6368,10 +6368,10 @@  discard block
 block discarded – undo
6368 6368
 				//$mb =(string)$addressObject->mailbox;
6369 6369
 				//$h = (string)$addressObject->host;
6370 6370
 				//$p = (string)$addressObject->personal;
6371
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
6371
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
6372 6372
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
6373 6373
 				$buff = imap_rfc822_write_address($addressObject->mailbox, Horde_Idna::decode($addressObject->host), $addressObject->personal);
6374
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
6374
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
6375 6375
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6376 6376
 				$returnAddr .= $buff;
6377 6377
 			}
@@ -6379,8 +6379,8 @@  discard block
 block discarded – undo
6379 6379
 		else
6380 6380
 		{
6381 6381
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6382
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6383
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6382
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6383
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6384 6384
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6385 6385
 		}
6386 6386
 		return $returnAddr;
@@ -6394,12 +6394,12 @@  discard block
 block discarded – undo
6394 6394
 	 * @param string &$err error-message on error
6395 6395
 	 * @return string/boolean merged content or false on error
6396 6396
 	 */
6397
-	static function merge($content,$ids,$mimetype='')
6397
+	static function merge($content, $ids, $mimetype = '')
6398 6398
 	{
6399 6399
 		$mergeobj = new Contacts\Merge();
6400 6400
 
6401
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6402
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6401
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6402
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6403 6403
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6404 6404
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6405 6405
 		return $rv;
@@ -6441,12 +6441,12 @@  discard block
 block discarded – undo
6441 6441
 		else
6442 6442
 			settype($bytes, 'integer');
6443 6443
 
6444
-		return $bytes . ' ' . $type ;
6444
+		return $bytes.' '.$type;
6445 6445
 	}
6446 6446
 
6447 6447
 	static function detect_qp(&$sting) {
6448 6448
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6449
-		return preg_match("$needle",$string);
6449
+		return preg_match("$needle", $string);
6450 6450
 	}
6451 6451
 
6452 6452
 	/**
@@ -6459,11 +6459,11 @@  discard block
 block discarded – undo
6459 6459
 	 * @param string $_methodNline - Information where the log was taken
6460 6460
 	 * @return void
6461 6461
 	 */
6462
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6462
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6463 6463
 	{
6464 6464
 		if (is_null($_endtime)) $_endtime = microtime(true);
6465 6465
 		$usagetime = microtime(true) - $_starttime;
6466
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6466
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6467 6467
 	}
6468 6468
 
6469 6469
 	/**
@@ -6476,9 +6476,9 @@  discard block
 block discarded – undo
6476 6476
 	 *
6477 6477
 	 * @throws Exception\WrongUserinput
6478 6478
 	 */
6479
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6479
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6480 6480
 	{
6481
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6481
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6482 6482
 
6483 6483
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6484 6484
 		$importfailed = $tmpFileName = false;
@@ -6488,7 +6488,7 @@  discard block
 block discarded – undo
6488 6488
 			$importfailed = true;
6489 6489
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6490 6490
 		}
6491
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6491
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6492 6492
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6493 6493
 		{
6494 6494
 			// ensure existance of eGW temp dir
@@ -6496,7 +6496,7 @@  discard block
 block discarded – undo
6496 6496
 			// and different from any other temp file location set in php.ini
6497 6497
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6498 6498
 			{
6499
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6499
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6500 6500
 			}
6501 6501
 
6502 6502
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6523,14 +6523,14 @@  discard block
 block discarded – undo
6523 6523
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6524 6524
 			// so we check for the suffix too
6525 6525
 			// trust vfs mime-types, trust the mimetype if it contains a method
6526
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6526
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6527 6527
 			{
6528
-				$buff = explode('.',$_formData['name']);
6528
+				$buff = explode('.', $_formData['name']);
6529 6529
 				$suffix = '';
6530 6530
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6531 6531
 				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
6532 6532
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6533
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6533
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6534 6534
 				{
6535 6535
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6536 6536
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6545,13 +6545,13 @@  discard block
 block discarded – undo
6545 6545
 			if ($reqMimeType)
6546 6546
 			{
6547 6547
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6548
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6548
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6549 6549
 				{
6550 6550
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6551 6551
 					{
6552 6552
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6553 6553
 						$importfailed = true;
6554
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6554
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6555 6555
 					}
6556 6556
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6557 6557
 					{
@@ -6560,17 +6560,17 @@  discard block
 block discarded – undo
6560 6560
 				}
6561 6561
 			}
6562 6562
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6563
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6563
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6564 6564
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6565 6565
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6566 6566
 
6567
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6567
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6568 6568
 			{
6569
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6569
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6570 6570
 			}
6571 6571
 			elseif (is_uploaded_file($_formData['file']))
6572 6572
 			{
6573
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);	// requirement for safe_mode!
6573
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); // requirement for safe_mode!
6574 6574
 			}
6575 6575
 			else
6576 6576
 			{
@@ -6579,7 +6579,7 @@  discard block
 block discarded – undo
6579 6579
 		} else {
6580 6580
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6581 6581
 			$importfailed = true;
6582
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6582
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6583 6583
 		}
6584 6584
 		if ($importfailed == true)
6585 6585
 		{
@@ -6587,7 +6587,7 @@  discard block
 block discarded – undo
6587 6587
 		}
6588 6588
 		else
6589 6589
 		{
6590
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6590
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6591 6591
 			{
6592 6592
 				Vfs::load_wrapper('vfs');
6593 6593
 			}
@@ -6612,7 +6612,7 @@  discard block
 block discarded – undo
6612 6612
 		$images = null;
6613 6613
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6614 6614
 		{
6615
-			foreach($images[2] as $i => $url)
6615
+			foreach ($images[2] as $i => $url)
6616 6616
 			{
6617 6617
 				//$isData = false;
6618 6618
 				$basedir = $data = '';
@@ -6624,20 +6624,20 @@  discard block
 block discarded – undo
6624 6624
 					$filename = basename($url);
6625 6625
 					if (($directory = dirname($url)) == '.') $directory = '';
6626 6626
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6627
-					$mimeType  = MimeMagic::ext2mime($ext);
6628
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6627
+					$mimeType = MimeMagic::ext2mime($ext);
6628
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6629 6629
 					$myUrl = $directory.$filename;
6630
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6630
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6631 6631
 					{
6632
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6632
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6633 6633
 					}
6634 6634
 					// use vfs instead of url containing webdav.php
6635 6635
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6636 6636
 					// webdav.php urls as vfs
6637
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6637
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6638 6638
 					{
6639 6639
 						Vfs::load_wrapper('vfs');
6640
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6640
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6641 6641
 						$basedir = 'vfs://default';
6642 6642
 						$needTempFile = false;
6643 6643
 					}
@@ -6650,11 +6650,11 @@  discard block
 block discarded – undo
6650 6650
 						// Strips the url and store it into a temp for further procss
6651 6651
 						$tmp_url = html_entity_decode($myUrl);
6652 6652
 
6653
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6653
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6654 6654
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6655 6655
 						{
6656 6656
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6657
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6657
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6658 6658
 							$mail_bo->closeConnection();
6659 6659
 							if ($attachment)
6660 6660
 							{
@@ -6665,32 +6665,32 @@  discard block
 block discarded – undo
6665 6665
 						}
6666 6666
 					}
6667 6667
 
6668
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6669
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6668
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6669
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6670 6670
 				}
6671
-				if (substr($url,0,strlen('data:'))=='data:')
6671
+				if (substr($url, 0, strlen('data:')) == 'data:')
6672 6672
 				{
6673 6673
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6674 6674
 					// we only support base64 encoded data
6675
-					$tmp = substr($url,strlen('data:'));
6676
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6675
+					$tmp = substr($url, strlen('data:'));
6676
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6677 6677
 					$data = base64_decode($data_base64);
6678 6678
 					// FF currently does NOT add any mime-type
6679 6679
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6680 6680
 					{
6681 6681
 						$mimeType = MimeMagic::analyze_data($data);
6682 6682
 					}
6683
-					list($what,$exactly) = explode('/',$mimeType);
6683
+					list($what, $exactly) = explode('/', $mimeType);
6684 6684
 					$needTempFile = true;
6685
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6685
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6686 6686
 				}
6687 6687
 				if ($data || $needTempFile === false)
6688 6688
 				{
6689 6689
 					if ($needTempFile)
6690 6690
 					{
6691
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6692
-						$tmpfile = fopen($attachment_file,'w');
6693
-						fwrite($tmpfile,$data);
6691
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6692
+						$tmpfile = fopen($attachment_file, 'w');
6693
+						fwrite($tmpfile, $data);
6694 6694
 						fclose($tmpfile);
6695 6695
 					}
6696 6696
 					else
@@ -6701,7 +6701,7 @@  discard block
 block discarded – undo
6701 6701
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6702 6702
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6703 6703
 					// on upload. filename itself is not sufficient to determine the sameness of images
6704
-					$cid = 'cid:' . md5($attachment_file);
6704
+					$cid = 'cid:'.md5($attachment_file);
6705 6705
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), urldecode($filename), $mimeType) !== null)
6706 6706
 					{
6707 6707
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6730,10 +6730,10 @@  discard block
 block discarded – undo
6730 6730
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6731 6731
 	 * @return mixed array of messages with success and failed messages or exception
6732 6732
 	 */
6733
-	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6733
+	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6734 6734
 	{
6735 6735
 		$importfailed = false;
6736
-		$processStats = array('success'=>array(),'failed'=>array());
6736
+		$processStats = array('success'=>array(), 'failed'=>array());
6737 6737
 		if (empty($SendAndMergeTocontacts))
6738 6738
 		{
6739 6739
 			$importfailed = true;
@@ -6774,7 +6774,7 @@  discard block
 block discarded – undo
6774 6774
 				$_folder = $this->getSentFolder();
6775 6775
 			}
6776 6776
 			$delimiter = $this->getHierarchyDelimiter();
6777
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6777
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6778 6778
 			if ($importfailed === false)
6779 6779
 			{
6780 6780
 				$Subject = $mailObject->getHeader('Subject');
@@ -6792,9 +6792,9 @@  discard block
 block discarded – undo
6792 6792
 				{
6793 6793
 					$mailObject->clearReplyTos();
6794 6794
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6795
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6795
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6796 6796
 
6797
-					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']),Mail::generateIdentityString($activeMailProfile,false));
6797
+					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']), Mail::generateIdentityString($activeMailProfile, false));
6798 6798
 				}
6799 6799
 				foreach ($SendAndMergeTocontacts as $k => $val)
6800 6800
 				{
@@ -6808,12 +6808,12 @@  discard block
 block discarded – undo
6808 6808
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6809 6809
 
6810 6810
 						// Parse destinations for placeholders
6811
-						foreach(Mailer::$type2header as $type => $h)
6811
+						foreach (Mailer::$type2header as $type => $h)
6812 6812
 						{
6813 6813
 							//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));
6814
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6815
-							$mailObject->addAddress($merged,'',$type);
6816
-							if($type == 'to')
6814
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6815
+							$mailObject->addAddress($merged, '', $type);
6816
+							if ($type == 'to')
6817 6817
 							{
6818 6818
 								$email = $merged;
6819 6819
 							}
@@ -6826,26 +6826,26 @@  discard block
 block discarded – undo
6826 6826
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6827 6827
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6828 6828
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6829
-							if($email)
6829
+							if ($email)
6830 6830
 							{
6831 6831
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6832 6832
 							}
6833 6833
 						}
6834 6834
 
6835 6835
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6836
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6836
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6837 6837
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6838 6838
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6839
-							self::generateIdentityString($activeMailProfile,false));
6839
+							self::generateIdentityString($activeMailProfile, false));
6840 6840
 
6841 6841
 						$mailObject->removeHeader('Message-ID');
6842 6842
 						$mailObject->removeHeader('Date');
6843 6843
 						$mailObject->clearCustomHeaders();
6844 6844
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6845 6845
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6846
-						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));
6846
+						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));
6847 6847
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6848
-						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));
6848
+						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));
6849 6849
 
6850 6850
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6851 6851
 						// set a higher timeout for big messages
@@ -6854,7 +6854,7 @@  discard block
 block discarded – undo
6854 6854
 						try {
6855 6855
 							$mailObject->send();
6856 6856
 						}
6857
-						catch(Exception $e) {
6857
+						catch (Exception $e) {
6858 6858
 							$sendOK = false;
6859 6859
 							$errorInfo = $e->getMessage();
6860 6860
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6868,41 +6868,41 @@  discard block
 block discarded – undo
6868 6868
 						$mailObject->clearCustomHeaders();
6869 6869
 
6870 6870
 						// Parse destinations for placeholders
6871
-						foreach(Mailer::$type2header as $type => $h)
6871
+						foreach (Mailer::$type2header as $type => $h)
6872 6872
 						{
6873
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6873
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6874 6874
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6875
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6875
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6876 6876
 						}
6877 6877
 
6878 6878
 						// No addresses from placeholders?  Treat it as just a contact ID
6879
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6879
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6880 6880
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6881 6881
 						{
6882 6882
 							$contact = $bo_merge->contacts->read($val);
6883 6883
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6884 6884
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6885 6885
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6886
-							if($email)
6886
+							if ($email)
6887 6887
 							{
6888 6888
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6889 6889
 							}
6890 6890
 						}
6891 6891
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6892 6892
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6893
-						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));
6893
+						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));
6894 6894
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6895
-						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));
6895
+						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));
6896 6896
 						$_folder = $this->getDraftFolder();
6897 6897
 					}
6898 6898
 					if ($sendOK || $openAsDraft)
6899 6899
 					{
6900
-						if ($this->folderExists($_folder,true))
6900
+						if ($this->folderExists($_folder, true))
6901 6901
 						{
6902
-						    if($this->isSentFolder($_folder))
6902
+						    if ($this->isSentFolder($_folder))
6903 6903
 							{
6904 6904
 						        $flags = '\\Seen';
6905
-						    } elseif($this->isDraftFolder($_folder)) {
6905
+						    } elseif ($this->isDraftFolder($_folder)) {
6906 6906
 						        $flags = '\\Draft';
6907 6907
 						    } else {
6908 6908
 						        $flags = '';
@@ -6910,7 +6910,7 @@  discard block
 block discarded – undo
6910 6910
 							$savefailed = false;
6911 6911
 							try
6912 6912
 							{
6913
-								$messageUid =$this->appendMessage($_folder,
6913
+								$messageUid = $this->appendMessage($_folder,
6914 6914
 									$mailObject->getRaw(),
6915 6915
 									null,
6916 6916
 									$flags);
@@ -6918,10 +6918,10 @@  discard block
 block discarded – undo
6918 6918
 							catch (\Exception\WrongUserinput $e)
6919 6919
 							{
6920 6920
 								$savefailed = true;
6921
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6921
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6922 6922
 							}
6923 6923
 							// no send, save successful, and message_uid present
6924
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6924
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6925 6925
 							{
6926 6926
 								$importID = $messageUid;
6927 6927
 								$openComposeWindow = true;
@@ -6930,20 +6930,20 @@  discard block
 block discarded – undo
6930 6930
 						else
6931 6931
 						{
6932 6932
 							$savefailed = true;
6933
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6933
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6934 6934
 						}
6935 6935
 						if ($sendOK)
6936 6936
 						{
6937
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6937
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6938 6938
 						}
6939 6939
 						else
6940 6940
 						{
6941
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6941
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6942 6942
 						}
6943 6943
 					}
6944
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6944
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6945 6945
 					{
6946
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6946
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6947 6947
 					}
6948 6948
 				}
6949 6949
 			}
@@ -7022,16 +7022,16 @@  discard block
 block discarded – undo
7022 7022
 
7023 7023
 		if (is_string($message))
7024 7024
 		{
7025
-			$start = substr($message,0, strpos($message, $eol));
7025
+			$start = substr($message, 0, strpos($message, $eol));
7026 7026
 			$body = substr($message, strlen($start));
7027 7027
 			$hlength = strpos($start, $eol) ? strpos($start, $eol) : strlen($start);
7028
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$hlength));
7029
-			foreach($headers->toArray() as $header => $value)
7028
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $hlength));
7029
+			foreach ($headers->toArray() as $header => $value)
7030 7030
 			{
7031 7031
 				$needsReplacement = false;
7032
-				foreach((array)$value as $val)
7032
+				foreach ((array)$value as $val)
7033 7033
 				{
7034
-					if (strlen($val)+ strlen($header) > 900)
7034
+					if (strlen($val) + strlen($header) > 900)
7035 7035
 					{
7036 7036
 						$needsReplacement = $needsFix = true;
7037 7037
 					}
@@ -7053,7 +7053,7 @@  discard block
 block discarded – undo
7053 7053
 	 * @param boolean $force8bitOnPrimaryPart (default false. force transferEncoding and charset to 8bit/utf8 if we have a textpart as primaryPart)
7054 7054
 	 * @throws Exception\WrongParameter when the required Horde_Mail_Part not found
7055 7055
 	 */
7056
-	function parseRawMessageIntoMailObject(Mailer $mailer, $message, $force8bitOnPrimaryPart=false)
7056
+	function parseRawMessageIntoMailObject(Mailer $mailer, $message, $force8bitOnPrimaryPart = false)
7057 7057
 	{
7058 7058
 		if (is_string($message) || is_resource($message))
7059 7059
 		{
@@ -7062,7 +7062,7 @@  discard block
 block discarded – undo
7062 7062
 
7063 7063
 			$structure = Horde_Mime_Part::parseMessage($message);
7064 7064
 			//error_log(__METHOD__.__LINE__.'#'.$structure->getPrimaryType().'#');
7065
-			if ($force8bitOnPrimaryPart&&$structure->getPrimaryType()=='text')
7065
+			if ($force8bitOnPrimaryPart && $structure->getPrimaryType() == 'text')
7066 7066
 			{
7067 7067
 				$structure->setTransferEncoding('8bit');
7068 7068
 				$structure->setCharset('utf-8');
@@ -7071,19 +7071,18 @@  discard block
 block discarded – undo
7071 7071
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
7072 7072
 
7073 7073
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
7074
-			$start = is_string($message) ? substr($message, 0, 8192) :
7075
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
7074
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
7076 7075
 
7077 7076
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
7078
-			if ($length===false) $length = strlen($start);
7079
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
7077
+			if ($length === false) $length = strlen($start);
7078
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
7080 7079
 
7081
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
7080
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
7082 7081
 			{
7083
-				foreach((array)$value as $n => $val)
7082
+				foreach ((array)$value as $n => $val)
7084 7083
 				{
7085 7084
 					$overwrite = !$n;
7086
-					switch($header)
7085
+					switch ($header)
7087 7086
 					{
7088 7087
 						case 'Content-Transfer-Encoding':
7089 7088
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -7110,7 +7109,7 @@  discard block
 block discarded – undo
7110 7109
 		}
7111 7110
 		else
7112 7111
 		{
7113
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
7112
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
7114 7113
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
7115 7114
 		}
7116 7115
 	}
@@ -7124,50 +7123,50 @@  discard block
 block discarded – undo
7124 7123
 	 * @param string $default_domain
7125 7124
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
7126 7125
 	 */
7127
-	public static function parseAddressList($addresses, $default_domain=null)
7126
+	public static function parseAddressList($addresses, $default_domain = null)
7128 7127
 	{
7129 7128
 		$rfc822 = new Horde_Mail_Rfc822();
7130 7129
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
7131 7130
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
7132
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
7131
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
7133 7132
 		{
7134 7133
 			$matches = array();
7135
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
7134
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
7136 7135
 			//error_log(__METHOD__.__LINE__.array2string($matches));
7137
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
7138
-			$addresses = implode(',',$matches[0]);
7136
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
7137
+			$addresses = implode(',', $matches[0]);
7139 7138
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
7140 7139
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
7141 7140
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
7142 7141
 		}
7143
-		$previousFailed=false;
7142
+		$previousFailed = false;
7144 7143
 		$ret2 = new Horde_Mail_Rfc822_List();
7145 7144
 		// handle known problems on emailaddresses
7146
-		foreach($ret as $i => $adr)
7145
+		foreach ($ret as $i => $adr)
7147 7146
 		{
7148 7147
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
7149
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
7150
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
7148
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
7149
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
7151 7150
 			{
7152
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
7153
-				$adr->host = str_replace("'","",$adr->host);
7151
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
7152
+				$adr->host = str_replace("'", "", $adr->host);
7154 7153
 			}
7155 7154
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
7156 7155
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
7157 7156
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
7158 7157
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
7159 7158
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
7160
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
7159
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
7161 7160
 			{
7162
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
7163
-				$previousFailed=true;
7161
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
7162
+				$previousFailed = true;
7164 7163
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
7165 7164
 			}
7166 7165
 			else
7167 7166
 			{
7168
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
7167
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
7169 7168
 				$remember = '';
7170
-				$previousFailed=false;
7169
+				$previousFailed = false;
7171 7170
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
7172 7171
 				$ret2->add($adr);
7173 7172
 			}
@@ -7183,7 +7182,7 @@  discard block
 block discarded – undo
7183 7182
 	 * @param string $_folder
7184 7183
 	 * @return boolean
7185 7184
 	 */
7186
-	function sendMDN($uid,$_folder)
7185
+	function sendMDN($uid, $_folder)
7187 7186
 	{
7188 7187
 		$acc = Mail\Account::read($this->profileID);
7189 7188
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
@@ -7213,7 +7212,7 @@  discard block
 block discarded – undo
7213 7212
 	 */
7214 7213
 	function addAccount($_hookValues)
7215 7214
 	{
7216
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7215
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7217 7216
 
7218 7217
 	}
7219 7218
 
@@ -7227,7 +7226,7 @@  discard block
 block discarded – undo
7227 7226
 	 */
7228 7227
 	function deleteAccount($_hookValues)
7229 7228
 	{
7230
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7229
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7231 7230
 
7232 7231
 	}
7233 7232
 
@@ -7241,7 +7240,7 @@  discard block
 block discarded – undo
7241 7240
 	 */
7242 7241
 	function updateAccount($_hookValues)
7243 7242
 	{
7244
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7243
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7245 7244
 
7246 7245
 	}
7247 7246
 }
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_propfind.php 3 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -42,244 +42,244 @@
 block discarded – undo
42 42
  */
43 43
 class _parse_propfind
44 44
 {
45
-    /**
46
-     * success state flag
47
-     *
48
-     * @var bool
49
-     * @access public
50
-     */
51
-    var $success = false;
45
+	/**
46
+	 * success state flag
47
+	 *
48
+	 * @var bool
49
+	 * @access public
50
+	 */
51
+	var $success = false;
52 52
 
53
-    /**
54
-     * found properties are collected here
55
-     *
56
-     * @var array
57
-     * @access public
58
-     */
59
-    var $props = false;
53
+	/**
54
+	 * found properties are collected here
55
+	 *
56
+	 * @var array
57
+	 * @access public
58
+	 */
59
+	var $props = false;
60 60
 
61
-    /**
62
-     * found (CalDAV) filters are collected here
63
-     *
64
-     * @var array
65
-     * @access public
66
-     */
67
-    var $filters = false;
61
+	/**
62
+	 * found (CalDAV) filters are collected here
63
+	 *
64
+	 * @var array
65
+	 * @access public
66
+	 */
67
+	var $filters = false;
68 68
 
69
-    /**
70
-     * found other tags, eg. CalDAV calendar-multiget href's
71
-     *
72
-     * @var array
73
-     * @access public
74
-     */
75
-    var $other = false;
69
+	/**
70
+	 * found other tags, eg. CalDAV calendar-multiget href's
71
+	 *
72
+	 * @var array
73
+	 * @access public
74
+	 */
75
+	var $other = false;
76 76
 
77
-    /**
78
-     * what we are currently parsing: props or filters
79
-     *
80
-     * @var array
81
-     * @access private
82
-     */
83
-    var $use = 'props';
77
+	/**
78
+	 * what we are currently parsing: props or filters
79
+	 *
80
+	 * @var array
81
+	 * @access private
82
+	 */
83
+	var $use = 'props';
84 84
 
85
-    /**
86
-     * Root tag, usually 'propfind' for PROPFIND, but can be eg. 'calendar-query' or 'calendar-multiget' for CalDAV REPORT
87
-     *
88
-     * @var array with keys 'name' and 'ns'
89
-     */
90
-    var $root;
85
+	/**
86
+	 * Root tag, usually 'propfind' for PROPFIND, but can be eg. 'calendar-query' or 'calendar-multiget' for CalDAV REPORT
87
+	 *
88
+	 * @var array with keys 'name' and 'ns'
89
+	 */
90
+	var $root;
91 91
 
92
-    /**
93
-     * internal tag nesting depth counter
94
-     *
95
-     * @var int
96
-     * @access private
97
-     */
98
-    var $depth = 0;
92
+	/**
93
+	 * internal tag nesting depth counter
94
+	 *
95
+	 * @var int
96
+	 * @access private
97
+	 */
98
+	var $depth = 0;
99 99
 
100
-    /**
101
-     * On return whole request, if $store_request == true was specified in constructor
102
-     *
103
-     * @var string
104
-     */
105
-    var $request;
100
+	/**
101
+	 * On return whole request, if $store_request == true was specified in constructor
102
+	 *
103
+	 * @var string
104
+	 */
105
+	var $request;
106 106
 
107
-    /**
108
-     * constructor
109
-     *
110
-     * @access public
111
-     * @param string $path
112
-     * @param boolean $store_request =false if true whole request data will be made available in $this->request
113
-     */
114
-    function __construct($path, $store_request=false)
115
-    {
116
-        // success state flag
117
-        $this->success = true;
107
+	/**
108
+	 * constructor
109
+	 *
110
+	 * @access public
111
+	 * @param string $path
112
+	 * @param boolean $store_request =false if true whole request data will be made available in $this->request
113
+	 */
114
+	function __construct($path, $store_request=false)
115
+	{
116
+		// success state flag
117
+		$this->success = true;
118 118
 
119
-        // property storage array
120
-        $this->props = array();
119
+		// property storage array
120
+		$this->props = array();
121 121
 
122
-        // internal tag depth counter
123
-        $this->depth = 0;
122
+		// internal tag depth counter
123
+		$this->depth = 0;
124 124
 
125
-        // remember if any input was parsed
126
-        $had_input = false;
125
+		// remember if any input was parsed
126
+		$had_input = false;
127 127
 
128
-        // open input stream
129
-        $f_in = fopen($path, "r");
130
-        if (!$f_in) {
131
-            $this->success = false;
132
-            return;
133
-        }
128
+		// open input stream
129
+		$f_in = fopen($path, "r");
130
+		if (!$f_in) {
131
+			$this->success = false;
132
+			return;
133
+		}
134 134
 
135
-        // create XML parser
136
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
135
+		// create XML parser
136
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
137 137
 
138
-        // set tag and data handlers
139
-        xml_set_element_handler($xml_parser,
140
-                                array(&$this, "_startElement"),
141
-                                array(&$this, "_endElement"));
138
+		// set tag and data handlers
139
+		xml_set_element_handler($xml_parser,
140
+								array(&$this, "_startElement"),
141
+								array(&$this, "_endElement"));
142 142
 
143 143
 		xml_set_character_data_handler($xml_parser,
144
-            array(&$this,'_charData')
145
-        );
144
+			array(&$this,'_charData')
145
+		);
146 146
 
147
-        // we want a case sensitive parser
148
-        xml_parser_set_option($xml_parser,
149
-                              XML_OPTION_CASE_FOLDING, false);
147
+		// we want a case sensitive parser
148
+		xml_parser_set_option($xml_parser,
149
+							  XML_OPTION_CASE_FOLDING, false);
150 150
 
151
-        // parse input
152
-        while ($this->success && !feof($f_in)) {
153
-            $line = fgets($f_in);
154
-            if ($store_request) $this->request .= $line;
155
-            if (is_string($line)) {
156
-                $had_input = true;
157
-                $this->success &= xml_parse($xml_parser, $line, false);
158
-            }
159
-        }
151
+		// parse input
152
+		while ($this->success && !feof($f_in)) {
153
+			$line = fgets($f_in);
154
+			if ($store_request) $this->request .= $line;
155
+			if (is_string($line)) {
156
+				$had_input = true;
157
+				$this->success &= xml_parse($xml_parser, $line, false);
158
+			}
159
+		}
160 160
 
161
-        // finish parsing
162
-        if ($had_input) {
163
-            $this->success &= xml_parse($xml_parser, "", true);
164
-        }
161
+		// finish parsing
162
+		if ($had_input) {
163
+			$this->success &= xml_parse($xml_parser, "", true);
164
+		}
165 165
 
166
-        // free parser
167
-        xml_parser_free($xml_parser);
166
+		// free parser
167
+		xml_parser_free($xml_parser);
168 168
 
169
-        // close input stream
170
-        fclose($f_in);
169
+		// close input stream
170
+		fclose($f_in);
171 171
 
172
-        // if no input was parsed it was a request
173
-        if(!count($this->props)) $this->props = "all"; // default
174
-    }
172
+		// if no input was parsed it was a request
173
+		if(!count($this->props)) $this->props = "all"; // default
174
+	}
175 175
 
176 176
 
177
-    /**
178
-     * start tag handler
179
-     *
180
-     * @access private
181
-     * @param  resource  parser
182
-     * @param  string    tag name
183
-     * @param  array     tag attributes
184
-     */
185
-    function _startElement($parser, $name, $attrs)
186
-    {
187
-        // name space handling
188
-        if (strstr($name, " ")) {
189
-            list($ns, $tag) = explode(" ", $name);
190
-            if ($ns == "")
191
-                $this->success = false;
192
-        } else {
193
-            $ns  = "";
194
-            $tag = $name;
195
-        }
177
+	/**
178
+	 * start tag handler
179
+	 *
180
+	 * @access private
181
+	 * @param  resource  parser
182
+	 * @param  string    tag name
183
+	 * @param  array     tag attributes
184
+	 */
185
+	function _startElement($parser, $name, $attrs)
186
+	{
187
+		// name space handling
188
+		if (strstr($name, " ")) {
189
+			list($ns, $tag) = explode(" ", $name);
190
+			if ($ns == "")
191
+				$this->success = false;
192
+		} else {
193
+			$ns  = "";
194
+			$tag = $name;
195
+		}
196 196
 
197
-        // record root tag
198
-        if ($this->depth == 0) {
199
-        	$this->root = array('name' => $tag, 'xmlns' => $ns, 'attrs' => $attrs);
200
-        }
201
-        // special tags at level 1: <allprop> and <propname>
202
-        if ($this->depth == 1) {
203
-         	$this->use = 'props';
204
-            switch ($tag)
205
-            {
206
-            	case "allprop":
207
-                	$this->props = "all";
197
+		// record root tag
198
+		if ($this->depth == 0) {
199
+			$this->root = array('name' => $tag, 'xmlns' => $ns, 'attrs' => $attrs);
200
+		}
201
+		// special tags at level 1: <allprop> and <propname>
202
+		if ($this->depth == 1) {
203
+		 	$this->use = 'props';
204
+			switch ($tag)
205
+			{
206
+				case "allprop":
207
+					$this->props = "all";
208 208
 					break;
209
-            	case "propname":
210
-               		$this->props = "names";
211
-               		break;
212
-            	case 'prop':
213
-           			break;
214
-            	case 'filter':
215
-            		$this->use = 'filters';
216
-            		$this->filters['attrs'] = $attrs;	// need attrs eg. <filters test="(anyof|alloff)">
217
-            		break;
218
-            	default:
219
-            		$this->use = 'other';
220
-            		break;
221
-            }
222
-        }
209
+				case "propname":
210
+			   		$this->props = "names";
211
+			   		break;
212
+				case 'prop':
213
+		   			break;
214
+				case 'filter':
215
+					$this->use = 'filters';
216
+					$this->filters['attrs'] = $attrs;	// need attrs eg. <filters test="(anyof|alloff)">
217
+					break;
218
+				default:
219
+					$this->use = 'other';
220
+					break;
221
+			}
222
+		}
223 223
 		//echo "$this->depth: use=$this->use $ns:$tag attrs=".array2string($attrs)."\n";
224 224
 
225
-        // requested properties are found at level 2
226
-        // CalDAV filters can be at deeper levels too and we need the attrs, same for other tags (eg. multiget href's)
227
-        if ($this->depth == 2 || $this->use == 'filters' && $this->depth >= 2 || $this->use == 'other' ||
228
-        	$this->use == 'props' && $this->depth >= 2) {
229
-            $prop = array("name" => $tag);
230
-            if ($ns)
231
-                $prop["xmlns"] = $ns;
232
-            if ($this->use != 'props' || $this->depth > 2) {
233
-            	$prop['attrs'] = $attrs;
234
-            	$prop['depth'] = $this->depth;
235
-            }
236
-            // collect sub-elements of props in the original props children attribute
237
-            // eg. required for CalDAV <calendar-data><expand start="..." end="..."/></calendar-data>
238
-            if ($this->use == 'props' && $this->depth > 2)
239
-            {
240
-            	$this->last_prop['children'][$tag] = $prop;
241
-            }
242
-            else
243
-            {
244
-	         	// this can happen if we have allprop and prop in one propfind:
245
-	        	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
246
-	            if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use});
247
-	            $this->{$this->use}[] =& $prop;
248
-	            $this->last_prop =& $prop;
249
-	            unset($prop);
250
-            }
251
-        }
225
+		// requested properties are found at level 2
226
+		// CalDAV filters can be at deeper levels too and we need the attrs, same for other tags (eg. multiget href's)
227
+		if ($this->depth == 2 || $this->use == 'filters' && $this->depth >= 2 || $this->use == 'other' ||
228
+			$this->use == 'props' && $this->depth >= 2) {
229
+			$prop = array("name" => $tag);
230
+			if ($ns)
231
+				$prop["xmlns"] = $ns;
232
+			if ($this->use != 'props' || $this->depth > 2) {
233
+				$prop['attrs'] = $attrs;
234
+				$prop['depth'] = $this->depth;
235
+			}
236
+			// collect sub-elements of props in the original props children attribute
237
+			// eg. required for CalDAV <calendar-data><expand start="..." end="..."/></calendar-data>
238
+			if ($this->use == 'props' && $this->depth > 2)
239
+			{
240
+				$this->last_prop['children'][$tag] = $prop;
241
+			}
242
+			else
243
+			{
244
+			 	// this can happen if we have allprop and prop in one propfind:
245
+				// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
246
+				if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use});
247
+				$this->{$this->use}[] =& $prop;
248
+				$this->last_prop =& $prop;
249
+				unset($prop);
250
+			}
251
+		}
252 252
 
253
-        // increment depth count
254
-        $this->depth++;
255
-    }
253
+		// increment depth count
254
+		$this->depth++;
255
+	}
256 256
 
257 257
 
258
-    /**
259
-     * end tag handler
260
-     *
261
-     * @access private
262
-     * @param  resource  parser
263
-     * @param  string    tag name
264
-     */
265
-    function _endElement($parser, $name)
266
-    {
267
-        // here we only need to decrement the depth count
268
-        $this->depth--;
269
-    }
258
+	/**
259
+	 * end tag handler
260
+	 *
261
+	 * @access private
262
+	 * @param  resource  parser
263
+	 * @param  string    tag name
264
+	 */
265
+	function _endElement($parser, $name)
266
+	{
267
+		// here we only need to decrement the depth count
268
+		$this->depth--;
269
+	}
270 270
 
271 271
 
272
-    /**
273
-     * char data handler for non prop tags, eg. href's in CalDAV multiget, or filter contents
274
-     *
275
-     * @access private
276
-     * @param  resource  parser
277
-     * @param  string    character data
278
-     */
279
-    function _charData($parser, $data)
280
-    {
281
-        if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) {
282
-        	$this->{$this->use}[$n-1]['data'] = $data;
283
-        }
284
-    }
272
+	/**
273
+	 * char data handler for non prop tags, eg. href's in CalDAV multiget, or filter contents
274
+	 *
275
+	 * @access private
276
+	 * @param  resource  parser
277
+	 * @param  string    character data
278
+	 */
279
+	function _charData($parser, $data)
280
+	{
281
+		if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) {
282
+			$this->{$this->use}[$n-1]['data'] = $data;
283
+		}
284
+	}
285 285
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      * @param string $path
112 112
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
113 113
      */
114
-    function __construct($path, $store_request=false)
114
+    function __construct($path, $store_request = false)
115 115
     {
116 116
         // success state flag
117 117
         $this->success = true;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                                 array(&$this, "_endElement"));
142 142
 
143 143
 		xml_set_character_data_handler($xml_parser,
144
-            array(&$this,'_charData')
144
+            array(&$this, '_charData')
145 145
         );
146 146
 
147 147
         // we want a case sensitive parser
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         fclose($f_in);
171 171
 
172 172
         // if no input was parsed it was a request
173
-        if(!count($this->props)) $this->props = "all"; // default
173
+        if (!count($this->props)) $this->props = "all"; // default
174 174
     }
175 175
 
176 176
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
            			break;
214 214
             	case 'filter':
215 215
             		$this->use = 'filters';
216
-            		$this->filters['attrs'] = $attrs;	// need attrs eg. <filters test="(anyof|alloff)">
216
+            		$this->filters['attrs'] = $attrs; // need attrs eg. <filters test="(anyof|alloff)">
217 217
             		break;
218 218
             	default:
219 219
             		$this->use = 'other';
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	         	// this can happen if we have allprop and prop in one propfind:
245 245
 	        	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
246 246
 	            if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use});
247
-	            $this->{$this->use}[] =& $prop;
248
-	            $this->last_prop =& $prop;
247
+	            $this->{$this->use}[] = & $prop;
248
+	            $this->last_prop = & $prop;
249 249
 	            unset($prop);
250 250
             }
251 251
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
     function _charData($parser, $data)
280 280
     {
281 281
         if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) {
282
-        	$this->{$this->use}[$n-1]['data'] = $data;
282
+        	$this->{$this->use}[$n - 1]['data'] = $data;
283 283
         }
284 284
     }
285 285
 }
Please login to merge, or discard this patch.
Braces   +42 added lines, -16 removed lines patch added patch discarded remove patch
@@ -127,7 +127,8 @@  discard block
 block discarded – undo
127 127
 
128 128
         // open input stream
129 129
         $f_in = fopen($path, "r");
130
-        if (!$f_in) {
130
+        if (!$f_in)
131
+        {
131 132
             $this->success = false;
132 133
             return;
133 134
         }
@@ -149,17 +150,23 @@  discard block
 block discarded – undo
149 150
                               XML_OPTION_CASE_FOLDING, false);
150 151
 
151 152
         // parse input
152
-        while ($this->success && !feof($f_in)) {
153
+        while ($this->success && !feof($f_in))
154
+        {
153 155
             $line = fgets($f_in);
154
-            if ($store_request) $this->request .= $line;
155
-            if (is_string($line)) {
156
+            if ($store_request)
157
+            {
158
+            	$this->request .= $line;
159
+            }
160
+            if (is_string($line))
161
+            {
156 162
                 $had_input = true;
157 163
                 $this->success &= xml_parse($xml_parser, $line, false);
158 164
             }
159 165
         }
160 166
 
161 167
         // finish parsing
162
-        if ($had_input) {
168
+        if ($had_input)
169
+        {
163 170
             $this->success &= xml_parse($xml_parser, "", true);
164 171
         }
165 172
 
@@ -170,7 +177,11 @@  discard block
 block discarded – undo
170 177
         fclose($f_in);
171 178
 
172 179
         // if no input was parsed it was a request
173
-        if(!count($this->props)) $this->props = "all"; // default
180
+        if(!count($this->props))
181
+        {
182
+        	$this->props = "all";
183
+        }
184
+        // default
174 185
     }
175 186
 
176 187
 
@@ -185,21 +196,28 @@  discard block
 block discarded – undo
185 196
     function _startElement($parser, $name, $attrs)
186 197
     {
187 198
         // name space handling
188
-        if (strstr($name, " ")) {
199
+        if (strstr($name, " "))
200
+        {
189 201
             list($ns, $tag) = explode(" ", $name);
190 202
             if ($ns == "")
191
-                $this->success = false;
192
-        } else {
203
+            {
204
+                            $this->success = false;
205
+            }
206
+        }
207
+        else
208
+        {
193 209
             $ns  = "";
194 210
             $tag = $name;
195 211
         }
196 212
 
197 213
         // record root tag
198
-        if ($this->depth == 0) {
214
+        if ($this->depth == 0)
215
+        {
199 216
         	$this->root = array('name' => $tag, 'xmlns' => $ns, 'attrs' => $attrs);
200 217
         }
201 218
         // special tags at level 1: <allprop> and <propname>
202
-        if ($this->depth == 1) {
219
+        if ($this->depth == 1)
220
+        {
203 221
          	$this->use = 'props';
204 222
             switch ($tag)
205 223
             {
@@ -225,11 +243,15 @@  discard block
 block discarded – undo
225 243
         // requested properties are found at level 2
226 244
         // CalDAV filters can be at deeper levels too and we need the attrs, same for other tags (eg. multiget href's)
227 245
         if ($this->depth == 2 || $this->use == 'filters' && $this->depth >= 2 || $this->use == 'other' ||
228
-        	$this->use == 'props' && $this->depth >= 2) {
246
+        	$this->use == 'props' && $this->depth >= 2)
247
+        {
229 248
             $prop = array("name" => $tag);
230 249
             if ($ns)
231
-                $prop["xmlns"] = $ns;
232
-            if ($this->use != 'props' || $this->depth > 2) {
250
+            {
251
+                            $prop["xmlns"] = $ns;
252
+            }
253
+            if ($this->use != 'props' || $this->depth > 2)
254
+            {
233 255
             	$prop['attrs'] = $attrs;
234 256
             	$prop['depth'] = $this->depth;
235 257
             }
@@ -243,7 +265,10 @@  discard block
 block discarded – undo
243 265
             {
244 266
 	         	// this can happen if we have allprop and prop in one propfind:
245 267
 	        	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
246
-	            if (!is_array($this->{$this->use}) && $this->{$this->use}) $this->{$this->use} = array($this->{$this->use});
268
+	            if (!is_array($this->{$this->use}) && $this->{$this->use})
269
+	            {
270
+	            	$this->{$this->use} = array($this->{$this->use});
271
+	            }
247 272
 	            $this->{$this->use}[] =& $prop;
248 273
 	            $this->last_prop =& $prop;
249 274
 	            unset($prop);
@@ -278,7 +303,8 @@  discard block
 block discarded – undo
278 303
      */
279 304
     function _charData($parser, $data)
280 305
     {
281
-        if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data))) {
306
+        if ($this->use != 'props' && ($n = count($this->{$this->use})) && ($data = trim($data)))
307
+        {
282 308
         	$this->{$this->use}[$n-1]['data'] = $data;
283 309
         }
284 310
     }
Please login to merge, or discard this patch.
api/src/Header/UserAgent.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 	{
77 77
 		// should be Ok for all HTML 4 compatible browsers
78 78
 		$parts = $all_parts = null;
79
-		if(!preg_match('/compatible; ([a-z]+)[\/ ]+([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$parts))
79
+		if (!preg_match('/compatible; ([a-z]+)[\/ ]+([0-9.]+)/i', $_SERVER['HTTP_USER_AGENT'], $parts))
80 80
 		{
81
-			preg_match_all('/([a-z]+)\/([0-9.]+)/i',$_SERVER['HTTP_USER_AGENT'],$all_parts,PREG_SET_ORDER);
81
+			preg_match_all('/([a-z]+)\/([0-9.]+)/i', $_SERVER['HTTP_USER_AGENT'], $all_parts, PREG_SET_ORDER);
82 82
 			$parts = array_pop($all_parts);
83
-			foreach($all_parts as $p)
83
+			foreach ($all_parts as $p)
84 84
 			{
85 85
 				if ($p[1] == 'Chrome' && $parts[1] != 'Edge')
86 86
 				{
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 				}
90 90
 			}
91 91
 		}
92
-		list(,self::$user_agent,self::$ua_version) = $parts;
92
+		list(,self::$user_agent, self::$ua_version) = $parts;
93 93
 		if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') self::$user_agent = 'opera';
94 94
 		// IE no longer reports MSIE, but "Trident/7.0; rv:11.0"
95
-		if (self::$user_agent=='trident')
95
+		if (self::$user_agent == 'trident')
96 96
 		{
97
-			self::$user_agent='msie';
97
+			self::$user_agent = 'msie';
98 98
 			$matches = null;
99 99
 			self::$ua_version = preg_match('|Trident/[0-9.]+; rv:([0-9.]+)|i', $_SERVER['HTTP_USER_AGENT'], $matches) ?
100 100
 				$matches[1] : 11.0;
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,10 @@
 block discarded – undo
90 90
 			}
91 91
 		}
92 92
 		list(,self::$user_agent,self::$ua_version) = $parts;
93
-		if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') self::$user_agent = 'opera';
93
+		if ((self::$user_agent = strtolower(self::$user_agent)) == 'version')
94
+		{
95
+			self::$user_agent = 'opera';
96
+		}
94 97
 		// IE no longer reports MSIE, but "Trident/7.0; rv:11.0"
95 98
 		if (self::$user_agent=='trident')
96 99
 		{
Please login to merge, or discard this patch.
api/src/Header/Content.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 * @param boolean $force_download =true send content-disposition attachment header
39 39
 	 * @param boolean $no_content_type =false do not send actual content-type and content-length header, just content-disposition
40 40
 	 */
41
-	public static function safe(&$content, $path, &$mime='', &$length=0, $nocache=true, $force_download=true, $no_content_type=false)
41
+	public static function safe(&$content, $path, &$mime = '', &$length = 0, $nocache = true, $force_download = true, $no_content_type = false)
42 42
 	{
43 43
 		// change old/aliased mime-types to new one, eg. image/pdf to application/pdf
44 44
 		$mime = Api\MimeMagic::fix_mime_type($mime);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 			if (UserAgent::type() == 'chrome' || UserAgent::type() == 'msie' && UserAgent::version() >= 8)
54 54
 			{
55 55
 				$mime = 'text/plain';
56
-				header('X-Content-Type-Options: nosniff');	// stop IE & Chrome from content-type sniffing
56
+				header('X-Content-Type-Options: nosniff'); // stop IE & Chrome from content-type sniffing
57 57
 			}
58 58
 			// for the rest we change mime-type to text/html and let code below handle it safely
59 59
 			// this stops Safari and Firefox from using it as src attribute in a script tag
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 				{
66 66
 					$data = fread($content, $length);
67 67
 					fclose($content);
68
-					$content =& $data;
68
+					$content = & $data;
69 69
 					unset($data);
70 70
 				}
71 71
 				$content = '<pre>'.$content;
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 			if (UserAgent::type() == 'chrome' && UserAgent::version() >= 24 ||
80 80
 				// mobile FF 24 on Android does NOT honor CSP!
81 81
 				UserAgent::type() == 'firefox' && !UserAgent::mobile() && UserAgent::version() >= 24 ||
82
-				UserAgent::type() == 'safari' && !UserAgent::mobile() && UserAgent::version() >= 536 ||	// OS X
82
+				UserAgent::type() == 'safari' && !UserAgent::mobile() && UserAgent::version() >= 536 || // OS X
83 83
 				UserAgent::type() == 'safari' && UserAgent::mobile() && UserAgent::version() >= 9537)	// iOS 7
84 84
 			{
85
-				$csp = "script-src 'none'";	// forbid to execute any javascript
85
+				$csp = "script-src 'none'"; // forbid to execute any javascript
86 86
 				header("Content-Security-Policy: $csp");
87
-				header("X-Webkit-CSP: $csp");	// Chrome: <= 24, Safari incl. iOS
87
+				header("X-Webkit-CSP: $csp"); // Chrome: <= 24, Safari incl. iOS
88 88
 				//header("X-Content-Security-Policy: $csp");	// FF <= 22
89 89
 				//error_log(__METHOD__."('$options[path]') ".UserAgent::type().'/'.UserAgent::version().(UserAgent::mobile()?'/mobile':'').": using Content-Security-Policy: $csp");
90 90
 			}
@@ -117,25 +117,25 @@  discard block
 block discarded – undo
117 117
 	 * @param boolean $nocache =true send headers to disallow browser/proxies to cache the download
118 118
 	 * @param boolean $forceDownload =true send headers to handle as attachment/download
119 119
 	 */
120
-	public static function type($fn,$mime='',$length=0,$nocache=True,$forceDownload=true)
120
+	public static function type($fn, $mime = '', $length = 0, $nocache = True, $forceDownload = true)
121 121
 	{
122 122
 		// if no mime-type is given or it's the default binary-type, guess it from the extension
123
-		if(empty($mime) || $mime == 'application/octet-stream')
123
+		if (empty($mime) || $mime == 'application/octet-stream')
124 124
 		{
125 125
 			$mime = Api\MimeMagic::filename2mime($fn);
126 126
 		}
127
-		if($fn)
127
+		if ($fn)
128 128
 		{
129 129
 			// Show this for all
130
-			self::disposition($fn,$forceDownload);
130
+			self::disposition($fn, $forceDownload);
131 131
 			header('Content-type: '.$mime);
132 132
 
133
-			if($length)
133
+			if ($length)
134 134
 			{
135 135
 				header('Content-length: '.$length);
136 136
 			}
137 137
 
138
-			if($nocache)
138
+			if ($nocache)
139 139
 			{
140 140
 				header('Pragma: no-cache');
141 141
 				header('Pragma: public');
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @param string $fn filename
152 152
 	 * @param boolean $forceDownload =true send headers to handle as attachment/download
153 153
 	 */
154
-	public static function disposition($fn, $forceDownload=true)
154
+	public static function disposition($fn, $forceDownload = true)
155 155
 	{
156 156
 		if ($forceDownload)
157 157
 		{
Please login to merge, or discard this patch.
Braces   +10 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,9 +80,13 @@  discard block
 block discarded – undo
80 80
 				// mobile FF 24 on Android does NOT honor CSP!
81 81
 				UserAgent::type() == 'firefox' && !UserAgent::mobile() && UserAgent::version() >= 24 ||
82 82
 				UserAgent::type() == 'safari' && !UserAgent::mobile() && UserAgent::version() >= 536 ||	// OS X
83
-				UserAgent::type() == 'safari' && UserAgent::mobile() && UserAgent::version() >= 9537)	// iOS 7
83
+				UserAgent::type() == 'safari' && UserAgent::mobile() && UserAgent::version() >= 9537)
84 84
 			{
85
-				$csp = "script-src 'none'";	// forbid to execute any javascript
85
+				// iOS 7
86
+			{
87
+				$csp = "script-src 'none'";
88
+			}
89
+			// forbid to execute any javascript
86 90
 				header("Content-Security-Policy: $csp");
87 91
 				header("X-Webkit-CSP: $csp");	// Chrome: <= 24, Safari incl. iOS
88 92
 				//header("X-Content-Security-Policy: $csp");	// FF <= 22
@@ -96,7 +100,10 @@  discard block
 block discarded – undo
96 100
 		}
97 101
 		if ($no_content_type)
98 102
 		{
99
-			if ($force_download) self::disposition(Api\Vfs::basename($path), $force_download);
103
+			if ($force_download)
104
+			{
105
+				self::disposition(Api\Vfs::basename($path), $force_download);
106
+			}
100 107
 		}
101 108
 		else
102 109
 		{
Please login to merge, or discard this patch.