Passed
Push — 16.1 ( acd54f...6c102b )
by Hadi
17:33
created
mail/inc/class.mail_compose.inc.php 1 patch
Spacing   +604 added lines, -605 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class mail_compose
26 26
 {
27
-	var $public_functions = array
28
-	(
27
+	var $public_functions = array(
29 28
 		'compose'		=> True,
30 29
 		'getAttachment'		=> True,
31 30
 	);
@@ -34,8 +33,8 @@  discard block
 block discarded – undo
34 33
 	 * class vars for destination, priorities, mimeTypes
35 34
 	 */
36 35
 	static $destinations = array(
37
-		'to' 		=> 'to',  // lang('to')
38
-		'cc'		=> 'cc',  // lang('cc')
36
+		'to' 		=> 'to', // lang('to')
37
+		'cc'		=> 'cc', // lang('cc')
39 38
 		'bcc'		=> 'bcc', // lang('bcc')
40 39
 		'replyto'	=> 'replyto', // lang('replyto')
41 40
 		'folder'	=> 'folder'  // lang('folder')
@@ -63,20 +62,20 @@  discard block
 block discarded – undo
63 62
 	 * @var array
64 63
 	 */
65 64
 	var $mailPreferences;
66
-	var $attachments;	// Array of attachments
65
+	var $attachments; // Array of attachments
67 66
 	var $displayCharset;
68 67
 	var $composeID;
69 68
 	var $sessionData;
70 69
 
71 70
 	function __construct()
72 71
 	{
73
-		$this->displayCharset   = Api\Translation::charset();
72
+		$this->displayCharset = Api\Translation::charset();
74 73
 
75 74
 		$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
76
-		$this->mail_bo	= Mail::getInstance(true,$profileID);
75
+		$this->mail_bo = Mail::getInstance(true, $profileID);
77 76
 		$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->mail_bo->profileID;
78 77
 
79
-		$this->mailPreferences	=& $this->mail_bo->mailPreferences;
78
+		$this->mailPreferences = & $this->mail_bo->mailPreferences;
80 79
 		//force the default for the forwarding -> asmail
81 80
 		if (!is_array($this->mailPreferences) || empty($this->mailPreferences['message_forwarding']))
82 81
 		{
@@ -84,7 +83,7 @@  discard block
 block discarded – undo
84 83
 		}
85 84
 		if (is_null(Mail::$mailConfig)) Mail::$mailConfig = Api\Config::read('mail');
86 85
 
87
-		$this->mailPreferences  =& $this->mail_bo->mailPreferences;
86
+		$this->mailPreferences = & $this->mail_bo->mailPreferences;
88 87
 	}
89 88
 
90 89
 	/**
@@ -94,15 +93,15 @@  discard block
 block discarded – undo
94 93
 	 */
95 94
 	function changeProfile($_icServerID)
96 95
 	{
97
-		if ($this->mail_bo->profileID!=$_icServerID)
96
+		if ($this->mail_bo->profileID != $_icServerID)
98 97
 		{
99 98
 			if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.$this->mail_bo->profileID.'<->'.$_icServerID);
100
-			$this->mail_bo = Mail::getInstance(false,$_icServerID);
99
+			$this->mail_bo = Mail::getInstance(false, $_icServerID);
101 100
 			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$this->mail_bo->profileID.':'.function_backtrace());
102 101
 			// no icServer Object: something failed big time
103 102
 			if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
104 103
 			$this->mail_bo->openConnection($this->mail_bo->profileID);
105
-			$this->mailPreferences  =& $this->mail_bo->mailPreferences;
104
+			$this->mailPreferences = & $this->mail_bo->mailPreferences;
106 105
 		}
107 106
 	}
108 107
 
@@ -180,7 +179,7 @@  discard block
 block discarded – undo
180 179
 				'checkbox' => true,
181 180
 				'hint' => 'check to save as trackerentry on send',
182 181
 				'onExecute' => 'javaScript:app.mail.compose_setToggle',
183
-				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'),
182
+				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'), 'tracker'),
184 183
 			),
185 184
 			'to_calendar' => array(
186 185
 				'caption' => 'Calendar',
@@ -205,7 +204,7 @@  discard block
 block discarded – undo
205 204
 				'children' => array(),
206 205
 				'hint' => 'Select the message priority tag',
207 206
 			),
208
-			'save2vfs' => array (
207
+			'save2vfs' => array(
209 208
 				'caption' => 'Save to filemanager',
210 209
 				'icon' => 'filesave',
211 210
 				'group' => ++$group,
@@ -242,7 +241,7 @@  discard block
 block discarded – undo
242 241
 		{
243 242
 			foreach (array_keys($actions) as $key)
244 243
 			{
245
-				if (!in_array($key, array('send','button[saveAsDraft]','uploadForCompose' ))) {
244
+				if (!in_array($key, array('send', 'button[saveAsDraft]', 'uploadForCompose'))) {
246 245
 					$actions[$key]['toolbarDefault'] = false;
247 246
 				}
248 247
 			}
@@ -266,7 +265,7 @@  discard block
 block discarded – undo
266 265
 	 * @var boolean $suppressSigOnTop =false
267 266
 	 * @var boolean $isReply =false
268 267
 	 */
269
-	function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false)
268
+	function compose(array $_content = null, $msg = null, $_focusElement = 'to', $suppressSigOnTop = false, $isReply = false)
270 269
 	{
271 270
 		if ($msg) Framework::message($msg);
272 271
 
@@ -287,14 +286,14 @@  discard block
 block discarded – undo
287 286
 		//lang('compose'),lang('from') // needed to be found by translationtools
288 287
 		//error_log(__METHOD__.__LINE__.array2string($_REQUEST).function_backtrace());
289 288
 		//error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace());
290
-		$_contentHasSigID = $_content?array_key_exists('mailidentity',(array)$_content):false;
291
-		$_contentHasMimeType = $_content? array_key_exists('mimeType',(array)$_content):false;
289
+		$_contentHasSigID = $_content ?array_key_exists('mailidentity', (array)$_content) : false;
290
+		$_contentHasMimeType = $_content ? array_key_exists('mimeType', (array)$_content) : false;
292 291
 		if (isset($_GET['reply_id'])) $replyID = $_GET['reply_id'];
293 292
 		if (!$replyID && isset($_GET['id'])) $replyID = $_GET['id'];
294 293
 
295 294
 		// Process different places we can use as a start for composing an email
296 295
 		$actionToProcess = 'compose';
297
-		if($_GET['from'] && $replyID)
296
+		if ($_GET['from'] && $replyID)
298 297
 		{
299 298
 			$_content = array_merge((array)$_content, $this->getComposeFrom(
300 299
 				// Parameters needed for fetching appropriate data
@@ -312,10 +311,10 @@  discard block
 block discarded – undo
312 311
 		}
313 312
 
314 313
 		$composeCache = array();
315
-		if (isset($_content['composeID'])&&!empty($_content['composeID']))
314
+		if (isset($_content['composeID']) && !empty($_content['composeID']))
316 315
 		{
317 316
 			$isFirstLoad = false;
318
-			$composeCache = Api\Cache::getCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$_content['composeID'],$callback=null,$callback_params=array(),$expiration=60*60*2);
317
+			$composeCache = Api\Cache::getCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$_content['composeID'], $callback = null, $callback_params = array(), $expiration = 60 * 60 * 2);
319 318
 			$this->composeID = $_content['composeID'];
320 319
 			//error_log(__METHOD__.__LINE__.array2string($composeCache));
321 320
 		}
@@ -325,7 +324,7 @@  discard block
 block discarded – undo
325 324
 			// respect that composeasnew may not want that, as we assume there
326 325
 			// is some style already set and our initalStyle always adds a span with &nbsp;
327 326
 			// and we want to avoid that
328
-			$isFirstLoad = !($actionToProcess=='composeasnew');//true;
327
+			$isFirstLoad = !($actionToProcess == 'composeasnew'); //true;
329 328
 			$this->composeID = $_content['composeID'] = $this->generateComposeID();
330 329
 			if (!is_array($_content))
331 330
 			{
@@ -360,7 +359,7 @@  discard block
 block discarded – undo
360 359
 				if (!isset($upload['file'])) $upload['file'] = $upload['tmp_name'];
361 360
 				try
362 361
 				{
363
-					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload,$this->composeID,false);
362
+					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload, $this->composeID, false);
364 363
 				}
365 364
 				catch (Api\Exception\WrongUserinput $e)
366 365
 				{
@@ -386,12 +385,12 @@  discard block
 block discarded – undo
386 385
 			unset($_content['attachments']['delete']);
387 386
 			$attachments = $_content['attachments'];
388 387
 			unset($_content['attachments']);
389
-			foreach($attachments as $i => $att)
388
+			foreach ($attachments as $i => $att)
390 389
 			{
391
-				$remove=false;
392
-				foreach(array_keys($toDelete) as $k)
390
+				$remove = false;
391
+				foreach (array_keys($toDelete) as $k)
393 392
 				{
394
-					if ($att['tmp_name']==$k) $remove=true;
393
+					if ($att['tmp_name'] == $k) $remove = true;
395 394
 				}
396 395
 				if (!$remove) $_content['attachments'][] = $att;
397 396
 			}
@@ -399,7 +398,7 @@  discard block
 block discarded – undo
399 398
 		// someone clicked something like send, or saveAsDraft
400 399
 		// make sure, we are connected to the correct server for sending and storing the send message
401 400
 		$activeProfile = $composeProfile = $this->mail_bo->profileID; // active profile may not be the profile uised in/for compose
402
-		$activeFolderCache = Api\Cache::getCache(Api\Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
401
+		$activeFolderCache = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 10);
403 402
 		if (!empty($activeFolderCache[$this->mail_bo->profileID]))
404 403
 		{
405 404
 			//error_log(__METHOD__.__LINE__.' CurrentFolder:'.$activeFolderCache[$this->mail_bo->profileID]);
@@ -407,7 +406,7 @@  discard block
 block discarded – undo
407 406
 		}
408 407
 		//error_log(__METHOD__.__LINE__.array2string($_content));
409 408
 		if (!empty($_content['serverID']) && $_content['serverID'] != $this->mail_bo->profileID &&
410
-			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft']||$_content['button']['saveAsDraftAndPrint'])
409
+			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft'] || $_content['button']['saveAsDraftAndPrint'])
411 410
 		)
412 411
 		{
413 412
 			$this->changeProfile($_content['serverID']);
@@ -421,19 +420,19 @@  discard block
 block discarded – undo
421 420
 		{
422 421
 			$buttonClicked = $suppressSigOnTop = true;
423 422
 			$sendOK = true;
424
-			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html'?'html':'plain').'text']);
423
+			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
425 424
 			/*
426 425
 			perform some simple checks, before trying to send on:
427 426
 			$_content['to'];$_content['cc'];$_content['bcc'];
428 427
 			trim($_content['subject']);
429 428
 			trim(strip_tags(str_replace('&nbsp;','',$_content['body'])));
430 429
 			*/
431
-			if (strlen(trim(strip_tags(str_replace('&nbsp;','',$_content['body']))))==0 && count($_content['attachments'])==0)
430
+			if (strlen(trim(strip_tags(str_replace('&nbsp;', '', $_content['body'])))) == 0 && count($_content['attachments']) == 0)
432 431
 			{
433 432
 				$sendOK = false;
434 433
 				$_content['msg'] = $message = lang("no message body supplied");
435 434
 			}
436
-			if ($sendOK && strlen(trim($_content['subject']))==0)
435
+			if ($sendOK && strlen(trim($_content['subject'])) == 0)
437 436
 			{
438 437
 				$sendOK = false;
439 438
 				$_content['msg'] = $message = lang("no subject supplied");
@@ -448,15 +447,15 @@  discard block
 block discarded – undo
448 447
 				try
449 448
 				{
450 449
 					$success = $this->send($_content);
451
-					if ($success==false)
450
+					if ($success == false)
452 451
 					{
453
-						$sendOK=false;
452
+						$sendOK = false;
454 453
 						$message = $this->errorInfo;
455 454
 					}
456 455
 					if (!empty($_content['mailidentity']) && $_content['mailidentity'] != $sigPref[$this->mail_bo->profileID])
457 456
 					{
458
-						$sigPref[$this->mail_bo->profileID]=$_content['mailidentity'];
459
-						$GLOBALS['egw']->preferences->add('mail','LastSignatureIDUsed',$sigPref,'user');
457
+						$sigPref[$this->mail_bo->profileID] = $_content['mailidentity'];
458
+						$GLOBALS['egw']->preferences->add('mail', 'LastSignatureIDUsed', $sigPref, 'user');
460 459
 						// save prefs
461 460
 						$GLOBALS['egw']->preferences->save_repository(true);
462 461
 					}
@@ -480,23 +479,23 @@  discard block
 block discarded – undo
480 479
 				if (isset($_content['mode']) && !empty($_content['mode']))
481 480
 				{
482 481
 					$mode = $_content['mode'];
483
-					if ($_content['mode']=='forward' && !empty($_content['processedmail_id']))
482
+					if ($_content['mode'] == 'forward' && !empty($_content['processedmail_id']))
484 483
 					{
485
-						$_content['processedmail_id'] = explode(',',$_content['processedmail_id']);
484
+						$_content['processedmail_id'] = explode(',', $_content['processedmail_id']);
486 485
 						foreach ($_content['processedmail_id'] as $k =>$rowid)
487 486
 						{
488 487
 							$fhA = mail_ui::splitRowID($rowid);
489 488
 							//$this->sessionData['uid'][] = $fhA['msgUID'];
490 489
 							//$this->sessionData['forwardedUID'][] = $fhA['msgUID'];
491
-							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp=false);
490
+							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp = false);
492 491
 							if (!empty($fhA['folder'])) $workingFolder = $fhA['folder'];
493 492
 						}
494 493
 					}
495
-					if ($_content['mode']=='reply' && !empty($_content['processedmail_id']))
494
+					if ($_content['mode'] == 'reply' && !empty($_content['processedmail_id']))
496 495
 					{
497 496
 						$rhA = mail_ui::splitRowID($_content['processedmail_id']);
498 497
 						//$this->sessionData['uid'] = $rhA['msgUID'];
499
-						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
498
+						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
500 499
 						$workingFolder = $rhA['folder'];
501 500
 					}
502 501
 				}
@@ -504,30 +503,30 @@  discard block
 block discarded – undo
504 503
 				if (empty($idsForRefresh) && !empty($_content['processedmail_id']))
505 504
 				{
506 505
 					$rhA = mail_ui::splitRowID($_content['processedmail_id']);
507
-					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
506
+					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
508 507
 				}
509 508
 				$response = Api\Json\Response::get();
510 509
 				if ($activeProfile != $composeProfile)
511 510
 				{
512 511
 					// we need a message only, when account ids (composeProfile vs. activeProfile) differ
513
-					$response->call('opener.egw_message',lang('Message send successfully.'));
512
+					$response->call('opener.egw_message', lang('Message send successfully.'));
514 513
 				}
515
-				elseif ($activeProfile == $composeProfile && ($workingFolder==$activeFolder && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder)))
514
+				elseif ($activeProfile == $composeProfile && ($workingFolder == $activeFolder && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder)))
516 515
 				{
517
-					if ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder))
516
+					if ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder))
518 517
 					{
519 518
 						// we may need a refresh when on sent folder or in drafts, as drafted messages will/should be deleted after succeeded send action
520
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail');
519
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail');
521 520
 					}
522 521
 					else
523 522
 					{
524 523
 						//error_log(__METHOD__.__LINE__.array2string($idsForRefresh));
525
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail',$idsForRefresh,'update');
524
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail', $idsForRefresh, 'update');
526 525
 					}
527 526
 				}
528 527
 				else
529 528
 				{
530
-					$response->call('opener.egw_message',lang('Message send successfully.'));
529
+					$response->call('opener.egw_message', lang('Message send successfully.'));
531 530
 				}
532 531
 				//egw_framework::refresh_opener(lang('Message send successfully.'),'mail');
533 532
 				Framework::window_close();
@@ -535,60 +534,60 @@  discard block
 block discarded – undo
535 534
 			if ($sendOK == false)
536 535
 			{
537 536
 				$response = Api\Json\Response::get();
538
-				Framework::message(lang('Message send failed: %1',$message),'error');// maybe error is more appropriate
537
+				Framework::message(lang('Message send failed: %1', $message), 'error'); // maybe error is more appropriate
539 538
 				$response->call('app.mail.clearIntevals');
540 539
 			}
541 540
 		}
542 541
 
543 542
 		if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile);
544 543
 		$insertSigOnTop = false;
545
-		$content = (is_array($_content)?$_content:array());
544
+		$content = (is_array($_content) ? $_content : array());
546 545
 		if ($_contentHasMimeType)
547 546
 		{
548 547
 			// mimeType is now a checkbox; convert it here to match expectations
549 548
 			// ToDo: match Code to meet checkbox value
550
-			if ($content['mimeType']==1)
549
+			if ($content['mimeType'] == 1)
551 550
 			{
552
-				$_content['mimeType'] = $content['mimeType']='html';
551
+				$_content['mimeType'] = $content['mimeType'] = 'html';
553 552
 			}
554 553
 			else
555 554
 			{
556
-				$_content['mimeType'] = $content['mimeType']='plain';
555
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
557 556
 			}
558 557
 
559 558
 		}
560 559
 		// user might have switched desired mimetype, so we should convert
561
-		if ($content['is_html'] && $content['mimeType']=='plain')
560
+		if ($content['is_html'] && $content['mimeType'] == 'plain')
562 561
 		{
563 562
 			//error_log(__METHOD__.__LINE__.$content['mail_htmltext']);
564 563
 			$suppressSigOnTop = true;
565
-			if (stripos($content['mail_htmltext'],'<pre>')!==false)
564
+			if (stripos($content['mail_htmltext'], '<pre>') !== false)
566 565
 			{
567 566
 				$contentArr = Api\Mail\Html::splithtmlByPRE($content['mail_htmltext']);
568 567
 				if (is_array($contentArr))
569 568
 				{
570 569
 					foreach ($contentArr as $k =>&$elem)
571 570
 					{
572
-						if (stripos($elem,'<pre>')!==false) $elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
571
+						if (stripos($elem, '<pre>') !== false) $elem = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $elem);
573 572
 					}
574
-					$content['mail_htmltext'] = implode('',$contentArr);
573
+					$content['mail_htmltext'] = implode('', $contentArr);
575 574
 				}
576 575
 			}
577 576
 			$content['mail_htmltext'] = $this->_getCleanHTML($content['mail_htmltext']);
578
-			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'],$charset=false,false,true);
577
+			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'], $charset = false, false, true);
579 578
 
580 579
 			$content['body'] = $content['mail_htmltext'];
581 580
 			unset($content['mail_htmltext']);
582 581
 			$content['is_html'] = false;
583 582
 			$content['is_plain'] = true;
584 583
 		}
585
-		if ($content['is_plain'] && $content['mimeType']=='html')
584
+		if ($content['is_plain'] && $content['mimeType'] == 'html')
586 585
 		{
587 586
 			// the possible font span should only be applied on first load or on switch plain->html
588 587
 			$isFirstLoad = "switchedplaintohtml";
589 588
 			//error_log(__METHOD__.__LINE__.$content['mail_plaintext']);
590 589
 			$suppressSigOnTop = true;
591
-			$content['mail_plaintext'] = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$content['mail_plaintext']);
590
+			$content['mail_plaintext'] = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $content['mail_plaintext']);
592 591
 			//$this->replaceEmailAdresses($content['mail_plaintext']);
593 592
 			$content['body'] = $content['mail_plaintext'];
594 593
 			unset($content['mail_plaintext']);
@@ -596,7 +595,7 @@  discard block
 block discarded – undo
596 595
 			$content['is_plain'] = false;
597 596
 		}
598 597
 
599
-		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text']);
598
+		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
600 599
 		unset($_content['body']);
601 600
 		unset($_content['mail_htmltext']);
602 601
 		unset($_content['mail_plaintext']);
@@ -608,7 +607,7 @@  discard block
 block discarded – undo
608 607
 
609 608
 		// form was submitted either by clicking a button or by changing one of the triggering selectboxes
610 609
 		// identity and signatureid; this might trigger that the signature in mail body may have to be altered
611
-		if ( !empty($content['body']) &&
610
+		if (!empty($content['body']) &&
612 611
 			(!empty($composeCache['mailaccount']) && !empty($_content['mailaccount']) && $_content['mailaccount'] != $composeCache['mailaccount']) ||
613 612
 			(!empty($composeCache['mailidentity']) && !empty($_content['mailidentity']) && $_content['mailidentity'] != $composeCache['mailidentity'])
614 613
 		)
@@ -619,7 +618,7 @@  discard block
 block discarded – undo
619 618
 			{
620 619
 				$acc = Mail\Account::read($_content['mailaccount']);
621 620
 				//error_log(__METHOD__.__LINE__.array2string($acc));
622
-				$Identities = Mail\Account::read_identity($acc['ident_id'],true);
621
+				$Identities = Mail\Account::read_identity($acc['ident_id'], true);
623 622
 				//error_log(__METHOD__.__LINE__.array2string($Identities));
624 623
 				if ($Identities['ident_id'])
625 624
 				{
@@ -632,41 +631,41 @@  discard block
 block discarded – undo
632 631
 				}
633 632
 			}
634 633
 			$_oldSig = $composeCache['mailidentity'];
635
-			$_signatureid = ($newSig?$newSig:$_content['mailidentity']);
634
+			$_signatureid = ($newSig ? $newSig : $_content['mailidentity']);
636 635
 
637 636
 			if ($_oldSig != $_signatureid)
638 637
 			{
639
-				if($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
638
+				if ($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
640 639
 				// prepare signatures, the selected sig may be used on top of the body
641 640
 				try
642 641
 				{
643
-					$oldSignature = Mail\Account::read_identity($_oldSig,true);
642
+					$oldSignature = Mail\Account::read_identity($_oldSig, true);
644 643
 					//error_log(__METHOD__.__LINE__.'Old:'.array2string($oldSignature).'#');
645 644
 					$oldSigText = $oldSignature['ident_signature'];
646 645
 				}
647 646
 				catch (Exception $e)
648 647
 				{
649
-					$oldSignature=array();
648
+					$oldSignature = array();
650 649
 					$oldSigText = null;
651 650
 				}
652 651
 				try
653 652
 				{
654
-					$signature = Mail\Account::read_identity($_signatureid,true);
653
+					$signature = Mail\Account::read_identity($_signatureid, true);
655 654
 					//error_log(__METHOD__.__LINE__.'New:'.array2string($signature).'#');
656 655
 					$sigText = $signature['ident_signature'];
657 656
 				}
658 657
 				catch (Exception $e)
659 658
 				{
660
-					$signature=array();
659
+					$signature = array();
661 660
 					$sigText = null;
662 661
 				}
663 662
 				//error_log(__METHOD__.'Old:'.$oldSigText.'#');
664 663
 				//error_log(__METHOD__.'New:'.$sigText.'#');
665 664
 				if ($_currentMode == 'plain')
666 665
 				{
667
-					$oldSigText = $this->convertHTMLToText($oldSigText,true,true);
668
-					$sigText = $this->convertHTMLToText($sigText,true,true);
669
-					if($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
666
+					$oldSigText = $this->convertHTMLToText($oldSigText, true, true);
667
+					$sigText = $this->convertHTMLToText($sigText, true, true);
668
+					if ($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
670 669
 				}
671 670
 
672 671
 				//$oldSigText = Mail::merge($oldSigText,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
@@ -680,9 +679,9 @@  discard block
 block discarded – undo
680 679
 				//error_log(__METHOD__.'Old(clean):'.$oldSigTextCleaned.'#');
681 680
 				if ($_currentMode == 'html')
682 681
 				{
683
-					$content['body'] = str_replace("\n",'\n',$content['body']);	// dont know why, but \n screws up preg_replace
682
+					$content['body'] = str_replace("\n", '\n', $content['body']); // dont know why, but \n screws up preg_replace
684 683
 					$styles = Mail::getStyles(array(array('body'=>$content['body'])));
685
-					if (stripos($content['body'],'style')!==false) Api\Mail\Html::replaceTagsCompletley($content['body'],'style',$endtag='',true); // clean out empty or pagewide style definitions / left over tags
684
+					if (stripos($content['body'], 'style') !== false) Api\Mail\Html::replaceTagsCompletley($content['body'], 'style', $endtag = '', true); // clean out empty or pagewide style definitions / left over tags
686 685
 				}
687 686
 				$content['body'] = str_replace(array("\r", "\t", "<br />\n", ": "), array("", "", "<br />", ":"),
688 687
 					$_currentMode == 'html' ? Api\Html::purify($content['body'], Mail::$htmLawed_config, array(), true) : $content['body']);
@@ -690,9 +689,9 @@  discard block
 block discarded – undo
690 689
 				if ($_currentMode == 'html')
691 690
 				{
692 691
 					$replaced = null;
693
-					$content['body'] = preg_replace($reg='|'.preg_quote('<!-- HTMLSIGBEGIN -->','|').'.*'.preg_quote('<!-- HTMLSIGEND -->','|').'|u',
694
-						$rep='<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in=$content['body'], -1, $replaced);
695
-					$content['body'] = str_replace(array('\n',"\xe2\x80\x93","\xe2\x80\x94","\xe2\x82\xac"),array("\n",'&ndash;','&mdash;','&euro;'),$content['body']);
692
+					$content['body'] = preg_replace($reg = '|'.preg_quote('<!-- HTMLSIGBEGIN -->', '|').'.*'.preg_quote('<!-- HTMLSIGEND -->', '|').'|u',
693
+						$rep = '<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in = $content['body'], -1, $replaced);
694
+					$content['body'] = str_replace(array('\n', "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x82\xac"), array("\n", '&ndash;', '&mdash;', '&euro;'), $content['body']);
696 695
 					//error_log(__METHOD__."() preg_replace('$reg', '$rep', '$in', -1)='".$content['body']."', replaced=$replaced");
697 696
 					unset($rep, $in);
698 697
 					if ($replaced)
@@ -703,32 +702,32 @@  discard block
 block discarded – undo
703 702
 					else
704 703
 					{
705 704
 						// try the old way
706
-						$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
705
+						$found = (strlen(trim($oldSigTextCleaned)) > 0 ?strpos($content['body'], trim($oldSigTextCleaned)) : false);
707 706
 					}
708 707
 				}
709 708
 				else
710 709
 				{
711
-					$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
710
+					$found = (strlen(trim($oldSigTextCleaned)) > 0 ?strpos($content['body'], trim($oldSigTextCleaned)) : false);
712 711
 				}
713 712
 
714
-				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
713
+				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
715 714
 				{
716 715
 					//error_log(__METHOD__.'Old Content:'.$content['body'].'#');
717
-					$_oldSigText = preg_quote($oldSigTextCleaned,'~');
716
+					$_oldSigText = preg_quote($oldSigTextCleaned, '~');
718 717
 					//error_log(__METHOD__.'Old(masked):'.$_oldSigText.'#');
719
-					$content['body'] = preg_replace('~'.$_oldSigText.'~mi',$sigText,$content['body'],1);
718
+					$content['body'] = preg_replace('~'.$_oldSigText.'~mi', $sigText, $content['body'], 1);
720 719
 					//error_log(__METHOD__.'new Content:'.$content['body'].'#');
721 720
 				}
722 721
 
723
-				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
722
+				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
724 723
 				{
725 724
 					// if there is no sig selected, there is no way to replace a signature
726 725
 				}
727 726
 
728 727
 				if ($found === false)
729 728
 				{
730
-					if($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
731
-					if($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
729
+					if ($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
730
+					if ($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
732 731
 				}
733 732
 				else
734 733
 				{
@@ -750,7 +749,7 @@  discard block
 block discarded – undo
750 749
 		if ($isFirstLoad)
751 750
 		{
752 751
 			$alwaysAttachVCardAtCompose = false; // we use this to eliminate double attachments, if users VCard is already present/attached
753
-			if ( isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
752
+			if (isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
754 753
 				$this->mailPreferences['attachVCardAtCompose']))
755 754
 			{
756 755
 				$alwaysAttachVCardAtCompose = true;
@@ -759,7 +758,7 @@  discard block
 block discarded – undo
759 758
 					$f = $_REQUEST['preset']['file'];
760 759
 					$_REQUEST['preset']['file'] = array($f);
761 760
 				}
762
-				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')."/.entry";
761
+				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')."/.entry";
763 762
 			}
764 763
 			// an app passed the request for fetching and mailing an entry
765 764
 			if (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id']))
@@ -768,33 +767,33 @@  discard block
 block discarded – undo
768 767
 				$mt = $_REQUEST['method'];
769 768
 				$id = $_REQUEST['id'];
770 769
 				// passed method MUST be registered
771
-				$method = Link::get_registry($app,$mt);
770
+				$method = Link::get_registry($app, $mt);
772 771
 				//error_log(__METHOD__.__LINE__.array2string($method));
773 772
 				if ($method)
774 773
 				{
775
-					$res = ExecMethod($method,array($id,'html'));
774
+					$res = ExecMethod($method, array($id, 'html'));
776 775
 					//error_log(__METHOD__.__LINE__.array2string($res));
777 776
 					if (!empty($res))
778 777
 					{
779 778
 						$insertSigOnTop = 'below';
780 779
 						if (isset($res['attachments']) && is_array($res['attachments']))
781 780
 						{
782
-							foreach($res['attachments'] as $f)
781
+							foreach ($res['attachments'] as $f)
783 782
 							{
784 783
 								$_REQUEST['preset']['file'][] = $f;
785 784
 							}
786 785
 						}
787 786
 						$content['subject'] = lang($app).' #'.$res['id'].': ';
788
-						foreach(array('subject','body','mimetype') as $name) {
787
+						foreach (array('subject', 'body', 'mimetype') as $name) {
789 788
 							$sName = $name;
790
-							if ($name=='mimetype'&&$res[$name])
789
+							if ($name == 'mimetype' && $res[$name])
791 790
 							{
792 791
 								$sName = 'mimeType';
793 792
 								$content[$sName] = $res[$name];
794 793
 							}
795 794
 							else
796 795
 							{
797
-								if ($res[$name]) $content[$sName] .= (strlen($content[$sName])>0 ? ' ':'') .$res[$name];
796
+								if ($res[$name]) $content[$sName] .= (strlen($content[$sName]) > 0 ? ' ' : '').$res[$name];
798 797
 							}
799 798
 						}
800 799
 					}
@@ -803,45 +802,45 @@  discard block
 block discarded – undo
803 802
 			// handle preset info/values
804 803
 			if (is_array($_REQUEST['preset']))
805 804
 			{
806
-				$alreadyProcessed=array();
805
+				$alreadyProcessed = array();
807 806
 				//_debug_array($_REQUEST);
808 807
 				if ($_REQUEST['preset']['mailto']) {
809 808
 					// handle mailto strings such as
810 809
 					// mailto:larry,dan?cc=mike&bcc=sue&subject=test&body=type+your&body=message+here
811 810
 					// the above string may be htmlentyty encoded, then multiple body tags are supported
812 811
 					// first, strip the mailto: string out of the mailto URL
813
-					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'],'mailto')===false?$_REQUEST['preset']['mailto']:trim(substr(html_entity_decode($_REQUEST['preset']['mailto']),7)));
812
+					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'], 'mailto') === false ? $_REQUEST['preset']['mailto'] : trim(substr(html_entity_decode($_REQUEST['preset']['mailto']), 7)));
814 813
 					// check if there is more than the to address
815
-					$mailtoArray = explode('?',$tmp_send_to,2);
814
+					$mailtoArray = explode('?', $tmp_send_to, 2);
816 815
 					if ($mailtoArray[1]) {
817 816
 						// check if there are more than one requests
818
-						$addRequests = explode('&',$mailtoArray[1]);
817
+						$addRequests = explode('&', $mailtoArray[1]);
819 818
 						foreach ($addRequests as $key => $reqval) {
820 819
 							// the additional requests should have a =, to separate key from value.
821
-							$keyValuePair = explode('=',$reqval,2);
822
-							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]])>0 ? ' ':'') . $keyValuePair[1];
820
+							$keyValuePair = explode('=', $reqval, 2);
821
+							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]]) > 0 ? ' ' : '').$keyValuePair[1];
823 822
 						}
824 823
 					}
825
-					$content['to']=$mailtoArray[0];
826
-					$alreadyProcessed['to']='to';
824
+					$content['to'] = $mailtoArray[0];
825
+					$alreadyProcessed['to'] = 'to';
827 826
 					// if the mailto string is not htmlentity decoded the arguments are passed as simple requests
828
-					foreach(array('cc','bcc','subject','body') as $name) {
829
-						$alreadyProcessed[$name]=$name;
830
-						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name])>0 ? ( $name == 'cc' || $name == 'bcc' ? ',' : ' ') : '') . $_REQUEST[$name];
827
+					foreach (array('cc', 'bcc', 'subject', 'body') as $name) {
828
+						$alreadyProcessed[$name] = $name;
829
+						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name]) > 0 ? ($name == 'cc' || $name == 'bcc' ? ',' : ' ') : '').$_REQUEST[$name];
831 830
 					}
832 831
 				}
833 832
 
834 833
 				if ($_REQUEST['preset']['mailtocontactbyid']) {
835 834
 					if ($GLOBALS['egw_info']['user']['apps']['addressbook']) {
836 835
 						$contacts_obj = new Api\Contacts();
837
-						$addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
838
-						if (method_exists($contacts_obj,'search')) {
836
+						$addressbookprefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook'];
837
+						if (method_exists($contacts_obj, 'search')) {
839 838
 
840
-							$addressArray = explode(',',$_REQUEST['preset']['mailtocontactbyid']);
839
+							$addressArray = explode(',', $_REQUEST['preset']['mailtocontactbyid']);
841 840
 							foreach ((array)$addressArray as $id => $addressID)
842 841
 							{
843
-								$addressID = (int) $addressID;
844
-								if (!($addressID>0))
842
+								$addressID = (int)$addressID;
843
+								if (!($addressID > 0))
845 844
 								{
846 845
 									unset($addressArray[$id]);
847 846
 								}
@@ -850,44 +849,44 @@  discard block
 block discarded – undo
850 849
 							{
851 850
 								$_searchCond = array('contact_id'=>$addressArray);
852 851
 								//error_log(__METHOD__.__LINE__.$_searchString);
853
-								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $showAccounts=false;
854
-								$filter = ($showAccounts?array():array('account_id' => null));
855
-								$filter['cols_to_search']=array('n_fn','email','email_home');
856
-								$contacts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter);
852
+								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $showAccounts = false;
853
+								$filter = ($showAccounts ? array() : array('account_id' => null));
854
+								$filter['cols_to_search'] = array('n_fn', 'email', 'email_home');
855
+								$contacts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
857 856
 								// additionally search the accounts, if the contact storage is not the account storage
858 857
 								if ($showAccounts &&
859 858
 									$GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
860 859
 									$GLOBALS['egw_info']['server']['contact_repository'] == 'sql')
861 860
 								{
862
-									$accounts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),array('owner' => 0));
861
+									$accounts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), array('owner' => 0));
863 862
 
864 863
 									if ($contacts && $accounts)
865 864
 									{
866
-										$contacts = array_merge($contacts,$accounts);
867
-										usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);'));
865
+										$contacts = array_merge($contacts, $accounts);
866
+										usort($contacts, create_function('$a,$b', 'return strcasecmp($a["n_fn"],$b["n_fn"]);'));
868 867
 									}
869
-									elseif($accounts)
868
+									elseif ($accounts)
870 869
 									{
871
-										$contacts =& $accounts;
870
+										$contacts = & $accounts;
872 871
 									}
873 872
 									unset($accounts);
874 873
 								}
875 874
 							}
876
-							if(is_array($contacts)) {
875
+							if (is_array($contacts)) {
877 876
 								$mailtoArray = array();
878 877
 								$primary = $addressbookprefs['distributionListPreferredMail'];
879 878
 								if ($primary != 'email' && $primary != 'email_home') $primary = 'email';
880
-								$secondary = ($primary == 'email'?'email_home':'email');
879
+								$secondary = ($primary == 'email' ? 'email_home' : 'email');
881 880
 								//error_log(__METHOD__.__LINE__.array2string($contacts));
882
-								foreach($contacts as $contact) {
883
-									$innerCounter=0;
884
-									foreach(array($contact[$primary],$contact[$secondary]) as $email) {
881
+								foreach ($contacts as $contact) {
882
+									$innerCounter = 0;
883
+									foreach (array($contact[$primary], $contact[$secondary]) as $email) {
885 884
 										// use pref distributionListPreferredMail for the primary address
886 885
 										// avoid wrong addresses, if an rfc822 encoded address is in addressbook
887
-										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
888
-										$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
889
-										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>');
890
-										if($innerCounter==0 && !empty($email) && in_array($completeMailString ,$mailtoArray) === false) {
886
+										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/", '$2', $email);
887
+										$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
888
+										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']).' <'.trim($email).'>');
889
+										if ($innerCounter == 0 && !empty($email) && in_array($completeMailString, $mailtoArray) === false) {
891 890
 											$i++;
892 891
 											$innerCounter++;
893 892
 											$mailtoArray[$i] = $completeMailString;
@@ -896,8 +895,8 @@  discard block
 block discarded – undo
896 895
 								}
897 896
 							}
898 897
 							//error_log(__METHOD__.__LINE__.array2string($mailtoArray));
899
-							$alreadyProcessed['to']='to';
900
-							$content['to']=$mailtoArray;
898
+							$alreadyProcessed['to'] = 'to';
899
+							$content['to'] = $mailtoArray;
901 900
 						}
902 901
 					}
903 902
 				}
@@ -912,20 +911,20 @@  discard block
 block discarded – undo
912 911
 					$types = (array)$_REQUEST['preset']['type'];
913 912
 					//if (!empty($types) && in_array('text/calendar; method=request',$types))
914 913
 					$files = (array)$_REQUEST['preset']['file'];
915
-					foreach($files as $k => $path)
914
+					foreach ($files as $k => $path)
916 915
 					{
917
-						if (!empty($types[$k]) && stripos($types[$k],'text/calendar')!==false)
916
+						if (!empty($types[$k]) && stripos($types[$k], 'text/calendar') !== false)
918 917
 						{
919 918
 							$insertSigOnTop = 'below';
920 919
 						}
921 920
 						//error_log(__METHOD__.__LINE__.$path.'->'.array2string(parse_url($path,PHP_URL_SCHEME == 'vfs')));
922
-						if (parse_url($path,PHP_URL_SCHEME == 'vfs'))
921
+						if (parse_url($path, PHP_URL_SCHEME == 'vfs'))
923 922
 						{
924 923
 							//Vfs::load_wrapper('vfs');
925 924
 							$type = Vfs::mime_content_type($path);
926 925
 							// special handling for attaching vCard of iCal --> use their link-title as name
927
-							if (substr($path,-7) != '/.entry' ||
928
-								!(list($app,$id) = array_slice(explode('/',$path),-3)) ||
926
+							if (substr($path, -7) != '/.entry' ||
927
+								!(list($app, $id) = array_slice(explode('/', $path), -3)) ||
929 928
 								!($name = Link::title($app, $id)))
930 929
 							{
931 930
 								$name = Vfs::decodePath(Vfs::basename($path));
@@ -939,7 +938,7 @@  discard block
 block discarded – undo
939 938
 							{
940 939
 								$type = $types[$k];
941 940
 							}
942
-							$path = str_replace('+','%2B',$path);
941
+							$path = str_replace('+', '%2B', $path);
943 942
 							$formData = array(
944 943
 								'name' => $name,
945 944
 								'type' => $type,
@@ -952,7 +951,7 @@  discard block
 block discarded – undo
952 951
 								Framework::message(lang('Directories have to be shared.'), 'info');
953 952
 							}
954 953
 						}
955
-						elseif(is_readable($path))
954
+						elseif (is_readable($path))
956 955
 						{
957 956
 							$formData = array(
958 957
 								'name' => isset($names[$k]) ? $names[$k] : basename($path),
@@ -965,28 +964,28 @@  discard block
 block discarded – undo
965 964
 						{
966 965
 							continue;
967 966
 						}
968
-						$this->addAttachment($formData,$content,($alwaysAttachVCardAtCompose?true:false));
967
+						$this->addAttachment($formData, $content, ($alwaysAttachVCardAtCompose ?true:false));
969 968
 					}
970 969
 					$remember = array();
971 970
 					if (isset($_REQUEST['preset']['mailto']) || (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id'])))
972 971
 					{
973
-						foreach(array_keys($content) as $k)
972
+						foreach (array_keys($content) as $k)
974 973
 						{
975
-							if (in_array($k,array('to','cc','bcc','subject','body','mimeType'))&&isset($this->sessionData[$k]))
974
+							if (in_array($k, array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType')) && isset($this->sessionData[$k]))
976 975
 							{
977
-								$alreadyProcessed[$k]=$k;
976
+								$alreadyProcessed[$k] = $k;
978 977
 								$remember[$k] = $this->sessionData[$k];
979 978
 							}
980 979
 						}
981 980
 					}
982
-					if(!empty($remember)) $content = array_merge($content,$remember);
981
+					if (!empty($remember)) $content = array_merge($content, $remember);
983 982
 				}
984
-				foreach(array('to','cc','bcc','subject','body','mimeType') as $name)
983
+				foreach (array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType') as $name)
985 984
 				{
986 985
 					//always handle mimeType
987
-					if ($name=='mimeType' && $_REQUEST['preset'][$name])
986
+					if ($name == 'mimeType' && $_REQUEST['preset'][$name])
988 987
 					{
989
-						$_content[$name]=$content[$name]=$_REQUEST['preset'][$name];
988
+						$_content[$name] = $content[$name] = $_REQUEST['preset'][$name];
990 989
 					}
991 990
 					//skip if already processed by "preset Routines"
992 991
 					if ($alreadyProcessed[$name]) continue;
@@ -999,36 +998,36 @@  discard block
 block discarded – undo
999 998
 			{
1000 999
 				$content['to'] = base64_decode($_REQUEST['send_to']);
1001 1000
 				// first check if there is a questionmark or ampersand
1002
-				if (strpos($content['to'],'?')!== false) list($content['to'],$rest) = explode('?',$content['to'],2);
1001
+				if (strpos($content['to'], '?') !== false) list($content['to'], $rest) = explode('?', $content['to'], 2);
1003 1002
 				$content['to'] = html_entity_decode($content['to']);
1004
-				if (($at_pos = strpos($content['to'],'@')) !== false)
1003
+				if (($at_pos = strpos($content['to'], '@')) !== false)
1005 1004
 				{
1006
-					if (($amp_pos = strpos(substr($content['to'],$at_pos),'&')) !== false)
1005
+					if (($amp_pos = strpos(substr($content['to'], $at_pos), '&')) !== false)
1007 1006
 					{
1008 1007
 						//list($email,$addoptions) = explode('&',$value,2);
1009
-						$email = substr($content['to'],0,$amp_pos+$at_pos);
1010
-						$rest = substr($content['to'], $amp_pos+$at_pos+1);
1008
+						$email = substr($content['to'], 0, $amp_pos + $at_pos);
1009
+						$rest = substr($content['to'], $amp_pos + $at_pos + 1);
1011 1010
 						//error_log(__METHOD__.__LINE__.$email.' '.$rest);
1012 1011
 						$content['to'] = $email;
1013 1012
 					}
1014 1013
 				}
1015
-				if (strpos($content['to'],'%40')!== false) $content['to'] = Api\Html::purify(str_replace('%40','@',$content['to']));
1014
+				if (strpos($content['to'], '%40') !== false) $content['to'] = Api\Html::purify(str_replace('%40', '@', $content['to']));
1016 1015
 				$rarr = array(Api\Html::purify($rest));
1017
-				if (isset($rest)&&!empty($rest) && strpos($rest,'&')!== false) $rarr = explode('&',$rest);
1016
+				if (isset($rest) && !empty($rest) && strpos($rest, '&') !== false) $rarr = explode('&', $rest);
1018 1017
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($rarr));
1019 1018
 				$karr = array();
1020 1019
 				foreach ($rarr as &$rval)
1021 1020
 				{
1022 1021
 					//must contain =
1023
-					if (strpos($rval,'=')!== false)
1022
+					if (strpos($rval, '=') !== false)
1024 1023
 					{
1025
-						list($k,$v) = explode('=',$rval,2);
1024
+						list($k, $v) = explode('=', $rval, 2);
1026 1025
 						$karr[$k] = (string)$v;
1027
-						unset($k,$v);
1026
+						unset($k, $v);
1028 1027
 					}
1029 1028
 				}
1030 1029
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($karr));
1031
-				foreach(array('cc','bcc','subject','body') as $name)
1030
+				foreach (array('cc', 'bcc', 'subject', 'body') as $name)
1032 1031
 				{
1033 1032
 					if ($karr[$name]) $content[$name] = $karr[$name];
1034 1033
 				}
@@ -1040,17 +1039,17 @@  discard block
 block discarded – undo
1040 1039
 		if ($isFirstLoad && !empty($_REQUEST['mimeType']))
1041 1040
 		{
1042 1041
 			$_content['mimeType'] = $content['mimeType'];
1043
-			if (($_REQUEST['mimeType']=="text" ||$_REQUEST['mimeType']=="plain") && $content['mimeType'] == 'html')
1042
+			if (($_REQUEST['mimeType'] == "text" || $_REQUEST['mimeType'] == "plain") && $content['mimeType'] == 'html')
1044 1043
 			{
1045
-				$_content['mimeType'] = $content['mimeType']  = 'plain';
1046
-				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1044
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
1045
+				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1047 1046
 			}
1048
-			if ($_REQUEST['mimeType']=="html" && $content['mimeType'] != 'html')
1047
+			if ($_REQUEST['mimeType'] == "html" && $content['mimeType'] != 'html')
1049 1048
 			{
1050
-				$_content['mimeType'] = $content['mimeType']  = 'html';
1049
+				$_content['mimeType'] = $content['mimeType'] = 'html';
1051 1050
 				$content['body'] = "<pre>".$content['body']."</pre>";
1052 1051
 				// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1053
-				if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1052
+				if (strpos($content['body'], "<pre> \r\n \r\n---") === 0) $content['body'] = substr_replace($content['body'], " <br>\r\n<pre>---", 0, strlen("<pre> \r\n \r\n---") - 1);
1054 1053
 			}
1055 1054
 		}
1056 1055
 		else
@@ -1058,24 +1057,24 @@  discard block
 block discarded – undo
1058 1057
 			// try to enforce a mimeType on reply ( if type is not of the wanted type )
1059 1058
 			if ($isReply)
1060 1059
 			{
1061
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="text" &&
1060
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "text" &&
1062 1061
 					$content['mimeType'] == 'html')
1063 1062
 				{
1064
-					$_content['mimeType'] = $content['mimeType']  = 'plain';
1065
-					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1063
+					$_content['mimeType'] = $content['mimeType'] = 'plain';
1064
+					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1066 1065
 				}
1067
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="html" &&
1066
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "html" &&
1068 1067
 					$content['mimeType'] != 'html')
1069 1068
 				{
1070
-					$_content['mimeType'] = $content['mimeType']  = 'html';
1069
+					$_content['mimeType'] = $content['mimeType'] = 'html';
1071 1070
 					$content['body'] = "<pre>".$content['body']."</pre>";
1072 1071
 					// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1073
-					if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1072
+					if (strpos($content['body'], "<pre> \r\n \r\n---") === 0) $content['body'] = substr_replace($content['body'], " <br>\r\n<pre>---", 0, strlen("<pre> \r\n \r\n---") - 1);
1074 1073
 				}
1075 1074
 			}
1076 1075
 		}
1077 1076
 
1078
-		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible()===false)
1077
+		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible() === false)
1079 1078
 		{
1080 1079
 			$_content['mimeType'] = $content['mimeType'] = 'plain';
1081 1080
 			$content['body'] = $this->convertHTMLToText($content['body']);
@@ -1094,36 +1093,36 @@  discard block
 block discarded – undo
1094 1093
 		//_debug_array(($presetSig ? $presetSig : $content['mailidentity']));
1095 1094
 		try
1096 1095
 		{
1097
-			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig,true);
1096
+			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig, true);
1098 1097
 		}
1099 1098
 		catch (Exception $e)
1100 1099
 		{
1101 1100
 			//PROBABLY NOT FOUND
1102
-			$signature=array();
1101
+			$signature = array();
1103 1102
 		}
1104 1103
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
1105 1104
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
1106
-			empty($signature['ident_signature']) || trim($this->convertHTMLToText($signature['ident_signature'],true,true)) =='')
1105
+			empty($signature['ident_signature']) || trim($this->convertHTMLToText($signature['ident_signature'], true, true)) == '')
1107 1106
 		{
1108 1107
 			$disableRuler = true;
1109 1108
 		}
1110 1109
 		$font_span = $font_part = '';
1111
-		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1110
+		if ($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1112 1111
 			// User preferences for style
1113 1112
 			$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
1114 1113
 			$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
1115
-			$font_part = '<span style="width:100%; display: inline; '.($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'">';
1114
+			$font_part = '<span style="width:100%; display: inline; '.($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').'">';
1116 1115
 			$font_span = $font_part.'&#8203;</span>';
1117 1116
 			if (empty($font) && empty($font_size)) $font_span = '';
1118 1117
 		}
1119 1118
 		// the font span should only be applied on first load or on switch plain->html and the absence of the font_part of the span
1120
-		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false) $font_span = '';
1119
+		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'], $font_part) === false) $font_span = '';
1121 1120
 		//remove possible html header stuff
1122
-		if (stripos($content['body'],'<html><head></head><body>')!==false) $content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1121
+		if (stripos($content['body'], '<html><head></head><body>') !== false) $content['body'] = str_ireplace(array('<html><head></head><body>', '</body></html>'), array('', ''), $content['body']);
1123 1122
 		//error_log(__METHOD__.__LINE__.array2string($this->mailPreferences));
1124
-		$blockElements = array('address','blockquote','center','del','dir','div','dl','fieldset','form','h1','h2','h3','h4','h5','h6','hr','ins','isindex','menu','noframes','noscript','ol','p','pre','table','ul');
1125
-		if ($this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend' &&
1126
-			!(isset($_POST['mySigID']) && !empty($_POST['mySigID']) ) && !$suppressSigOnTop
1123
+		$blockElements = array('address', 'blockquote', 'center', 'del', 'dir', 'div', 'dl', 'fieldset', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ins', 'isindex', 'menu', 'noframes', 'noscript', 'ol', 'p', 'pre', 'table', 'ul');
1124
+		if ($this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' &&
1125
+			!(isset($_POST['mySigID']) && !empty($_POST['mySigID'])) && !$suppressSigOnTop
1127 1126
 		)
1128 1127
 		{
1129 1128
 			// ON tOP OR BELOW? pREF CAN TELL
@@ -1133,57 +1132,57 @@  discard block
 block discarded – undo
1133 1132
 						'1' => 'before reply, visible during compose',
1134 1133
 						'no_belowaftersend'  => 'appended after reply before sending',
1135 1134
 			*/
1136
-			$insertSigOnTop = ($insertSigOnTop?$insertSigOnTop:($this->mailPreferences['insertSignatureAtTopOfMessage']?$this->mailPreferences['insertSignatureAtTopOfMessage']:'below'));
1137
-			$sigText = Mail::merge($signature['ident_signature'],array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
1135
+			$insertSigOnTop = ($insertSigOnTop ? $insertSigOnTop : ($this->mailPreferences['insertSignatureAtTopOfMessage'] ? $this->mailPreferences['insertSignatureAtTopOfMessage'] : 'below'));
1136
+			$sigText = Mail::merge($signature['ident_signature'], array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
1138 1137
 			if ($content['mimeType'] == 'html')
1139 1138
 			{
1140
-				$sigTextStartsWithBlockElement = ($disableRuler?false:true);
1141
-				foreach($blockElements as $e)
1139
+				$sigTextStartsWithBlockElement = ($disableRuler ?false:true);
1140
+				foreach ($blockElements as $e)
1142 1141
 				{
1143 1142
 					if ($sigTextStartsWithBlockElement) break;
1144
-					if (stripos(trim($sigText),'<'.$e)===0) $sigTextStartsWithBlockElement = true;
1143
+					if (stripos(trim($sigText), '<'.$e) === 0) $sigTextStartsWithBlockElement = true;
1145 1144
 				}
1146 1145
 			}
1147
-			if($content['mimeType'] == 'html') {
1146
+			if ($content['mimeType'] == 'html') {
1148 1147
 				$before = $disableRuler ? '' : '<hr style="border:1px dotted silver; width:100%;">';
1149 1148
 				$inbetween = '';
1150 1149
 			} else {
1151
-				$before = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
1150
+				$before = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
1152 1151
 				$inbetween = "\r\n";
1153 1152
 			}
1154 1153
 			if ($content['mimeType'] == 'html')
1155 1154
 			{
1156
-				$sigText = ($sigTextStartsWithBlockElement?'':"<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement?'':"</div>");
1155
+				$sigText = ($sigTextStartsWithBlockElement ? '' : "<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement ? '' : "</div>");
1157 1156
 			}
1158 1157
 
1159 1158
 			if ($insertSigOnTop === 'below')
1160 1159
 			{
1161
-				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true));
1160
+				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true));
1162 1161
 			}
1163 1162
 			else
1164 1163
 			{
1165
-				$content['body'] = $font_span.$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true)).$inbetween.$content['body'];
1164
+				$content['body'] = $font_span.$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true)).$inbetween.$content['body'];
1166 1165
 			}
1167 1166
 		}
1168 1167
 		else
1169 1168
 		{
1170
-			$content['body'] = ($font_span?($isFirstLoad === "switchedplaintohtml"?$font_part:$font_span):/*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml"?"</span>":"");
1169
+			$content['body'] = ($font_span ? ($isFirstLoad === "switchedplaintohtml" ? $font_part : $font_span) : /*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml" ? "</span>" : "");
1171 1170
 		}
1172 1171
 		//error_log(__METHOD__.__LINE__.$content['body']);
1173 1172
 
1174 1173
 		// prepare body
1175 1174
 		// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
1176
-		$content['body'] = Api\Translation::convert_jsonsafe($content['body'],'utf-8');
1175
+		$content['body'] = Api\Translation::convert_jsonsafe($content['body'], 'utf-8');
1177 1176
 		//error_log(__METHOD__.__LINE__.array2string($content));
1178 1177
 
1179 1178
 		// get identities of all accounts as "$acc_id:$ident_id" => $identity
1180 1179
 		$sel_options['mailaccount'] = $identities = array();
1181
-		foreach(Mail\Account::search(true,false) as $acc_id => $account)
1180
+		foreach (Mail\Account::search(true, false) as $acc_id => $account)
1182 1181
 		{
1183 1182
 			// do NOT add SMTP only accounts as identities
1184 1183
 			if (!$account->is_imap(false)) continue;
1185 1184
 
1186
-			foreach($account->identities($acc_id) as $ident_id => $identity)
1185
+			foreach ($account->identities($acc_id) as $ident_id => $identity)
1187 1186
 			{
1188 1187
 				$sel_options['mailaccount'][$acc_id.':'.$ident_id] = $identity;
1189 1188
 				$identities[$ident_id] = $identity;
@@ -1194,7 +1193,7 @@  discard block
 block discarded – undo
1194 1193
 		//$content['bcc'] = array('[email protected]','[email protected]');
1195 1194
 		// address stuff like from, to, cc, replyto
1196 1195
 		$destinationRows = 0;
1197
-		foreach(self::$destinations as $destination) {
1196
+		foreach (self::$destinations as $destination) {
1198 1197
 			if (!is_array($content[$destination]))
1199 1198
 			{
1200 1199
 				if (!empty($content[$destination])) $content[$destination] = (array)$content[$destination];
@@ -1202,22 +1201,22 @@  discard block
 block discarded – undo
1202 1201
 			$addr_content = $content[strtolower($destination)];
1203 1202
 			// we clear the given address array and rebuild it
1204 1203
 			unset($content[strtolower($destination)]);
1205
-			foreach((array)$addr_content as $key => $value) {
1206
-				if ($value=="NIL@NIL") continue;
1207
-				if ($destination=='replyto' && str_replace('"','',$value) ==
1208
-					str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
1204
+			foreach ((array)$addr_content as $key => $value) {
1205
+				if ($value == "NIL@NIL") continue;
1206
+				if ($destination == 'replyto' && str_replace('"', '', $value) ==
1207
+					str_replace('"', '', $identities[$this->mail_bo->getDefaultIdentity()]))
1209 1208
 				{
1210 1209
 					// preserve/restore the value to content.
1211
-					$content[strtolower($destination)][]=$value;
1210
+					$content[strtolower($destination)][] = $value;
1212 1211
 					continue;
1213 1212
 				}
1214 1213
 				//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
1215
-				$value = str_replace("\"\"",'"', htmlspecialchars_decode($value, ENT_COMPAT));
1216
-				foreach(Mail::parseAddressList($value) as $addressObject) {
1214
+				$value = str_replace("\"\"", '"', htmlspecialchars_decode($value, ENT_COMPAT));
1215
+				foreach (Mail::parseAddressList($value) as $addressObject) {
1217 1216
 					if ($addressObject->host == '.SYNTAX-ERROR.') continue;
1218
-					$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
1217
+					$address = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
1219 1218
 					//$address = Mail::htmlentities($address, $this->displayCharset);
1220
-					$content[strtolower($destination)][]=$address;
1219
+					$content[strtolower($destination)][] = $address;
1221 1220
 					$destinationRows++;
1222 1221
 				}
1223 1222
 			}
@@ -1225,10 +1224,10 @@  discard block
 block discarded – undo
1225 1224
 		if ($_content)
1226 1225
 		{
1227 1226
 			//input array of _content had no signature information but was seeded later, and content has a valid setting
1228
-			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content)) unset($_content['mailidentity']);
1229
-			$content = array_merge($content,$_content);
1227
+			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity', $_content)) unset($_content['mailidentity']);
1228
+			$content = array_merge($content, $_content);
1230 1229
 
1231
-			if (!empty($content['folder'])) $sel_options['folder']=$this->ajax_searchFolder(0,true);
1230
+			if (!empty($content['folder'])) $sel_options['folder'] = $this->ajax_searchFolder(0, true);
1232 1231
 			if (empty($content['mailaccount'])) $content['mailaccount'] = $this->mail_bo->profileID;
1233 1232
 		}
1234 1233
 		else
@@ -1237,12 +1236,12 @@  discard block
 block discarded – undo
1237 1236
 			$content['mailaccount'] = $this->mail_bo->profileID;
1238 1237
 			//error_log(__METHOD__.__LINE__.$content['body']);
1239 1238
 		}
1240
-		$content['is_html'] = ($content['mimeType'] == 'html'?true:'');
1241
-		$content['is_plain'] = ($content['mimeType'] == 'html'?'':true);
1242
-		$content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text'] =$content['body'];
1243
-		$content['showtempname']=0;
1239
+		$content['is_html'] = ($content['mimeType'] == 'html' ?true:'');
1240
+		$content['is_plain'] = ($content['mimeType'] == 'html' ? '' : true);
1241
+		$content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text'] = $content['body'];
1242
+		$content['showtempname'] = 0;
1244 1243
 		//if (is_array($content['attachments']))error_log(__METHOD__.__LINE__.'before merging content with uploadforCompose:'.array2string($content['attachments']));
1245
-		$content['attachments']=(is_array($content['attachments'])&&is_array($content['uploadForCompose'])?array_merge($content['attachments'],(!empty($content['uploadForCompose'])?$content['uploadForCompose']:array())):(is_array($content['uploadForCompose'])?$content['uploadForCompose']:(is_array($content['attachments'])?$content['attachments']:null)));
1244
+		$content['attachments'] = (is_array($content['attachments']) && is_array($content['uploadForCompose']) ?array_merge($content['attachments'], (!empty($content['uploadForCompose']) ? $content['uploadForCompose'] : array())) : (is_array($content['uploadForCompose']) ? $content['uploadForCompose'] : (is_array($content['attachments']) ? $content['attachments'] : null)));
1246 1245
 		//if (is_array($content['attachments'])) foreach($content['attachments'] as $k => &$file) $file['delete['.$file['tmp_name'].']']=0;
1247 1246
 		$content['no_griddata'] = empty($content['attachments']);
1248 1247
 		$preserv['attachments'] = $content['attachments'];
@@ -1276,12 +1275,12 @@  discard block
 block discarded – undo
1276 1275
 		$sel_options['mimeType'] = self::$mimeTypes;
1277 1276
 		$sel_options['priority'] = self::$priorities;
1278 1277
 		$sel_options['filemode'] = Vfs\Sharing::$modes;
1279
-		if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
1278
+		if (!isset($content['priority']) || empty($content['priority'])) $content['priority'] = 3;
1280 1279
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
1281 1280
 		$etpl = new Etemplate('mail.compose');
1282 1281
 
1283 1282
 		$etpl->setElementAttribute('composeToolbar', 'actions', $this->getToolbarActions($_content));
1284
-		if ($content['mimeType']=='html')
1283
+		if ($content['mimeType'] == 'html')
1285 1284
 		{
1286 1285
 			//mode="$cont[rtfEditorFeatures]" validation_rules="$cont[validation_rules]" base_href="$cont[upload_dir]"
1287 1286
 			$_htmlConfig = Mail::$htmLawed_config;
@@ -1291,23 +1290,23 @@  discard block
 block discarded – undo
1291 1290
 			// and not the eGroupware wide pref to prevent users from trying things that will potentially not work
1292 1291
 			// or not work as expected, as a full featured editor that may be wanted in other apps
1293 1292
 			// is way overloading the "normal" needs for composing mails
1294
-			$content['rtfEditorFeatures']='simple-withimage';//Api\Html\CkEditorConfig::get_ckeditor_config();
1293
+			$content['rtfEditorFeatures'] = 'simple-withimage'; //Api\Html\CkEditorConfig::get_ckeditor_config();
1295 1294
 			//$content['rtfEditorFeatures']='advanced';//Api\Html\CkEditorConfig::get_ckeditor_config();
1296
-			$content['validation_rules']= json_encode(Mail::$htmLawed_config);
1297
-			$etpl->setElementAttribute('mail_htmltext','mode',$content['rtfEditorFeatures']);
1298
-			$etpl->setElementAttribute('mail_htmltext','validation_rules',$content['validation_rules']);
1295
+			$content['validation_rules'] = json_encode(Mail::$htmLawed_config);
1296
+			$etpl->setElementAttribute('mail_htmltext', 'mode', $content['rtfEditorFeatures']);
1297
+			$etpl->setElementAttribute('mail_htmltext', 'validation_rules', $content['validation_rules']);
1299 1298
 			Mail::$htmLawed_config = $_htmlConfig;
1300 1299
 		}
1301 1300
 
1302
-		if (isset($content['composeID'])&&!empty($content['composeID']))
1301
+		if (isset($content['composeID']) && !empty($content['composeID']))
1303 1302
 		{
1304 1303
 			$composeCache = $content;
1305 1304
 			unset($composeCache['body']);
1306 1305
 			unset($composeCache['mail_htmltext']);
1307 1306
 			unset($composeCache['mail_plaintext']);
1308
-			Api\Cache::setCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID,$composeCache,$expiration=60*60*2);
1307
+			Api\Cache::setCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID, $composeCache, $expiration = 60 * 60 * 2);
1309 1308
 		}
1310
-		if (!isset($_content['serverID'])||empty($_content['serverID']))
1309
+		if (!isset($_content['serverID']) || empty($_content['serverID']))
1311 1310
 		{
1312 1311
 			$content['serverID'] = $this->mail_bo->profileID;
1313 1312
 		}
@@ -1323,13 +1322,13 @@  discard block
 block discarded – undo
1323 1322
 		$preserv['list-id'] = $content['list-id'];
1324 1323
 		$preserv['mode'] = $content['mode'];
1325 1324
 		// convert it back to checkbox expectations
1326
-		if($content['mimeType'] == 'html') {
1327
-			$content['mimeType']=1;
1325
+		if ($content['mimeType'] == 'html') {
1326
+			$content['mimeType'] = 1;
1328 1327
 		} else {
1329
-			$content['mimeType']=0;
1328
+			$content['mimeType'] = 0;
1330 1329
 		}
1331 1330
 		// set the current selected mailaccount as param for folderselection
1332
-		$etpl->setElementAttribute('folder','autocomplete_params',array('mailaccount'=>$content['mailaccount']));
1331
+		$etpl->setElementAttribute('folder', 'autocomplete_params', array('mailaccount'=>$content['mailaccount']));
1333 1332
 		// join again mailaccount and identity
1334 1333
 		$content['mailaccount'] .= ':'.$content['mailidentity'];
1335 1334
 		//Try to set the initial selected account to the first identity match found
@@ -1348,14 +1347,14 @@  discard block
 block discarded – undo
1348 1347
 			}
1349 1348
 		}
1350 1349
 		// Resolve distribution list before send content to client
1351
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $f)
1350
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $f)
1352 1351
 		{
1353
-			if (is_array($content[$f])) $content[$f]= self::resolveEmailAddressList ($content[$f]);
1352
+			if (is_array($content[$f])) $content[$f] = self::resolveEmailAddressList($content[$f]);
1354 1353
 		}
1355 1354
 
1356 1355
 		$content['to'] = self::resolveEmailAddressList($content['to']);
1357 1356
 		//error_log(__METHOD__.__LINE__.array2string($content));
1358
-		$etpl->exec('mail.mail_compose.compose',$content,$sel_options,array(),$preserv,2);
1357
+		$etpl->exec('mail.mail_compose.compose', $content, $sel_options, array(), $preserv, 2);
1359 1358
 	}
1360 1359
 
1361 1360
 	/**
@@ -1376,9 +1375,9 @@  discard block
 block discarded – undo
1376 1375
 		$content = array();
1377 1376
 		//error_log(__METHOD__.__LINE__.array2string($mail_id).", $part_id, $from, $_focusElement, $suppressSigOnTop, $isReply");
1378 1377
 		// on forward we may have to support multiple ids
1379
-		if ($from=='forward')
1378
+		if ($from == 'forward')
1380 1379
 		{
1381
-			$replyIds = explode(',',$mail_id);
1380
+			$replyIds = explode(',', $mail_id);
1382 1381
 			$mail_id = $replyIds[0];
1383 1382
 		}
1384 1383
 		$hA = mail_ui::splitRowID($mail_id);
@@ -1390,15 +1389,15 @@  discard block
 block discarded – undo
1390 1389
 			$this->changeProfile($icServerID);
1391 1390
 		}
1392 1391
 		$icServer = $this->mail_bo->icServer;
1393
-		if (!empty($folder) && !empty($msgUID) )
1392
+		if (!empty($folder) && !empty($msgUID))
1394 1393
 		{
1395 1394
 			// this fill the session data with the values from the original email
1396
-			switch($from)
1395
+			switch ($from)
1397 1396
 			{
1398 1397
 				case 'composefromdraft':
1399 1398
 				case 'composeasnew':
1400 1399
 					$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
1401
-					if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
1400
+					if ($from == 'composefromdraft') $content['mode'] = 'composefromdraft';
1402 1401
 					$content['processedmail_id'] = $mail_id;
1403 1402
 
1404 1403
 					$_focusElement = 'body';
@@ -1414,7 +1413,7 @@  discard block
 block discarded – undo
1414 1413
 					$isReply = true;
1415 1414
 					break;
1416 1415
 				case 'forward':
1417
-					$mode  = ($_GET['mode']=='forwardinline'?'inline':'asmail');
1416
+					$mode = ($_GET['mode'] == 'forwardinline' ? 'inline' : 'asmail');
1418 1417
 					// this fill the session data with the values from the original email
1419 1418
 					foreach ($replyIds as &$mail_id)
1420 1419
 					{
@@ -1424,14 +1423,14 @@  discard block
 block discarded – undo
1424 1423
 						$folder = $hA['folder'];
1425 1424
 						$content = $this->getForwardData($icServer, $folder, $msgUID, $part_id, $mode);
1426 1425
 					}
1427
-					$content['processedmail_id'] = implode(',',$replyIds);
1426
+					$content['processedmail_id'] = implode(',', $replyIds);
1428 1427
 					$content['mode'] = 'forward';
1429
-					$isReply = ($mode?$mode=='inline':$this->mailPreferences['message_forwarding'] == 'inline');
1430
-					$suppressSigOnTop = false;// ($mode && $mode=='inline'?true:false);// may be a better solution
1428
+					$isReply = ($mode ? $mode == 'inline' : $this->mailPreferences['message_forwarding'] == 'inline');
1429
+					$suppressSigOnTop = false; // ($mode && $mode=='inline'?true:false);// may be a better solution
1431 1430
 					$_focusElement = 'to';
1432 1431
 					break;
1433 1432
 				default:
1434
-					error_log('Unhandled compose source: ' . $from);
1433
+					error_log('Unhandled compose source: '.$from);
1435 1434
 			}
1436 1435
 		}
1437 1436
 		else if ($from == 'merge' && $_REQUEST['document'])
@@ -1446,12 +1445,12 @@  discard block
 block discarded – undo
1446 1445
 			$document_merge = new $merge_class();
1447 1446
 			$this->mail_bo->openConnection();
1448 1447
 			$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
1449
-			if (!is_array($merge_ids)) $merge_ids = explode(',',$merge_ids);
1448
+			if (!is_array($merge_ids)) $merge_ids = explode(',', $merge_ids);
1450 1449
 			try
1451 1450
 			{
1452 1451
 				$merged_mail_id = '';
1453 1452
 				$folder = '';
1454
-				if(($error = $document_merge->check_document($_REQUEST['document'],'')))
1453
+				if (($error = $document_merge->check_document($_REQUEST['document'], '')))
1455 1454
 				{
1456 1455
 					$content['msg'] = $error;
1457 1456
 					return $content;
@@ -1461,10 +1460,10 @@  discard block
 block discarded – undo
1461 1460
 				//$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
1462 1461
 
1463 1462
 				// Actually do the merge
1464
-				if(count($merge_ids) <= 1)
1463
+				if (count($merge_ids) <= 1)
1465 1464
 				{
1466 1465
 					$results = $this->mail_bo->importMessageToMergeAndSend(
1467
-						$document_merge, Vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1466
+						$document_merge, Vfs::PREFIX.$_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1468 1467
 					);
1469 1468
 
1470 1469
 					// Open compose
@@ -1475,9 +1474,9 @@  discard block
 block discarded – undo
1475 1474
 				}
1476 1475
 				else
1477 1476
 				{
1478
-					$success = implode(', ',$results['success']);
1477
+					$success = implode(', ', $results['success']);
1479 1478
 					$fail = implode(', ', $results['failed']);
1480
-					if($success) Framework::message($success, 'success');
1479
+					if ($success) Framework::message($success, 'success');
1481 1480
 					Framework::window_close($fail);
1482 1481
 				}
1483 1482
 			}
@@ -1505,22 +1504,22 @@  discard block
 block discarded – undo
1505 1504
 		return 1;
1506 1505
 	}
1507 1506
 
1508
-	function convertHTMLToText(&$_html,$sourceishtml = true, $stripcrl=false)
1507
+	function convertHTMLToText(&$_html, $sourceishtml = true, $stripcrl = false)
1509 1508
 	{
1510 1509
 		$stripalltags = true;
1511 1510
 		// third param is stripalltags, we may not need that, if the source is already in ascii
1512
-		if (!$sourceishtml) $stripalltags=false;
1513
-		return Api\Mail\Html::convertHTMLToText($_html,$this->displayCharset,$stripcrl,$stripalltags);
1511
+		if (!$sourceishtml) $stripalltags = false;
1512
+		return Api\Mail\Html::convertHTMLToText($_html, $this->displayCharset, $stripcrl, $stripalltags);
1514 1513
 	}
1515 1514
 
1516 1515
 	function generateRFC822Address($_addressObject)
1517 1516
 	{
1518
-		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1519
-			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1520
-		} elseif($_addressObject->mailbox && $_addressObject->host) {
1521
-			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1517
+		if ($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1518
+			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1519
+		} elseif ($_addressObject->mailbox && $_addressObject->host) {
1520
+			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1522 1521
 		} else {
1523
-			return $this->mail_bo->decode_header($_addressObject->mailbox,true);
1522
+			return $this->mail_bo->decode_header($_addressObject->mailbox, true);
1524 1523
 		}
1525 1524
 	}
1526 1525
 
@@ -1535,9 +1534,9 @@  discard block
 block discarded – undo
1535 1534
 	// $_mode can be:
1536 1535
 	// single: for a reply to one address
1537 1536
 	// all: for a reply to all
1538
-	function getDraftData($_icServer, $_folder, $_uid, $_partID=NULL)
1537
+	function getDraftData($_icServer, $_folder, $_uid, $_partID = NULL)
1539 1538
 	{
1540
-		unset($_icServer);	// not used
1539
+		unset($_icServer); // not used
1541 1540
 		$this->sessionData['to'] = array();
1542 1541
 
1543 1542
 		$mail_bo = $this->mail_bo;
@@ -1546,7 +1545,7 @@  discard block
 block discarded – undo
1546 1545
 
1547 1546
 		// get message headers for specified message
1548 1547
 		#$headers	= $mail_bo->getMessageHeader($_folder, $_uid);
1549
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID);
1548
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID);
1550 1549
 		$addHeadInfo = $mail_bo->getMessageHeader($_uid, $_partID);
1551 1550
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
1552 1551
 		// horde does not support the encoding of thread-topic, and probably will not no so in the future
@@ -1554,10 +1553,10 @@  discard block
 block discarded – undo
1554 1553
 
1555 1554
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1556 1555
 		if (!empty($addHeadInfo['X-MAILFOLDER'])) {
1557
-			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val ) {
1558
-				$fval=$val;
1556
+			foreach (explode('|', $addHeadInfo['X-MAILFOLDER']) as $val) {
1557
+				$fval = $val;
1559 1558
 				$icServerID = $mail_bo->icServer->ImapServerId;
1560
-				if (stripos($val,'::')!==false) list($icServerID,$fval) = explode('::',$val,2);
1559
+				if (stripos($val, '::') !== false) list($icServerID, $fval) = explode('::', $val, 2);
1561 1560
 				if ($icServerID != $mail_bo->icServer->ImapServerId) continue;
1562 1561
 				if ($mail_bo->folderExists($fval)) $this->sessionData['folder'][] = $val;
1563 1562
 			}
@@ -1593,71 +1592,71 @@  discard block
 block discarded – undo
1593 1592
 			}
1594 1593
 		}
1595 1594
 		// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
1596
-		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);//array('uid'=>$_uid,'folder'=>$_folder);
1595
+		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid); //array('uid'=>$_uid,'folder'=>$_folder);
1597 1596
 		$this->sessionData['uid'] = $_uid;
1598 1597
 		$this->sessionData['messageFolder'] = $_folder;
1599 1598
 		$this->sessionData['isDraft'] = true;
1600 1599
 		$foundAddresses = array();
1601
-		foreach((array)$headers['CC'] as $val) {
1602
-			$rfcAddr=Mail::parseAddressList($val);
1600
+		foreach ((array)$headers['CC'] as $val) {
1601
+			$rfcAddr = Mail::parseAddressList($val);
1603 1602
 			$_rfcAddr = $rfcAddr[0];
1604 1603
 			if (!$_rfcAddr->valid) continue;
1605
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1604
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1606 1605
 				continue;
1607 1606
 			}
1608
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1609
-			if(!$foundAddresses[$keyemail]) {
1610
-				$address = $this->mail_bo->decode_header($val,true);
1607
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1608
+			if (!$foundAddresses[$keyemail]) {
1609
+				$address = $this->mail_bo->decode_header($val, true);
1611 1610
 				$this->sessionData['cc'][] = $val;
1612 1611
 				$foundAddresses[$keyemail] = true;
1613 1612
 			}
1614 1613
 		}
1615 1614
 
1616
-		foreach((array)$headers['TO'] as $val) {
1617
-			if(!is_array($val))
1615
+		foreach ((array)$headers['TO'] as $val) {
1616
+			if (!is_array($val))
1618 1617
 			{
1619 1618
 				$this->sessionData['to'][] = $val;
1620 1619
 				continue;
1621 1620
 			}
1622
-			$rfcAddr=Mail::parseAddressList($val);
1621
+			$rfcAddr = Mail::parseAddressList($val);
1623 1622
 			$_rfcAddr = $rfcAddr[0];
1624 1623
 			if (!$_rfcAddr->valid) continue;
1625
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1624
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1626 1625
 				continue;
1627 1626
 			}
1628
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1629
-			if(!$foundAddresses[$keyemail]) {
1630
-				$address = $this->mail_bo->decode_header($val,true);
1627
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1628
+			if (!$foundAddresses[$keyemail]) {
1629
+				$address = $this->mail_bo->decode_header($val, true);
1631 1630
 				$this->sessionData['to'][] = $val;
1632 1631
 				$foundAddresses[$keyemail] = true;
1633 1632
 			}
1634 1633
 		}
1635 1634
 
1636
-		foreach((array)$headers['REPLY-TO'] as $val) {
1637
-			$rfcAddr=Mail::parseAddressList($val);
1635
+		foreach ((array)$headers['REPLY-TO'] as $val) {
1636
+			$rfcAddr = Mail::parseAddressList($val);
1638 1637
 			$_rfcAddr = $rfcAddr[0];
1639 1638
 			if (!$_rfcAddr->valid) continue;
1640
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1639
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1641 1640
 				continue;
1642 1641
 			}
1643
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1644
-			if(!$foundAddresses[$keyemail]) {
1645
-				$address = $this->mail_bo->decode_header($val,true);
1642
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1643
+			if (!$foundAddresses[$keyemail]) {
1644
+				$address = $this->mail_bo->decode_header($val, true);
1646 1645
 				$this->sessionData['replyto'][] = $val;
1647 1646
 				$foundAddresses[$keyemail] = true;
1648 1647
 			}
1649 1648
 		}
1650 1649
 
1651
-		foreach((array)$headers['BCC'] as $val) {
1652
-			$rfcAddr=Mail::parseAddressList($val);
1650
+		foreach ((array)$headers['BCC'] as $val) {
1651
+			$rfcAddr = Mail::parseAddressList($val);
1653 1652
 			$_rfcAddr = $rfcAddr[0];
1654 1653
 			if (!$_rfcAddr->valid) continue;
1655
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1654
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1656 1655
 				continue;
1657 1656
 			}
1658
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1659
-			if(!$foundAddresses[$keyemail]) {
1660
-				$address = $this->mail_bo->decode_header($val,true);
1657
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1658
+			if (!$foundAddresses[$keyemail]) {
1659
+				$address = $this->mail_bo->decode_header($val, true);
1661 1660
 				$this->sessionData['bcc'][] = $val;
1662 1661
 				$foundAddresses[$keyemail] = true;
1663 1662
 			}
@@ -1666,48 +1665,48 @@  discard block
 block discarded – undo
1666 1665
 		$this->sessionData['subject']	= $mail_bo->decode_header($headers['SUBJECT']);
1667 1666
 		// remove a printview tag if composing
1668 1667
 		$searchfor = '/^\['.lang('printview').':\]/';
1669
-		$this->sessionData['subject'] = preg_replace($searchfor,'',$this->sessionData['subject']);
1670
-		$bodyParts = $mail_bo->getMessageBody($_uid,'always_display', $_partID);
1668
+		$this->sessionData['subject'] = preg_replace($searchfor, '', $this->sessionData['subject']);
1669
+		$bodyParts = $mail_bo->getMessageBody($_uid, 'always_display', $_partID);
1671 1670
 		//_debug_array($bodyParts);
1672 1671
 		#$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
1673
-		if($bodyParts['0']['mimeType'] == 'text/html') {
1674
-			$this->sessionData['mimeType'] 	= 'html';
1672
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
1673
+			$this->sessionData['mimeType'] = 'html';
1675 1674
 
1676
-			for($i=0; $i<count($bodyParts); $i++) {
1677
-				if($i>0) {
1675
+			for ($i = 0; $i < count($bodyParts); $i++) {
1676
+				if ($i > 0) {
1678 1677
 					$this->sessionData['body'] .= '<hr>';
1679 1678
 				}
1680
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
1679
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
1681 1680
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']);
1682 1681
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
1683 1682
 				}
1684
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1683
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1685 1684
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1686 1685
 				#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1687
-				$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
1686
+				$this->sessionData['body'] .= ($i > 0 ? "<br>" : "").$bodyParts[$i]['body'];
1688 1687
 			}
1689 1688
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID);
1690 1689
 
1691 1690
 		} else {
1692
-			$this->sessionData['mimeType']	= 'plain';
1691
+			$this->sessionData['mimeType'] = 'plain';
1693 1692
 
1694
-			for($i=0; $i<count($bodyParts); $i++) {
1695
-				if($i>0) {
1693
+			for ($i = 0; $i < count($bodyParts); $i++) {
1694
+				if ($i > 0) {
1696 1695
 					$this->sessionData['body'] .= "<hr>";
1697 1696
 				}
1698
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1697
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1699 1698
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1700 1699
 				#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1701
-				$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
1700
+				$this->sessionData['body'] .= ($i > 0 ? "\r\n" : "").$bodyParts[$i]['body'];
1702 1701
 			}
1703
-			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID,'plain');
1702
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'plain');
1704 1703
 		}
1705 1704
 
1706
-		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID))) {
1707
-			foreach($attachments as $attachment) {
1705
+		if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID))) {
1706
+			foreach ($attachments as $attachment) {
1708 1707
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
1709 1708
 				$cid = $attachment['cid'];
1710
-				$match=null;
1709
+				$match = null;
1711 1710
 				preg_match("/cid:{$cid}/", $bodyParts['0']['body'], $match);
1712 1711
 				//error_log(__METHOD__.__LINE__.'searching for cid:'."/cid:{$cid}/".'#'.$r.'#'.array2string($match));
1713 1712
 				if (!$match || !$attachment['cid'])
@@ -1727,7 +1726,7 @@  discard block
 block discarded – undo
1727 1726
 
1728 1727
 	function getErrorInfo()
1729 1728
 	{
1730
-		if(isset($this->errorInfo)) {
1729
+		if (isset($this->errorInfo)) {
1731 1730
 			$errorInfo = $this->errorInfo;
1732 1731
 			unset($this->errorInfo);
1733 1732
 			return $errorInfo;
@@ -1735,39 +1734,39 @@  discard block
 block discarded – undo
1735 1734
 		return false;
1736 1735
 	}
1737 1736
 
1738
-	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode=false)
1737
+	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode = false)
1739 1738
 	{
1740 1739
 		if ($_mode)
1741 1740
 		{
1742 1741
 			$modebuff = $this->mailPreferences['message_forwarding'];
1743 1742
 			$this->mailPreferences['message_forwarding'] = $_mode;
1744 1743
 		}
1745
-		if  ($this->mailPreferences['message_forwarding'] == 'inline') {
1744
+		if ($this->mailPreferences['message_forwarding'] == 'inline') {
1746 1745
 			$this->getReplyData('forward', $_icServer, $_folder, $_uid, $_partID);
1747 1746
 		}
1748
-		$mail_bo    = $this->mail_bo;
1747
+		$mail_bo = $this->mail_bo;
1749 1748
 		$mail_bo->openConnection();
1750 1749
 		$mail_bo->reopen($_folder);
1751 1750
 
1752 1751
 		// get message headers for specified message
1753
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder);
1752
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder);
1754 1753
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1755 1754
 		//_debug_array($headers); exit;
1756 1755
 		// check for Re: in subject header
1757
-		$this->sessionData['subject'] 	= "[FWD] " . $mail_bo->decode_header($headers['SUBJECT']);
1756
+		$this->sessionData['subject'] = "[FWD] ".$mail_bo->decode_header($headers['SUBJECT']);
1758 1757
 		// the three attributes below are substituted by processedmail_id and mode
1759 1758
 		//$this->sessionData['sourceFolder']=$_folder;
1760 1759
 		//$this->sessionData['forwardFlag']='forwarded';
1761 1760
 		//$this->sessionData['forwardedUID']=$_uid;
1762
-		if  ($this->mailPreferences['message_forwarding'] == 'asmail') {
1763
-			$this->sessionData['mimeType']  = $this->mailPreferences['composeOptions'];
1764
-			if($headers['SIZE'])
1761
+		if ($this->mailPreferences['message_forwarding'] == 'asmail') {
1762
+			$this->sessionData['mimeType'] = $this->mailPreferences['composeOptions'];
1763
+			if ($headers['SIZE'])
1765 1764
 				$size				= $headers['SIZE'];
1766 1765
 			else
1767 1766
 				$size				= lang('unknown');
1768 1767
 
1769 1768
 			$this->addMessageAttachment($_uid, $_partID, $_folder,
1770
-				$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
1769
+				$mail_bo->decode_header(($headers['SUBJECT'] ? $headers['SUBJECT'] : lang('no subject'))).'.eml',
1771 1770
 				'MESSAGE/RFC822', $size);
1772 1771
 		}
1773 1772
 		else
@@ -1775,10 +1774,10 @@  discard block
 block discarded – undo
1775 1774
 			unset($this->sessionData['in-reply-to']);
1776 1775
 			unset($this->sessionData['to']);
1777 1776
 			unset($this->sessionData['cc']);
1778
-			if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false))) {
1777
+			if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID, null, true, false, false))) {
1779 1778
 				//error_log(__METHOD__.__LINE__.':'.array2string($attachments));
1780
-				foreach($attachments as $attachment) {
1781
-					if (!($attachment['cid'] && preg_match("/image\//",$attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1779
+				foreach ($attachments as $attachment) {
1780
+					if (!($attachment['cid'] && preg_match("/image\//", $attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1782 1781
 					{
1783 1782
 						$this->addMessageAttachment($_uid, $attachment['partID'],
1784 1783
 							$_folder,
@@ -1807,7 +1806,7 @@  discard block
 block discarded – undo
1807 1806
 	 * @param array $_content the content passed to the function and to be modified
1808 1807
 	 * @return void
1809 1808
 	 */
1810
-	function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false)
1809
+	function addAttachment($_formData, &$_content, $eliminateDoubleAttachments = false)
1811 1810
 	{
1812 1811
 		//error_log(__METHOD__.__LINE__.' Formdata:'.array2string($_formData).' Content:'.array2string($_content));
1813 1812
 
@@ -1816,7 +1815,7 @@  discard block
 block discarded – undo
1816 1815
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
1817 1816
 		try
1818 1817
 		{
1819
-			$tmpFileName = Mail::checkFileBasics($_formData,$this->composeID,false);
1818
+			$tmpFileName = Mail::checkFileBasics($_formData, $this->composeID, false);
1820 1819
 		}
1821 1820
 		catch (Api\Exception\WrongUserinput $e)
1822 1821
 		{
@@ -1832,8 +1831,8 @@  discard block
 block discarded – undo
1832 1831
 			foreach ((array)$_content['attachments'] as $attach)
1833 1832
 			{
1834 1833
 				if ($attach['name'] && $attach['name'] == $_formData['name'] &&
1835
-					strtolower($_formData['type'])== strtolower($attach['type']) &&
1836
-					stripos($_formData['file'],'vfs://') !== false) return;
1834
+					strtolower($_formData['type']) == strtolower($attach['type']) &&
1835
+					stripos($_formData['file'], 'vfs://') !== false) return;
1837 1836
 			}
1838 1837
 		}
1839 1838
 		if ($attachfailed === false)
@@ -1845,7 +1844,7 @@  discard block
 block discarded – undo
1845 1844
 				'tmp_name'	=> $tmpFileName,
1846 1845
 				'size'	=> $_formData['size']
1847 1846
 			);
1848
-			if (!is_array($_content['attachments'])) $_content['attachments']=array();
1847
+			if (!is_array($_content['attachments'])) $_content['attachments'] = array();
1849 1848
 			$_content['attachments'][] = $buffer;
1850 1849
 			unset($buffer);
1851 1850
 		}
@@ -1855,9 +1854,9 @@  discard block
 block discarded – undo
1855 1854
 		}
1856 1855
 	}
1857 1856
 
1858
-	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail= null)
1857
+	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail = null)
1859 1858
 	{
1860
-		$this->sessionData['attachments'][]=array (
1859
+		$this->sessionData['attachments'][] = array(
1861 1860
 			'uid'		=> $_uid,
1862 1861
 			'partID'	=> $_partID,
1863 1862
 			'name'		=> $_name,
@@ -1865,7 +1864,7 @@  discard block
 block discarded – undo
1865 1864
 			'size'		=> $_size,
1866 1865
 			'folder'	=> $_folder,
1867 1866
 			'winmailFlag' => $_is_winmail,
1868
-			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID)?$_partID:count($this->sessionData['attachments'])+1),
1867
+			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID) ? $_partID : count($this->sessionData['attachments']) + 1),
1869 1868
 		);
1870 1869
 	}
1871 1870
 
@@ -1874,7 +1873,7 @@  discard block
 block discarded – undo
1874 1873
 		// read attachment data from etemplate request, use tmpname only to identify it
1875 1874
 		if (($request = Etemplate\Request::read($_GET['etemplate_exec_id'])))
1876 1875
 		{
1877
-			foreach($request->preserv['attachments'] as $attachment)
1876
+			foreach ($request->preserv['attachments'] as $attachment)
1878 1877
 			{
1879 1878
 				if ($_GET['tmpname'] === $attachment['tmp_name']) break;
1880 1879
 			}
@@ -1886,7 +1885,7 @@  discard block
 block discarded – undo
1886 1885
 		}
1887 1886
 
1888 1887
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
1889
-		if (parse_url($attachment['tmp_name'],PHP_URL_SCHEME) == 'vfs')
1888
+		if (parse_url($attachment['tmp_name'], PHP_URL_SCHEME) == 'vfs')
1890 1889
 		{
1891 1890
 			Vfs::load_wrapper('vfs');
1892 1891
 		}
@@ -1895,7 +1894,7 @@  discard block
 block discarded – undo
1895 1894
 		{
1896 1895
 			$attachment['tmp_name'] = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['tmp_name']);
1897 1896
 		}
1898
-		if(!file_exists($attachment['tmp_name']))
1897
+		if (!file_exists($attachment['tmp_name']))
1899 1898
 		{
1900 1899
 			header('HTTP/1.1 404 Not found');
1901 1900
 			die('Attachment '.htmlspecialchars($attachment['tmp_name']).' NOT found!');
@@ -1908,7 +1907,7 @@  discard block
 block discarded – undo
1908 1907
 			if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY')
1909 1908
 			{
1910 1909
 				$sfxMimeType = $attachment['type'];
1911
-				$buff = explode('.',$attachment['tmp_name']);
1910
+				$buff = explode('.', $attachment['tmp_name']);
1912 1911
 				$suffix = '';
1913 1912
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
1914 1913
 				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -1920,10 +1919,10 @@  discard block
 block discarded – undo
1920 1919
 			{
1921 1920
 				//error_log(__METHOD__."about to call calendar_ical");
1922 1921
 				$calendar_ical = new calendar_ical();
1923
-				$eventid = $calendar_ical->search($attachment['attachment'],-1);
1922
+				$eventid = $calendar_ical->search($attachment['attachment'], -1);
1924 1923
 				//error_log(__METHOD__.array2string($eventid));
1925 1924
 				if (!$eventid) $eventid = -1;
1926
-				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
1925
+				$event = $calendar_ical->importVCal($attachment['attachment'], (is_array($eventid) ? $eventid[0] : $eventid), null, true);
1927 1926
 				//error_log(__METHOD__.$event);
1928 1927
 				if ((int)$event > 0)
1929 1928
 				{
@@ -1931,7 +1930,7 @@  discard block
 block discarded – undo
1931 1930
 						'menuaction'      => 'calendar.calendar_uiforms.edit',
1932 1931
 						'cal_id'      => $event,
1933 1932
 					);
1934
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1933
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1935 1934
 				}
1936 1935
 				//Import failed, download content anyway
1937 1936
 			}
@@ -1946,13 +1945,13 @@  discard block
 block discarded – undo
1946 1945
 				{
1947 1946
 					$vcard['uid'] = trim($vcard['uid']);
1948 1947
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
1949
-					$contact = $addressbook_vcal->find_contact($vcard,false);
1948
+					$contact = $addressbook_vcal->find_contact($vcard, false);
1950 1949
 				}
1951 1950
 				if (!$contact) $contact = null;
1952 1951
 				// if there are not enough fields in the vcard (or the parser was unable to correctly parse the vcard (as of VERSION:3.0 created by MSO))
1953
-				if ($contact || count($vcard)>2)
1952
+				if ($contact || count($vcard) > 2)
1954 1953
 				{
1955
-					$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true);
1954
+					$contact = $addressbook_vcal->addVCard($attachment['attachment'], (is_array($contact) ?array_shift($contact) : $contact), true);
1956 1955
 				}
1957 1956
 				if ((int)$contact > 0)
1958 1957
 				{
@@ -1960,13 +1959,13 @@  discard block
 block discarded – undo
1960 1959
 						'menuaction'	=> 'addressbook.addressbook_ui.edit',
1961 1960
 						'contact_id'	=> $contact,
1962 1961
 					);
1963
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1962
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1964 1963
 				}
1965 1964
 				//Import failed, download content anyway
1966 1965
 			}
1967 1966
 		}
1968 1967
 		//error_log(__METHOD__.__LINE__.'->'.array2string($attachment));
1969
-		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size=0, true, $_GET['mode'] == "save");
1968
+		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size = 0, true, $_GET['mode'] == "save");
1970 1969
 		echo $attachment['attachment'];
1971 1970
 
1972 1971
 		exit();
@@ -1979,11 +1978,11 @@  discard block
 block discarded – undo
1979 1978
 	 * @param string haystack
1980 1979
 	 * @return boolean
1981 1980
 	 */
1982
-	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack) {
1981
+	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst, $haystack) {
1983 1982
 		foreach (array_keys($arrayToTestAgainst) as $k)
1984 1983
 		{
1985 1984
 			//error_log(__METHOD__.__LINE__.':'.$k.'<->'.$haystack);
1986
-			if (stripos($haystack,$k)!==false)
1985
+			if (stripos($haystack, $k) !== false)
1987 1986
 			{
1988 1987
 				//error_log(__METHOD__.__LINE__.':FOUND:'.$k.'<->'.$haystack.function_backtrace());
1989 1988
 				return true;
@@ -2006,10 +2005,10 @@  discard block
 block discarded – undo
2006 2005
 	 */
2007 2006
 	function getReplyData($_mode, $_icServer, $_folder, $_uid, $_partID)
2008 2007
 	{
2009
-		unset($_icServer);	// not used
2008
+		unset($_icServer); // not used
2010 2009
 		$foundAddresses = array();
2011 2010
 
2012
-		$mail_bo  = $this->mail_bo;
2011
+		$mail_bo = $this->mail_bo;
2013 2012
 		$mail_bo->openConnection();
2014 2013
 		$mail_bo->reopen($_folder);
2015 2014
 
@@ -2017,20 +2016,20 @@  discard block
 block discarded – undo
2017 2016
 
2018 2017
 		// get message headers for specified message
2019 2018
 		//print "AAAA: $_folder, $_uid, $_partID<br>";
2020
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder,$useHeaderInsteadOfEnvelope=true);
2019
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder, $useHeaderInsteadOfEnvelope = true);
2021 2020
 		//$headers	= $mail_bo->getMessageHeader($_uid, $_partID, true, true, $_folder);
2022 2021
 		$this->sessionData['uid'] = $_uid;
2023 2022
 		$this->sessionData['messageFolder'] = $_folder;
2024
-		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO']?$headers['IN-REPLY-TO']:$headers['MESSAGE_ID']);
2025
-		$this->sessionData['references'] = ($headers['REFERENCES']?$headers['REFERENCES']:$headers['MESSAGE_ID']);
2023
+		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO'] ? $headers['IN-REPLY-TO'] : $headers['MESSAGE_ID']);
2024
+		$this->sessionData['references'] = ($headers['REFERENCES'] ? $headers['REFERENCES'] : $headers['MESSAGE_ID']);
2026 2025
 
2027 2026
 		// break reference into multiple lines if they're greater than 998 chars
2028 2027
 		// and remove comma seperation. Fix error serer does not support binary
2029 2028
 		// data due to long references.
2030
-		if (strlen($this->sessionData['references'])> 998)
2029
+		if (strlen($this->sessionData['references']) > 998)
2031 2030
 		{
2032
-			$temp_refs = explode(',',$this->sessionData['references']);
2033
-			$this->sessionData['references'] = implode(" ",$temp_refs);
2031
+			$temp_refs = explode(',', $this->sessionData['references']);
2032
+			$this->sessionData['references'] = implode(" ", $temp_refs);
2034 2033
 		}
2035 2034
 
2036 2035
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
@@ -2040,36 +2039,36 @@  discard block
 block discarded – undo
2040 2039
 		if ($headers['LIST-ID']) $this->sessionData['list-id'] = $headers['LIST-ID'];
2041 2040
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_mode.':'.array2string($headers));
2042 2041
 		// check for Reply-To: header and use if available
2043
-		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2044
-			foreach($headers['REPLY-TO'] as $val) {
2045
-				if(!$foundAddresses[$val]) {
2042
+		if (!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2043
+			foreach ($headers['REPLY-TO'] as $val) {
2044
+				if (!$foundAddresses[$val]) {
2046 2045
 					$oldTo[] = $val;
2047 2046
 					$foundAddresses[$val] = true;
2048 2047
 				}
2049 2048
 			}
2050
-			$oldToAddress	= (is_array($headers['REPLY-TO'])?$headers['REPLY-TO'][0]:$headers['REPLY-TO']);
2049
+			$oldToAddress = (is_array($headers['REPLY-TO']) ? $headers['REPLY-TO'][0] : $headers['REPLY-TO']);
2051 2050
 		} else {
2052
-			foreach($headers['FROM'] as $val) {
2053
-				if(!$foundAddresses[$val]) {
2051
+			foreach ($headers['FROM'] as $val) {
2052
+				if (!$foundAddresses[$val]) {
2054 2053
 					$oldTo[] = $val;
2055 2054
 					$foundAddresses[$val] = true;
2056 2055
 				}
2057 2056
 			}
2058
-			$oldToAddress	= (is_array($headers['FROM'])?$headers['FROM'][0]:$headers['FROM']);
2057
+			$oldToAddress = (is_array($headers['FROM']) ? $headers['FROM'][0] : $headers['FROM']);
2059 2058
 		}
2060 2059
 		//error_log(__METHOD__.__LINE__.' OldToAddress:'.$oldToAddress.'#');
2061
-		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) ) {
2060
+		if ($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $oldToAddress))) {
2062 2061
 			$this->sessionData['to'] = $oldTo;
2063 2062
 		}
2064 2063
 
2065
-		if($_mode == 'all') {
2064
+		if ($_mode == 'all') {
2066 2065
 			// reply to any address which is cc, but not to my self
2067 2066
 			#if($headers->cc) {
2068
-				foreach($headers['CC'] as $val) {
2069
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2067
+				foreach ($headers['CC'] as $val) {
2068
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2070 2069
 						continue;
2071 2070
 					}
2072
-					if(!$foundAddresses[$val]) {
2071
+					if (!$foundAddresses[$val]) {
2073 2072
 						$this->sessionData['cc'][] = $val;
2074 2073
 						$foundAddresses[$val] = true;
2075 2074
 					}
@@ -2078,11 +2077,11 @@  discard block
 block discarded – undo
2078 2077
 
2079 2078
 			// reply to any address which is to, but not to my self
2080 2079
 			#if($headers->to) {
2081
-				foreach($headers['TO'] as $val) {
2082
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2080
+				foreach ($headers['TO'] as $val) {
2081
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2083 2082
 						continue;
2084 2083
 					}
2085
-					if(!$foundAddresses[$val]) {
2084
+					if (!$foundAddresses[$val]) {
2086 2085
 						$this->sessionData['to'][] = $val;
2087 2086
 						$foundAddresses[$val] = true;
2088 2087
 					}
@@ -2090,12 +2089,12 @@  discard block
 block discarded – undo
2090 2089
 			#}
2091 2090
 
2092 2091
 			#if($headers->from) {
2093
-				foreach($headers['FROM'] as $val) {
2094
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2092
+				foreach ($headers['FROM'] as $val) {
2093
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2095 2094
 						continue;
2096 2095
 					}
2097 2096
 					//error_log(__METHOD__.__LINE__.' '.$val);
2098
-					if(!$foundAddresses[$val]) {
2097
+					if (!$foundAddresses[$val]) {
2099 2098
 						$this->sessionData['to'][] = $val;
2100 2099
 						$foundAddresses[$val] = true;
2101 2100
 					}
@@ -2104,59 +2103,59 @@  discard block
 block discarded – undo
2104 2103
 		}
2105 2104
 
2106 2105
 		// check for Re: in subject header
2107
-		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2106
+		if (strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2108 2107
 			$this->sessionData['subject'] = $mail_bo->decode_header($headers['SUBJECT']);
2109 2108
 		} else {
2110
-			$this->sessionData['subject'] = "Re: " . $mail_bo->decode_header($headers['SUBJECT']);
2109
+			$this->sessionData['subject'] = "Re: ".$mail_bo->decode_header($headers['SUBJECT']);
2111 2110
 		}
2112 2111
 
2113 2112
 		//_debug_array($headers);
2114 2113
 		//error_log(__METHOD__.__LINE__.'->'.array2string($this->mailPreferences['htmlOptions']));
2115
-		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions']?$this->mailPreferences['htmlOptions']:''), $_partID);
2114
+		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions'] ? $this->mailPreferences['htmlOptions'] : ''), $_partID);
2116 2115
 		//_debug_array($bodyParts);
2117 2116
 		$styles = Mail::getStyles($bodyParts);
2118 2117
 
2119
-		$fromAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$headers['FROM']));
2118
+		$fromAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $headers['FROM']));
2120 2119
 
2121 2120
 		$toAddressA = array();
2122 2121
 		$toAddress = '';
2123 2122
 		foreach ($headers['TO'] as $mailheader) {
2124
-			$toAddressA[] =  $mailheader;
2123
+			$toAddressA[] = $mailheader;
2125 2124
 		}
2126
-		if (count($toAddressA)>0)
2125
+		if (count($toAddressA) > 0)
2127 2126
 		{
2128
-			$toAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$toAddressA));
2129
-			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2127
+			$toAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $toAddressA));
2128
+			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2130 2129
 		}
2131 2130
 		$ccAddressA = array();
2132 2131
 		$ccAddress = '';
2133 2132
 		foreach ($headers['CC'] as $mailheader) {
2134
-			$ccAddressA[] =  $mailheader;
2133
+			$ccAddressA[] = $mailheader;
2135 2134
 		}
2136
-		if (count($ccAddressA)>0)
2135
+		if (count($ccAddressA) > 0)
2137 2136
 		{
2138
-			$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA));
2139
-			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2137
+			$ccAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $ccAddressA));
2138
+			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2140 2139
 		}
2141
-		if($bodyParts['0']['mimeType'] == 'text/html') {
2142
-			$this->sessionData['body']	= /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2140
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
2141
+			$this->sessionData['body'] = /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2143 2142
 				@htmlspecialchars(lang("from")).": ".$fromAddress."<br>".
2144 2143
 				$toAddress.$ccAddress.
2145
-				@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>".
2144
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."<br>".
2146 2145
 				'----------------------------------------------------------'."</div>";
2147
-			$this->sessionData['mimeType'] 	= 'html';
2146
+			$this->sessionData['mimeType'] = 'html';
2148 2147
 			if (!empty($styles)) $this->sessionData['body'] .= $styles;
2149
-			$this->sessionData['body']	.= '<blockquote type="cite">';
2148
+			$this->sessionData['body'] .= '<blockquote type="cite">';
2150 2149
 
2151
-			for($i=0; $i<count($bodyParts); $i++) {
2152
-				if($i>0) {
2150
+			for ($i = 0; $i < count($bodyParts); $i++) {
2151
+				if ($i > 0) {
2153 2152
 					$this->sessionData['body'] .= '<hr>';
2154 2153
 				}
2155
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
2154
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
2156 2155
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>";
2157 2156
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
2158 2157
 				}
2159
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2158
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2160 2159
 
2161 2160
 				$_htmlConfig = Mail::$htmLawed_config;
2162 2161
 				Mail::$htmLawed_config['comment'] = 2;
@@ -2166,30 +2165,30 @@  discard block
 block discarded – undo
2166 2165
 				#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2167 2166
 			}
2168 2167
 
2169
-			$this->sessionData['body']	.= '</blockquote><br>';
2170
-			$this->sessionData['body'] =  mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2168
+			$this->sessionData['body'] .= '</blockquote><br>';
2169
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2171 2170
 		} else {
2172 2171
 			//$this->sessionData['body']	= @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n";
2173 2172
 			// take care the way the ReplyHeader is created here, is used later on in uicompose::compose, in case you force replys to be HTML (prefs)
2174
-            $this->sessionData['body']  = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2173
+            $this->sessionData['body'] = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2175 2174
                 @htmlspecialchars(lang("from")).": ".$fromAddress."\r\n".
2176 2175
 				$toAddress.$ccAddress.
2177
-				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
2176
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."\r\n".
2178 2177
                 '-------------------------------------------------'."\r\n \r\n ";
2179
-			$this->sessionData['mimeType']	= 'plain';
2178
+			$this->sessionData['mimeType'] = 'plain';
2180 2179
 
2181
-			for($i=0; $i<count($bodyParts); $i++) {
2182
-				if($i>0) {
2180
+			for ($i = 0; $i < count($bodyParts); $i++) {
2181
+				if ($i > 0) {
2183 2182
 					$this->sessionData['body'] .= "<hr>";
2184 2183
 				}
2185 2184
 
2186 2185
 				// add line breaks to $bodyParts
2187
-				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']);
2186
+				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
2188 2187
 				#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2189 2188
 				$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
2190 2189
 				$this->sessionData['body'] .= "\r\n";
2191 2190
 				// create body new, with good line breaks and indention
2192
-				foreach(explode("\n",$newBody) as $value) {
2191
+				foreach (explode("\n", $newBody) as $value) {
2193 2192
 					// the explode is removing the character
2194 2193
 					if (trim($value) != '') {
2195 2194
 						#if ($value != "\r") $value .= "\n";
@@ -2197,12 +2196,12 @@  discard block
 block discarded – undo
2197 2196
 					$numberOfChars = strspn(trim($value), ">");
2198 2197
 					$appendString = str_repeat('>', $numberOfChars + 1);
2199 2198
 
2200
-					$bodyAppend = $this->mail_bo->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
2199
+					$bodyAppend = $this->mail_bo->wordwrap($value, 76 - strlen("\r\n$appendString "), "\r\n$appendString ", '>');
2201 2200
 
2202
-					if($bodyAppend[0] == '>') {
2203
-						$bodyAppend = '>'. $bodyAppend;
2201
+					if ($bodyAppend[0] == '>') {
2202
+						$bodyAppend = '>'.$bodyAppend;
2204 2203
 					} else {
2205
-						$bodyAppend = '> '. $bodyAppend;
2204
+						$bodyAppend = '> '.$bodyAppend;
2206 2205
 					}
2207 2206
 
2208 2207
 					$this->sessionData['body'] .= $bodyAppend;
@@ -2225,16 +2224,16 @@  discard block
 block discarded – undo
2225 2224
 	 */
2226 2225
 	static function _getCleanHTML($_body, $_useTidy = false)
2227 2226
 	{
2228
-		static $nonDisplayAbleCharacters = array('[\016]','[\017]',
2229
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2230
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
2227
+		static $nonDisplayAbleCharacters = array('[\016]', '[\017]',
2228
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
2229
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2231 2230
 
2232
-		if ($_useTidy && extension_loaded('tidy') )
2231
+		if ($_useTidy && extension_loaded('tidy'))
2233 2232
 		{
2234 2233
 			$tidy = new tidy();
2235
-			$cleaned = $tidy->repairString($_body, Mail::$tidy_config,'utf8');
2234
+			$cleaned = $tidy->repairString($_body, Mail::$tidy_config, 'utf8');
2236 2235
 			// Found errors. Strip it all so there's some output
2237
-			if($tidy->getStatus() == 2)
2236
+			if ($tidy->getStatus() == 2)
2238 2237
 			{
2239 2238
 				error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
2240 2239
 			}
@@ -2268,13 +2267,13 @@  discard block
 block discarded – undo
2268 2267
 	 *
2269 2268
 	 * @return array returns found inline images as attachment structure
2270 2269
 	 */
2271
-	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving=false)
2270
+	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving = false)
2272 2271
 	{
2273 2272
 		if (substr($_formData['body'], 0, 27) == '-----BEGIN PGP MESSAGE-----')
2274 2273
 		{
2275 2274
 			$_formData['mimeType'] = 'openpgp';
2276 2275
 		}
2277
-		$mail_bo	= $this->mail_bo;
2276
+		$mail_bo = $this->mail_bo;
2278 2277
 		$activeMailProfile = Mail\Account::read($this->mail_bo->profileID);
2279 2278
 
2280 2279
 		// you need to set the sender, if you work with different identities, since most smtp servers, dont allow
@@ -2283,37 +2282,37 @@  discard block
 block discarded – undo
2283 2282
 		{
2284 2283
 			error_log(__METHOD__.__LINE__.' Faking From/SenderInfo for '.$activeMailProfile['ident_email'].' with ID:'.$activeMailProfile['ident_id'].'. Identitiy to use for sending:'.array2string($_identity));
2285 2284
 		}
2286
-		$email_From =  $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2285
+		$email_From = $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2287 2286
 		// Try to fix identity email with no domain part set
2288 2287
 		$_mailObject->setFrom(Mail::fixInvalidAliasAddress(Api\Accounts::id2name($_identity['account_id'], 'account_email'), $email_From),
2289
-			Mail::generateIdentityString($_identity,false));
2288
+			Mail::generateIdentityString($_identity, false));
2290 2289
 
2291 2290
 		$_mailObject->addHeader('X-Priority', $_formData['priority']);
2292 2291
 		$_mailObject->addHeader('X-Mailer', 'EGroupware-Mail');
2293
-		if(!empty($_formData['in-reply-to'])) {
2294
-			if (stripos($_formData['in-reply-to'],'<')===false) $_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2292
+		if (!empty($_formData['in-reply-to'])) {
2293
+			if (stripos($_formData['in-reply-to'], '<') === false) $_formData['in-reply-to'] = '<'.trim($_formData['in-reply-to']).'>';
2295 2294
 			$_mailObject->addHeader('In-Reply-To', $_formData['in-reply-to']);
2296 2295
 		}
2297
-		if(!empty($_formData['references'])) {
2298
-			if (stripos($_formData['references'],'<')===false)
2296
+		if (!empty($_formData['references'])) {
2297
+			if (stripos($_formData['references'], '<') === false)
2299 2298
 			{
2300
-				$_formData['references']='<'.trim($_formData['references']).'>';
2299
+				$_formData['references'] = '<'.trim($_formData['references']).'>';
2301 2300
 			}
2302 2301
 			$_mailObject->addHeader('References', $_formData['references']);
2303 2302
 		}
2304 2303
 
2305
-		if(!empty($_formData['thread-index'])) {
2304
+		if (!empty($_formData['thread-index'])) {
2306 2305
 			$_mailObject->addHeader('Thread-Index', $_formData['thread-index']);
2307 2306
 		}
2308
-		if(!empty($_formData['list-id'])) {
2307
+		if (!empty($_formData['list-id'])) {
2309 2308
 			$_mailObject->addHeader('List-Id', $_formData['list-id']);
2310 2309
 		}
2311
-		if($_formData['disposition']=='on') {
2310
+		if ($_formData['disposition'] == 'on') {
2312 2311
 			$_mailObject->addHeader('Disposition-Notification-To', $_identity['ident_email']);
2313 2312
 		}
2314 2313
 
2315 2314
 		// Expand any mailing lists
2316
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $field)
2315
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $field)
2317 2316
 		{
2318 2317
 			if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2319 2318
 
@@ -2329,7 +2328,7 @@  discard block
 block discarded – undo
2329 2328
 		}
2330 2329
 		$disableRuler = false;
2331 2330
 		$signature = $_identity['ident_signature'];
2332
-		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend'?1:0;
2331
+		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' ? 1 : 0;
2333 2332
 		if ($sigAlreadyThere)
2334 2333
 		{
2335 2334
 			// note: if you use stationery ' s the insert signatures at the top does not apply here anymore, as the signature
@@ -2338,7 +2337,7 @@  discard block
 block discarded – undo
2338 2337
 		}
2339 2338
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
2340 2339
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
2341
-			empty($signature) || trim($this->convertHTMLToText($signature)) =='')
2340
+			empty($signature) || trim($this->convertHTMLToText($signature)) == '')
2342 2341
 		{
2343 2342
 			$disableRuler = true;
2344 2343
 		}
@@ -2349,7 +2348,7 @@  discard block
 block discarded – undo
2349 2348
 				array_unique(array_merge((array)$_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc'])),
2350 2349
 				$_formData['expiration'], $_formData['password']);
2351 2350
 		}
2352
-		if($_formData['mimeType'] == 'html')
2351
+		if ($_formData['mimeType'] == 'html')
2353 2352
 		{
2354 2353
 			$body = $_formData['body'];
2355 2354
 			if ($attachment_links)
@@ -2363,13 +2362,13 @@  discard block
 block discarded – undo
2363 2362
 					$body .= $attachment_links;
2364 2363
 				}
2365 2364
 			}
2366
-			if(!empty($signature))
2365
+			if (!empty($signature))
2367 2366
 			{
2368 2367
 				$_mailObject->setBody($this->convertHTMLToText($body, true, true).
2369 2368
 					($disableRuler ? "\r\n" : "\r\n-- \r\n").
2370 2369
 					$this->convertHTMLToText($signature, true, true));
2371 2370
 
2372
-				$body .= ($disableRuler ?'<br>':'<hr style="border:1px dotted silver; width:90%;">').$signature;
2371
+				$body .= ($disableRuler ? '<br>' : '<hr style="border:1px dotted silver; width:90%;">').$signature;
2373 2372
 			}
2374 2373
 			else
2375 2374
 			{
@@ -2377,11 +2376,11 @@  discard block
 block discarded – undo
2377 2376
 			}
2378 2377
 			// convert URL Images to inline images - if possible
2379 2378
 			if (!$_autosaving) $inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2380
-			if (strpos($body,"<!-- HTMLSIGBEGIN -->")!==false)
2379
+			if (strpos($body, "<!-- HTMLSIGBEGIN -->") !== false)
2381 2380
 			{
2382
-				$body = str_replace(array('<!-- HTMLSIGBEGIN -->','<!-- HTMLSIGEND -->'),'',$body);
2381
+				$body = str_replace(array('<!-- HTMLSIGBEGIN -->', '<!-- HTMLSIGEND -->'), '', $body);
2383 2382
 			}
2384
-			$_mailObject->setHtmlBody($body, null, false);	// false = no automatic alternative, we called setBody()
2383
+			$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
2385 2384
 		}
2386 2385
 		elseif ($_formData['mimeType'] == 'openpgp')
2387 2386
 		{
@@ -2389,14 +2388,14 @@  discard block
 block discarded – undo
2389 2388
 		}
2390 2389
 		else
2391 2390
 		{
2392
-			$body = $this->convertHTMLToText($_formData['body'],false);
2391
+			$body = $this->convertHTMLToText($_formData['body'], false);
2393 2392
 
2394 2393
 			if ($attachment_links) $body .= $attachment_links;
2395 2394
 
2396 2395
 			#$_mailObject->Body = $_formData['body'];
2397
-			if(!empty($signature)) {
2398
-				$body .= ($disableRuler ?"\r\n":"\r\n-- \r\n").
2399
-					$this->convertHTMLToText($signature,true,true);
2396
+			if (!empty($signature)) {
2397
+				$body .= ($disableRuler ? "\r\n" : "\r\n-- \r\n").
2398
+					$this->convertHTMLToText($signature, true, true);
2400 2399
 			}
2401 2400
 			$_mailObject->setBody($body);
2402 2401
 		}
@@ -2405,8 +2404,8 @@  discard block
 block discarded – undo
2405 2404
 		{
2406 2405
 			$connection_opened = false;
2407 2406
 			$tnfattachments = null;
2408
-			foreach((array)$_formData['attachments'] as $attachment) {
2409
-				if(is_array($attachment))
2407
+			foreach ((array)$_formData['attachments'] as $attachment) {
2408
+				if (is_array($attachment))
2410 2409
 				{
2411 2410
 					if (!empty($attachment['uid']) && !empty($attachment['folder'])) {
2412 2411
 						/* Example:
@@ -2424,20 +2423,20 @@  discard block
 block discarded – undo
2424 2423
 							$connection_opened = true;
2425 2424
 						}
2426 2425
 						$mail_bo->reopen($attachment['folder']);
2427
-						switch(strtoupper($attachment['type'])) {
2426
+						switch (strtoupper($attachment['type'])) {
2428 2427
 							case 'MESSAGE/RFC':
2429 2428
 							case 'MESSAGE/RFC822':
2430
-								$rawBody='';
2429
+								$rawBody = '';
2431 2430
 								if (isset($attachment['partID'])) {
2432
-									$eml = $mail_bo->getAttachment($attachment['uid'],$attachment['partID'],0,false,true,$attachment['folder']);
2433
-									$rawBody=$eml['attachment'];
2431
+									$eml = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false, true, $attachment['folder']);
2432
+									$rawBody = $eml['attachment'];
2434 2433
 								} else {
2435
-									$rawBody        = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'],$attachment['folder']);
2434
+									$rawBody = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'], $attachment['folder']);
2436 2435
 								}
2437 2436
 								$_mailObject->addStringAttachment($rawBody, $attachment['name'], 'message/rfc822');
2438 2437
 								break;
2439 2438
 							default:
2440
-								$attachmentData	= $mail_bo->getAttachment($attachment['uid'], $attachment['partID'],0,false);
2439
+								$attachmentData = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false);
2441 2440
 								if ($attachmentData['type'] == 'APPLICATION/MS-TNEF')
2442 2441
 								{
2443 2442
 									if (!is_array($tnfattachments)) $tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
@@ -2445,7 +2444,7 @@  discard block
 block discarded – undo
2445 2444
 									{
2446 2445
 										if ($k['name'] == $attachment['name'])
2447 2446
 										{
2448
-											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'],$k['is_winmail']);
2447
+											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'], $k['is_winmail']);
2449 2448
 											$attachmentData['attachment'] = $tnfpart['attachment'];
2450 2449
 											break;
2451 2450
 										}
@@ -2458,7 +2457,7 @@  discard block
 block discarded – undo
2458 2457
 					// attach files not for autosaving
2459 2458
 					elseif ($_formData['filemode'] == Vfs\Sharing::ATTACH && !$_autosaving)
2460 2459
 					{
2461
-						if (isset($attachment['file']) && parse_url($attachment['file'],PHP_URL_SCHEME) == 'vfs')
2460
+						if (isset($attachment['file']) && parse_url($attachment['file'], PHP_URL_SCHEME) == 'vfs')
2462 2461
 						{
2463 2462
 							Vfs::load_wrapper('vfs');
2464 2463
 							$tmp_path = $attachment['file'];
@@ -2467,7 +2466,7 @@  discard block
 block discarded – undo
2467 2466
 						{
2468 2467
 							$tmp_path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['file']);
2469 2468
 						}
2470
-						$_mailObject->addAttachment (
2469
+						$_mailObject->addAttachment(
2471 2470
 							$tmp_path,
2472 2471
 							$attachment['name'],
2473 2472
 							$attachment['type']
@@ -2477,7 +2476,7 @@  discard block
 block discarded – undo
2477 2476
 			}
2478 2477
 			if ($connection_opened) $mail_bo->closeConnection();
2479 2478
 		}
2480
-		return is_array($inline_images)?$inline_images:array();
2479
+		return is_array($inline_images) ? $inline_images : array();
2481 2480
 	}
2482 2481
 
2483 2482
 	/**
@@ -2493,16 +2492,16 @@  discard block
 block discarded – undo
2493 2492
 	 * @param string $password =null
2494 2493
 	 * @return string might be empty if no file attachments found
2495 2494
 	 */
2496
-	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
2495
+	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients = array(), $expiration = null, $password = null)
2497 2496
 	{
2498 2497
 		if ($filemode == Vfs\Sharing::ATTACH) return '';
2499 2498
 
2500 2499
 		$links = array();
2501
-		foreach($attachments as $attachment)
2500
+		foreach ($attachments as $attachment)
2502 2501
 		{
2503 2502
 			$path = $attachment['file'];
2504
-			if (empty($path)) continue;	// we only care about file attachments, not forwarded messages or parts
2505
-			if (parse_url($attachment['file'],PHP_URL_SCHEME) != 'vfs')
2503
+			if (empty($path)) continue; // we only care about file attachments, not forwarded messages or parts
2504
+			if (parse_url($attachment['file'], PHP_URL_SCHEME) != 'vfs')
2506 2505
 			{
2507 2506
 				$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($path);
2508 2507
 			}
@@ -2532,7 +2531,7 @@  discard block
 block discarded – undo
2532 2531
 		}
2533 2532
 		if (!$links)
2534 2533
 		{
2535
-			return null;	// no file attachments found
2534
+			return null; // no file attachments found
2536 2535
 		}
2537 2536
 		elseif ($html)
2538 2537
 		{
@@ -2547,7 +2546,7 @@  discard block
 block discarded – undo
2547 2546
 	 * @param array $content content sent from client-side
2548 2547
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2549 2548
 	 */
2550
-	public function ajax_saveAsDraft ($content, $action='button[saveAsDraft]')
2549
+	public function ajax_saveAsDraft($content, $action = 'button[saveAsDraft]')
2551 2550
 	{
2552 2551
 		//error_log(__METHOD__.__LINE__.array2string($content)."(, action=$action)");
2553 2552
 		$response = Api\Json\Response::get();
@@ -2561,8 +2560,8 @@  discard block
 block discarded – undo
2561 2560
 
2562 2561
 		$formData = array_merge($content, array(
2563 2562
 			'isDrafted' => 1,
2564
-			'body' => $content['mail_'.($content['mimeType']?'htmltext':'plaintext')],
2565
-			'mimeType' => $content['mimeType']?'html':'plain' // checkbox has only true|false value
2563
+			'body' => $content['mail_'.($content['mimeType'] ? 'htmltext' : 'plaintext')],
2564
+			'mimeType' => $content['mimeType'] ? 'html' : 'plain' // checkbox has only true|false value
2566 2565
 		));
2567 2566
 
2568 2567
 		//Saving draft procedure
@@ -2574,8 +2573,8 @@  discard block
 block discarded – undo
2574 2573
 			if (($messageUid = $this->saveAsDraft($formData, $folder, $action)))
2575 2574
 			{
2576 2575
 				// saving as draft, does not mean closing the message
2577
-				$messageUid = ($messageUid===true ? $status['uidnext'] : $messageUid);
2578
-				if (is_array($this->mail_bo->getMessageHeader($messageUid, '',false, false, $folder)))
2576
+				$messageUid = ($messageUid === true ? $status['uidnext'] : $messageUid);
2577
+				if (is_array($this->mail_bo->getMessageHeader($messageUid, '', false, false, $folder)))
2579 2578
 				{
2580 2579
 					$draft_id = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $messageUid);
2581 2580
 					if ($content['lastDrafted'] != $draft_id && isset($content['lastDrafted']))
@@ -2584,7 +2583,7 @@  discard block
 block discarded – undo
2584 2583
 						$duid = $dhA['msgUID'];
2585 2584
 						$dmailbox = $dhA['folder'];
2586 2585
 						// beware: do not delete the original mail as found in processedmail_id
2587
-						$pMuid='';
2586
+						$pMuid = '';
2588 2587
 						if ($content['processedmail_id'])
2589 2588
 						{
2590 2589
 							$pMhA = mail_ui::splitRowID($content['processedmail_id']);
@@ -2592,15 +2591,15 @@  discard block
 block discarded – undo
2592 2591
 						}
2593 2592
 						//error_log(__METHOD__.__LINE__."#$pMuid#$pMuid!=$duid#".array2string($content['attachments']));
2594 2593
 						// do not delete the original message if attachments are present
2595
-						if (empty($pMuid) || $pMuid!=$duid || empty($content['attachments']))
2594
+						if (empty($pMuid) || $pMuid != $duid || empty($content['attachments']))
2596 2595
 						{
2597 2596
 							try
2598 2597
 							{
2599
-								$this->mail_bo->deleteMessages($duid,$dmailbox,'remove_immediately');
2598
+								$this->mail_bo->deleteMessages($duid, $dmailbox, 'remove_immediately');
2600 2599
 							}
2601 2600
 							catch (Api\Exception $e)
2602 2601
 							{
2603
-								$msg = str_replace('"',"'",$e->getMessage());
2602
+								$msg = str_replace('"', "'", $e->getMessage());
2604 2603
 								$success = false;
2605 2604
 								error_log(__METHOD__.__LINE__.$msg);
2606 2605
 							}
@@ -2621,7 +2620,7 @@  discard block
 block discarded – undo
2621 2620
 		}
2622 2621
 		catch (Api\Exception\WrongUserinput $e)
2623 2622
 		{
2624
-			$msg = str_replace('"',"'",$e->getMessage());
2623
+			$msg = str_replace('"', "'", $e->getMessage());
2625 2624
 			error_log(__METHOD__.__LINE__.$msg);
2626 2625
 			$success = false;
2627 2626
 		}
@@ -2645,17 +2644,17 @@  discard block
 block discarded – undo
2645 2644
 	static function resolveEmailAddressList($_emailAddressList)
2646 2645
 	{
2647 2646
 		$contacts_obs = null;
2648
-		$addrFromList=array();
2649
-		foreach((array)$_emailAddressList as $ak => $address)
2647
+		$addrFromList = array();
2648
+		foreach ((array)$_emailAddressList as $ak => $address)
2650 2649
 		{
2651
-			if(is_int($address))
2650
+			if (is_int($address))
2652 2651
 			{
2653 2652
 				if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts();
2654 2653
 				// List was selected, expand to addresses
2655 2654
 				unset($_emailAddressList[$ak]);
2656
-				$list = $contacts_obj->search('',array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'','','',False,'AND',false,array('list' =>(int)$address));
2655
+				$list = $contacts_obj->search('', array('n_fn', 'n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home'), '', '', '', False, 'AND', false, array('list' =>(int)$address));
2657 2656
 				// Just add email addresses, they'll be checked below
2658
-				foreach($list as $email)
2657
+				foreach ($list as $email)
2659 2658
 				{
2660 2659
 					$addrFromList[] = $email['email'] ? $email['email'] : $email['email_home'];
2661 2660
 				}
@@ -2665,7 +2664,7 @@  discard block
 block discarded – undo
2665 2664
 		{
2666 2665
 			foreach ($addrFromList as $addr)
2667 2666
 			{
2668
-				if (!empty($addr)) $_emailAddressList[]=$addr;
2667
+				if (!empty($addr)) $_emailAddressList[] = $addr;
2669 2668
 			}
2670 2669
 		}
2671 2670
 		return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList;
@@ -2679,15 +2678,15 @@  discard block
 block discarded – undo
2679 2678
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2680 2679
 	 * @return boolean return messageUID| false due to an error
2681 2680
 	 */
2682
-	function saveAsDraft($_formData, &$savingDestination='', $action='button[saveAsDraft]')
2681
+	function saveAsDraft($_formData, &$savingDestination = '', $action = 'button[saveAsDraft]')
2683 2682
 	{
2684 2683
 		//error_log(__METHOD__."(..., $savingDestination, action=$action)");
2685
-		$mail_bo	= $this->mail_bo;
2686
-		$mail		= new Api\Mailer($this->mail_bo->profileID);
2684
+		$mail_bo = $this->mail_bo;
2685
+		$mail = new Api\Mailer($this->mail_bo->profileID);
2687 2686
 
2688 2687
 		// preserve the bcc and if possible the save to folder information
2689
-		$this->sessionData['folder']    = $_formData['folder'];
2690
-		$this->sessionData['bcc']   = $_formData['bcc'];
2688
+		$this->sessionData['folder'] = $_formData['folder'];
2689
+		$this->sessionData['bcc'] = $_formData['bcc'];
2691 2690
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2692 2691
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2693 2692
 		$this->sessionData['mailaccount']  = $_formData['mailaccount'];
@@ -2696,11 +2695,11 @@  discard block
 block discarded – undo
2696 2695
 		{
2697 2696
 			$acc = Mail\Account::read($this->sessionData['mailaccount']);
2698 2697
 			//error_log(__METHOD__.__LINE__.array2string($acc));
2699
-			$identity = Mail\Account::read_identity($acc['ident_id'],true);
2698
+			$identity = Mail\Account::read_identity($acc['ident_id'], true);
2700 2699
 		}
2701 2700
 		catch (Exception $e)
2702 2701
 		{
2703
-			$identity=array();
2702
+			$identity = array();
2704 2703
 		}
2705 2704
 
2706 2705
 		$flags = '\\Seen \\Draft';
@@ -2710,7 +2709,7 @@  discard block
 block discarded – undo
2710 2709
 		// folder list as Customheader
2711 2710
 		if (!empty($this->sessionData['folder']))
2712 2711
 		{
2713
-			$folders = implode('|',array_unique($this->sessionData['folder']));
2712
+			$folders = implode('|', array_unique($this->sessionData['folder']));
2714 2713
 			$mail->addHeader('X-Mailfolder', $folders);
2715 2714
 		}
2716 2715
 		$mail->addHeader('X-Mailidentity', $this->sessionData['mailidentity']);
@@ -2730,25 +2729,25 @@  discard block
 block discarded – undo
2730 2729
 			$savingDestination = $this->sessionData['messageFolder'];
2731 2730
 			//error_log(__METHOD__.__LINE__.' SavingDestination:'.$savingDestination);
2732 2731
 		}
2733
-		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 ) $savingDestination = $mail_bo->getDraftFolder();
2732
+		if (!empty($_formData['printit']) && $_formData['printit'] == 0) $savingDestination = $mail_bo->getDraftFolder();
2734 2733
 
2735 2734
 		// normaly Bcc is only added to recipients, but not as header visible to all recipients
2736 2735
 		$mail->forceBccHeader();
2737 2736
 
2738 2737
 		$mail_bo->openConnection();
2739
-		if ($mail_bo->folderExists($savingDestination,true)) {
2738
+		if ($mail_bo->folderExists($savingDestination, true)) {
2740 2739
 			try
2741 2740
 			{
2742 2741
 				$messageUid = $mail_bo->appendMessage($savingDestination, $mail->getRaw(), null, $flags);
2743 2742
 			}
2744 2743
 			catch (Api\Exception\WrongUserinput $e)
2745 2744
 			{
2746
-				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",__METHOD__,$savingDestination,$e->getMessage()));
2745
+				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", __METHOD__, $savingDestination, $e->getMessage()));
2747 2746
 				return false;
2748 2747
 			}
2749 2748
 
2750 2749
 		} else {
2751
-			error_log(__METHOD__.__LINE__."->".lang("folder")." ". $savingDestination." ".lang("does not exist on IMAP Server."));
2750
+			error_log(__METHOD__.__LINE__."->".lang("folder")." ".$savingDestination." ".lang("does not exist on IMAP Server."));
2752 2751
 			return false;
2753 2752
 		}
2754 2753
 		$mail_bo->closeConnection();
@@ -2757,26 +2756,26 @@  discard block
 block discarded – undo
2757 2756
 
2758 2757
 	function send($_formData)
2759 2758
 	{
2760
-		$mail_bo	= $this->mail_bo;
2761
-		$mail 		= new Api\Mailer($mail_bo->profileID);
2762
-		$messageIsDraft	=  false;
2759
+		$mail_bo = $this->mail_bo;
2760
+		$mail = new Api\Mailer($mail_bo->profileID);
2761
+		$messageIsDraft = false;
2763 2762
 
2764
-		$this->sessionData['mailaccount']	= $_formData['mailaccount'];
2763
+		$this->sessionData['mailaccount'] = $_formData['mailaccount'];
2765 2764
 		$this->sessionData['to']	= self::resolveEmailAddressList($_formData['to']);
2766 2765
 		$this->sessionData['cc']	= self::resolveEmailAddressList($_formData['cc']);
2767
-		$this->sessionData['bcc']	= self::resolveEmailAddressList($_formData['bcc']);
2768
-		$this->sessionData['folder']	= $_formData['folder'];
2766
+		$this->sessionData['bcc'] = self::resolveEmailAddressList($_formData['bcc']);
2767
+		$this->sessionData['folder'] = $_formData['folder'];
2769 2768
 		$this->sessionData['replyto']	= $_formData['replyto'];
2770 2769
 		$this->sessionData['subject']	= trim($_formData['subject']);
2771
-		$this->sessionData['body']	= $_formData['body'];
2772
-		$this->sessionData['priority']	= $_formData['priority'];
2770
+		$this->sessionData['body'] = $_formData['body'];
2771
+		$this->sessionData['priority'] = $_formData['priority'];
2773 2772
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2774 2773
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2775 2774
 		$this->sessionData['disposition'] = $_formData['disposition'];
2776
-		$this->sessionData['mimeType']	= $_formData['mimeType'];
2775
+		$this->sessionData['mimeType'] = $_formData['mimeType'];
2777 2776
 		$this->sessionData['to_infolog'] = $_formData['to_infolog'];
2778 2777
 		$this->sessionData['to_tracker'] = $_formData['to_tracker'];
2779
-		$this->sessionData['attachments']  = $_formData['attachments'];
2778
+		$this->sessionData['attachments'] = $_formData['attachments'];
2780 2779
 
2781 2780
 		if (isset($_formData['lastDrafted']) && !empty($_formData['lastDrafted']))
2782 2781
 		{
@@ -2785,11 +2784,11 @@  discard block
 block discarded – undo
2785 2784
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_formData['mode'].' PID:'.$_formData['processedmail_id']);
2786 2785
 		if (isset($_formData['mode']) && !empty($_formData['mode']))
2787 2786
 		{
2788
-			if ($_formData['mode']=='forward' && !empty($_formData['processedmail_id']))
2787
+			if ($_formData['mode'] == 'forward' && !empty($_formData['processedmail_id']))
2789 2788
 			{
2790
-				$this->sessionData['forwardFlag']='forwarded';
2791
-				$_formData['processedmail_id'] = explode(',',$_formData['processedmail_id']);
2792
-				$this->sessionData['uid']=array();
2789
+				$this->sessionData['forwardFlag'] = 'forwarded';
2790
+				$_formData['processedmail_id'] = explode(',', $_formData['processedmail_id']);
2791
+				$this->sessionData['uid'] = array();
2793 2792
 				foreach ($_formData['processedmail_id'] as $k =>$rowid)
2794 2793
 				{
2795 2794
 					$fhA = mail_ui::splitRowID($rowid);
@@ -2798,13 +2797,13 @@  discard block
 block discarded – undo
2798 2797
 					if (!empty($fhA['folder'])) $this->sessionData['sourceFolder'] = $fhA['folder'];
2799 2798
 				}
2800 2799
 			}
2801
-			if ($_formData['mode']=='reply' && !empty($_formData['processedmail_id']))
2800
+			if ($_formData['mode'] == 'reply' && !empty($_formData['processedmail_id']))
2802 2801
 			{
2803 2802
 				$rhA = mail_ui::splitRowID($_formData['processedmail_id']);
2804 2803
 				$this->sessionData['uid'] = $rhA['msgUID'];
2805 2804
 				$this->sessionData['messageFolder'] = $rhA['folder'];
2806 2805
 			}
2807
-			if ($_formData['mode']=='composefromdraft' && !empty($_formData['processedmail_id']))
2806
+			if ($_formData['mode'] == 'composefromdraft' && !empty($_formData['processedmail_id']))
2808 2807
 			{
2809 2808
 				$dhA = mail_ui::splitRowID($_formData['processedmail_id']);
2810 2809
 				$this->sessionData['uid'] = $dhA['msgUID'];
@@ -2813,26 +2812,26 @@  discard block
 block discarded – undo
2813 2812
 		}
2814 2813
 		// if the body is empty, maybe someone pasted something with scripts, into the message body
2815 2814
 		// this should not happen anymore, unless you call send directly, since the check was introduced with the action command
2816
-		if(empty($this->sessionData['body']))
2815
+		if (empty($this->sessionData['body']))
2817 2816
 		{
2818 2817
 			// this is to be found with the egw_unset_vars array for the _POST['body'] array
2819
-			$name='_POST';
2820
-			$key='body';
2818
+			$name = '_POST';
2819
+			$key = 'body';
2821 2820
 			#error_log($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2822 2821
 			if (isset($GLOBALS['egw_unset_vars'][$name.'['.$key.']']))
2823 2822
 			{
2824
-				$this->sessionData['body'] = self::_getCleanHTML( $GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2825
-				$_formData['body']=$this->sessionData['body'];
2823
+				$this->sessionData['body'] = self::_getCleanHTML($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2824
+				$_formData['body'] = $this->sessionData['body'];
2826 2825
 			}
2827 2826
 			#error_log($this->sessionData['body']);
2828 2827
 		}
2829
-		if(empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2828
+		if (empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2830 2829
 		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder'])) {
2831 2830
 		   	$messageIsDraft = true;
2832 2831
 		}
2833 2832
 		try
2834 2833
 		{
2835
-			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'],true);
2834
+			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'], true);
2836 2835
 		}
2837 2836
 		catch (Exception $e)
2838 2837
 		{
@@ -2843,7 +2842,7 @@  discard block
 block discarded – undo
2843 2842
 		// create the messages and store inline images
2844 2843
 		$inline_images = $this->createMessage($mail, $_formData, $identity);
2845 2844
 		// remember the identity
2846
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2845
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From; //$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2847 2846
 		#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
2848 2847
 		#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";
2849 2848
 		#exit;
@@ -2854,12 +2853,12 @@  discard block
 block discarded – undo
2854 2853
 		$folderOnMailAccount = array();
2855 2854
 		foreach ($folderToCheck as $k => $f)
2856 2855
 		{
2857
-			$fval=$f;
2858
-			$icServerID = $_formData['serverID'];//folders always assumed with serverID
2859
-			if (stripos($f,'::')!==false) list($icServerID,$fval) = explode('::',$f,2);
2860
-			if ($_formData['serverID']!=$_formData['mailaccount'])
2856
+			$fval = $f;
2857
+			$icServerID = $_formData['serverID']; //folders always assumed with serverID
2858
+			if (stripos($f, '::') !== false) list($icServerID, $fval) = explode('::', $f, 2);
2859
+			if ($_formData['serverID'] != $_formData['mailaccount'])
2861 2860
 			{
2862
-				if ($icServerID == $_formData['serverID'] )
2861
+				if ($icServerID == $_formData['serverID'])
2863 2862
 				{
2864 2863
 					$folder[$fval] = $fval;
2865 2864
 					$folderOnServerID[] = $fval;
@@ -2872,7 +2871,7 @@  discard block
 block discarded – undo
2872 2871
 			}
2873 2872
 			else
2874 2873
 			{
2875
-				if ($icServerID == $_formData['serverID'] )
2874
+				if ($icServerID == $_formData['serverID'])
2876 2875
 				{
2877 2876
 					$folder[$fval] = $fval;
2878 2877
 					$folderOnServerID[] = $fval;
@@ -2889,7 +2888,7 @@  discard block
 block discarded – undo
2889 2888
 		// we use the sentFolder settings of the choosen mailaccount
2890 2889
 		// sentFolder is account specific
2891 2890
 		$changeProfileOnSentFolderNeeded = false;
2892
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2891
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2893 2892
 		{
2894 2893
 			$this->changeProfile($_formData['mailaccount']);
2895 2894
 			//error_log(__METHOD__.__LINE__.'#'.$this->mail_bo->profileID.'<->'.$mail_bo->profileID.'#');
@@ -2897,30 +2896,30 @@  discard block
 block discarded – undo
2897 2896
 			// sentFolder is account specific
2898 2897
 			$sentFolder = $this->mail_bo->getSentFolder();
2899 2898
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2900
-			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2899
+			if ($sentFolder && $sentFolder != 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2901 2900
 		}
2902 2901
 		else
2903 2902
 		{
2904 2903
 			$sentFolder = $mail_bo->getSentFolder();
2905 2904
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2906
-			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2905
+			if ($sentFolder && $sentFolder != 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2907 2906
 		}
2908 2907
 		//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2909 2908
 
2910 2909
 		// we switch $this->mail_bo back to the account we used to work on
2911
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2910
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2912 2911
 		{
2913 2912
 			$this->changeProfile($_formData['serverID']);
2914 2913
 		}
2915 2914
 
2916 2915
 
2917
-		if(isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2916
+		if (isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2918 2917
 			$this->mailPreferences['sendOptions'] != 'send_only' &&
2919 2918
 			$messageIsDraft == false)
2920 2919
 		{
2921 2920
 			if ($sentFolder)
2922 2921
 			{
2923
-				if ($_formData['serverID']!=$_formData['mailaccount'])
2922
+				if ($_formData['serverID'] != $_formData['mailaccount'])
2924 2923
 				{
2925 2924
 					$folderOnMailAccount[] = $sentFolder;
2926 2925
 				}
@@ -2937,14 +2936,14 @@  discard block
 block discarded – undo
2937 2936
 		}
2938 2937
 		else
2939 2938
 		{
2940
-			if (((!isset($sentFolder)||$sentFolder==false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2939
+			if (((!isset($sentFolder) || $sentFolder == false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2941 2940
 				($this->mailPreferences['sendOptions'] != 'send_only' &&
2942 2941
 				$sentFolder != 'none')) $this->errorInfo = lang("No Send Folder set in preferences");
2943 2942
 		}
2944 2943
 		// draftFolder is on Server we start from
2945
-		if($messageIsDraft == true) {
2944
+		if ($messageIsDraft == true) {
2946 2945
 			$draftFolder = $mail_bo->getDraftFolder();
2947
-			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true)) {
2946
+			if (!empty($draftFolder) && $mail_bo->folderExists($draftFolder, true)) {
2948 2947
 				$this->sessionData['folder'] = array($draftFolder);
2949 2948
 				$folderOnServerID[] = $draftFolder;
2950 2949
 				$folder[$draftFolder] = $draftFolder;
@@ -2953,10 +2952,10 @@  discard block
 block discarded – undo
2953 2952
 		if ($folderOnServerID) $folderOnServerID = array_unique($folderOnServerID);
2954 2953
 		if ($folderOnMailAccount) $folderOnMailAccount = array_unique($folderOnMailAccount);
2955 2954
 		if (($this->mailPreferences['sendOptions'] != 'send_only' && $sentFolder != 'none') &&
2956
-			!( count($folder) > 0) &&
2957
-			!($_formData['to_infolog']=='on' || $_formData['to_tracker']=='on'))
2955
+			!(count($folder) > 0) &&
2956
+			!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on'))
2958 2957
 		{
2959
-			$this->errorInfo = lang("Error: ").lang("No Folder destination supplied, and no folder to save message or other measure to store the mail (save to infolog/tracker) provided, but required.").($this->errorInfo?' '.$this->errorInfo:'');
2958
+			$this->errorInfo = lang("Error: ").lang("No Folder destination supplied, and no folder to save message or other measure to store the mail (save to infolog/tracker) provided, but required.").($this->errorInfo ? ' '.$this->errorInfo : '');
2960 2959
 			#error_log($this->errorInfo);
2961 2960
 			return false;
2962 2961
 		}
@@ -2965,18 +2964,18 @@  discard block
 block discarded – undo
2965 2964
 		@set_time_limit(120);
2966 2965
 		//$mail->SMTPDebug = 10;
2967 2966
 		//error_log("Folder:".count(array($this->sessionData['folder']))."To:".count((array)$this->sessionData['to'])."CC:". count((array)$this->sessionData['cc']) ."bcc:".count((array)$this->sessionData['bcc']));
2968
-		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2967
+		if (count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2969 2968
 			try {
2970 2969
 				$mail->send();
2971 2970
 			}
2972
-			catch(Exception $e) {
2971
+			catch (Exception $e) {
2973 2972
 				_egw_log_exception($e);
2974 2973
 				//if( $e->details ) error_log(__METHOD__.__LINE__.array2string($e->details));
2975
-				$this->errorInfo = $e->getMessage().($e->details?'<br/>'.$e->details:'');
2974
+				$this->errorInfo = $e->getMessage().($e->details ? '<br/>'.$e->details : '');
2976 2975
 				return false;
2977 2976
 			}
2978 2977
 		} else {
2979
-			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder'])) {
2978
+			if (count(array($this->sessionData['folder'])) > 0 && !empty($this->sessionData['folder'])) {
2980 2979
 				//error_log(__METHOD__.__LINE__."Folders:".print_r($this->sessionData['folder'],true));
2981 2980
 			} else {
2982 2981
 				$this->errorInfo = lang("Error: ").lang("No Address TO/CC/BCC supplied, and no folder to save message to provided.");
@@ -3004,15 +3003,15 @@  discard block
 block discarded – undo
3004 3003
 		// copying mail to folder
3005 3004
 		if (count($folder) > 0)
3006 3005
 		{
3007
-			foreach($folderOnServerID as $folderName) {
3006
+			foreach ($folderOnServerID as $folderName) {
3008 3007
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3009 3008
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3010 3009
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3011 3010
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3012
-				if ($mail_bo->folderExists($folderName,true)) {
3013
-					if($mail_bo->isSentFolder($folderName)) {
3011
+				if ($mail_bo->folderExists($folderName, true)) {
3012
+					if ($mail_bo->isSentFolder($folderName)) {
3014 3013
 						$flags = '\\Seen';
3015
-					} elseif($mail_bo->isDraftFolder($folderName)) {
3014
+					} elseif ($mail_bo->isDraftFolder($folderName)) {
3016 3015
 						$flags = '\\Draft';
3017 3016
 					} else {
3018 3017
 						$flags = '\\Seen';
@@ -3028,25 +3027,25 @@  discard block
 block discarded – undo
3028 3027
 					}
3029 3028
 					catch (Api\Exception\WrongUserinput $e)
3030 3029
 					{
3031
-						error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$this->sessionData['subject'],$folderName,$e->getMessage()));
3030
+						error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $this->sessionData['subject'], $folderName, $e->getMessage()));
3032 3031
 					}
3033 3032
 				}
3034 3033
 				else
3035 3034
 				{
3036
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3035
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3037 3036
 				}
3038 3037
 			}
3039 3038
 			// if we choose to send from a differing profile
3040 3039
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['mailaccount']);
3041
-			foreach($folderOnMailAccount as $folderName) {
3040
+			foreach ($folderOnMailAccount as $folderName) {
3042 3041
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3043 3042
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3044 3043
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3045 3044
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3046
-				if ($this->mail_bo->folderExists($folderName,true)) {
3047
-					if($this->mail_bo->isSentFolder($folderName)) {
3045
+				if ($this->mail_bo->folderExists($folderName, true)) {
3046
+					if ($this->mail_bo->isSentFolder($folderName)) {
3048 3047
 						$flags = '\\Seen';
3049
-					} elseif($this->mail_bo->isDraftFolder($folderName)) {
3048
+					} elseif ($this->mail_bo->isDraftFolder($folderName)) {
3050 3049
 						$flags = '\\Draft';
3051 3050
 					} else {
3052 3051
 						$flags = '\\Seen';
@@ -3062,12 +3061,12 @@  discard block
 block discarded – undo
3062 3061
 					}
3063 3062
 					catch (Api\Exception\WrongUserinput $e)
3064 3063
 					{
3065
-						error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$this->sessionData['subject'],$folderName,$e->getMessage()));
3064
+						error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $this->sessionData['subject'], $folderName, $e->getMessage()));
3066 3065
 					}
3067 3066
 				}
3068 3067
 				else
3069 3068
 				{
3070
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3069
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3071 3070
 				}
3072 3071
 			}
3073 3072
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['serverID']);
@@ -3078,27 +3077,27 @@  discard block
 block discarded – undo
3078 3077
 		$lastDrafted = false;
3079 3078
 		if (isset($this->sessionData['lastDrafted']))
3080 3079
 		{
3081
-			$lastDrafted=array();
3080
+			$lastDrafted = array();
3082 3081
 			$dhA = mail_ui::splitRowID($this->sessionData['lastDrafted']);
3083 3082
 			$lastDrafted['uid'] = $dhA['msgUID'];
3084 3083
 			$lastDrafted['folder'] = $dhA['folder'];
3085
-			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
3084
+			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
3086 3085
 			// manually drafted, do not delete
3087 3086
 			// will be handled later on IF mode was $_formData['mode']=='composefromdraft'
3088
-			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
3087
+			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted = false;
3089 3088
 			//error_log(__METHOD__.__LINE__.array2string($lastDrafted));
3090 3089
 		}
3091 3090
 		if ($lastDrafted && is_array($lastDrafted) && $mail_bo->isDraftFolder($lastDrafted['folder']))
3092 3091
 		{
3093 3092
 			try
3094 3093
 			{
3095
-				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode']=='composefromdraft' &&
3096
-					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )&&$this->sessionData['attachments']))
3094
+				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode'] == 'composefromdraft' &&
3095
+					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3097 3096
 				{
3098 3097
 					//error_log(__METHOD__.__LINE__."#".$lastDrafted['uid'].'#'.$lastDrafted['folder'].array2string($_formData));
3099 3098
 					//error_log(__METHOD__.__LINE__."#".array2string($_formData));
3100 3099
 					//error_log(__METHOD__.__LINE__."#".array2string($this->sessionData));
3101
-					$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
3100
+					$mail_bo->deleteMessages($lastDrafted['uid'], $lastDrafted['folder'], 'remove_immediately');
3102 3101
 				}
3103 3102
 			}
3104 3103
 			catch (Api\Exception $e)
@@ -3110,22 +3109,22 @@  discard block
 block discarded – undo
3110 3109
 		unset($this->sessionData['lastDrafted']);
3111 3110
 
3112 3111
 		//error_log("handling draft messages, flagging and such");
3113
-		if((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3112
+		if ((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3114 3113
 			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3115 3114
 			// mark message as answered
3116 3115
 			$mail_bo->openConnection();
3117
-			$mail_bo->reopen(($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3116
+			$mail_bo->reopen(($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3118 3117
 			// if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send
3119 3118
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
3120 3119
 			if ($mail_bo->isDraftFolder($this->sessionData['messageFolder']) && !$mail_bo->isTemplateFolder($this->sessionData['messageFolder']))
3121 3120
 			{
3122 3121
 				try // message may be deleted already, as it maybe done by autosave
3123 3122
 				{
3124
-					if ($_formData['mode']=='composefromdraft' &&
3123
+					if ($_formData['mode'] == 'composefromdraft' &&
3125 3124
 						!(($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3126 3125
 					{
3127 3126
 						//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
3128
-						$mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder']);
3127
+						$mail_bo->deleteMessages(array($this->sessionData['uid']), $this->sessionData['messageFolder']);
3129 3128
 					}
3130 3129
 				}
3131 3130
 				catch (Api\Exception $e)
@@ -3134,14 +3133,14 @@  discard block
 block discarded – undo
3134 3133
 					unset($e);
3135 3134
 				}
3136 3135
 			} else {
3137
-				$mail_bo->flagMessages("answered", $this->sessionData['uid'],($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3136
+				$mail_bo->flagMessages("answered", $this->sessionData['uid'], ($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3138 3137
 				//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)).':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3139
-				if (array_key_exists('forwardFlag',$this->sessionData) && $this->sessionData['forwardFlag']=='forwarded')
3138
+				if (array_key_exists('forwardFlag', $this->sessionData) && $this->sessionData['forwardFlag'] == 'forwarded')
3140 3139
 				{
3141 3140
 					try
3142 3141
 					{
3143 3142
 						//error_log(__METHOD__.__LINE__.':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3144
-						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'],$this->sessionData['sourceFolder']);
3143
+						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'], $this->sessionData['sourceFolder']);
3145 3144
 					}
3146 3145
 					catch (Api\Exception $e)
3147 3146
 					{
@@ -3169,49 +3168,49 @@  discard block
 block discarded – undo
3169 3168
 		if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc'];
3170 3169
 		if (!empty($mailaddresses)) $mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3171 3170
 
3172
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )
3171
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on')
3173 3172
 		{
3174 3173
 			$this->sessionData['attachments'] = array_merge((array)$this->sessionData['attachments'], (array)$inline_images);
3175 3174
 
3176
-			foreach(array('to_infolog','to_tracker','to_calendar') as $app_key)
3175
+			foreach (array('to_infolog', 'to_tracker', 'to_calendar') as $app_key)
3177 3176
 			{
3178 3177
 				$entryid = $_formData['to_integrate_ids'][0][$app_key];
3179 3178
 				if ($_formData[$app_key] == 'on')
3180 3179
 				{
3181
-					$app_name = substr($app_key,3);
3180
+					$app_name = substr($app_key, 3);
3182 3181
 					// Get registered hook data of the app called for integration
3183
-					$hook = Api\Hooks::single(array('location'=> 'mail_import'),$app_name);
3182
+					$hook = Api\Hooks::single(array('location'=> 'mail_import'), $app_name);
3184 3183
 
3185 3184
 					// store mail / eml in temp. file to not have to download it from mail-server again
3186
-					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'mail_integrate');
3185
+					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'mail_integrate');
3187 3186
 					$eml_fp = fopen($eml, 'w');
3188 3187
 					stream_copy_to_stream($mail->getRaw(), $eml_fp);
3189 3188
 					fclose($eml_fp);
3190 3189
 					$target = array(
3191 3190
 						'menuaction' => $hook['menuaction'],
3192
-						'egw_data' => Link::set_data(null,'mail_integration::integrate',array(
3191
+						'egw_data' => Link::set_data(null, 'mail_integration::integrate', array(
3193 3192
 							$mailaddresses,
3194 3193
 							$this->sessionData['subject'],
3195 3194
 							$this->convertHTMLToText($this->sessionData['body']),
3196 3195
 							$this->sessionData['attachments'],
3197 3196
 							false, // date
3198 3197
 							$eml,
3199
-							$_formData['serverID']),true),
3198
+							$_formData['serverID']), true),
3200 3199
 						'app' => $app_name
3201 3200
 					);
3202 3201
 					if ($entryid) $target['entry_id'] = $entryid;
3203 3202
 					// Open the app called for integration in a popup
3204 3203
 					// and store the mail raw data as egw_data, in order to
3205 3204
 					// be stored from registered app method later
3206
-					Framework::popup(Egw::link('/index.php', $target),'_blank',$hook['popup']);
3205
+					Framework::popup(Egw::link('/index.php', $target), '_blank', $hook['popup']);
3207 3206
 				}
3208 3207
 			}
3209 3208
 		}
3210 3209
 		// only clean up temp-files, if we dont need them for mail_integration::integrate
3211
-		elseif(is_array($this->sessionData['attachments']))
3210
+		elseif (is_array($this->sessionData['attachments']))
3212 3211
 		{
3213
-			foreach($this->sessionData['attachments'] as $value) {
3214
-				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3212
+			foreach ($this->sessionData['attachments'] as $value) {
3213
+				if (!empty($value['file']) && parse_url($value['file'], PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3215 3214
 					unlink($GLOBALS['egw_info']['server']['temp_dir'].'/'.$value['file']);
3216 3215
 				}
3217 3216
 			}
@@ -3228,7 +3227,7 @@  discard block
 block discarded – undo
3228 3227
 	 * @param array $content
3229 3228
 	 * @return array - the input, enriched with some not set attributes
3230 3229
 	 */
3231
-	function setDefaults($content=array())
3230
+	function setDefaults($content = array())
3232 3231
 	{
3233 3232
 		// if there's not already an identity selected for current account
3234 3233
 		if (empty($content['mailidentity']))
@@ -3237,7 +3236,7 @@  discard block
 block discarded – undo
3237 3236
 			if (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed']))
3238 3237
 			{
3239 3238
 				$sigPref = $GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed'];
3240
-				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID]>0)
3239
+				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID] > 0)
3241 3240
 				{
3242 3241
 					$content['mailidentity'] = $sigPref[$this->mail_bo->profileID];
3243 3242
 				}
@@ -3246,7 +3245,7 @@  discard block
 block discarded – undo
3246 3245
 			if (empty($content['mailidentity']))
3247 3246
 			{
3248 3247
 				$default_identity = null;
3249
-				foreach(Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3248
+				foreach (Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3250 3249
 				{
3251 3250
 					if (!isset($default_identity)) $default_identity = $identity['ident_id'];
3252 3251
 					if (!empty($identity['ident_signature']))
@@ -3261,7 +3260,7 @@  discard block
 block discarded – undo
3261 3260
 		if (!isset($content['mimeType']) || empty($content['mimeType']))
3262 3261
 		{
3263 3262
 			$content['mimeType'] = 'html';
3264
-			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text") $content['mimeType']  = 'plain';
3263
+			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions'] == "text") $content['mimeType'] = 'plain';
3265 3264
 		}
3266 3265
 		return $content;
3267 3266
 
@@ -3284,7 +3283,7 @@  discard block
 block discarded – undo
3284 3283
 	 * @param boolean $_noPrefixId = false, if set to true folders name does not get prefixed by account id
3285 3284
 	 * @return type
3286 3285
 	 */
3287
-	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false) {
3286
+	function ajax_searchFolder($_searchStringLength = 2, $_returnList = false, $_mailaccountToSearch = null, $_noPrefixId = false) {
3288 3287
 		//error_log(__METHOD__.__LINE__.':'.array2string($_REQUEST));
3289 3288
 		static $useCacheIfPossible = null;
3290 3289
 		if (is_null($useCacheIfPossible)) $useCacheIfPossible = true;
@@ -3297,36 +3296,36 @@  discard block
 block discarded – undo
3297 3296
 		{
3298 3297
 			$this->changeProfile($_mailaccountToSearch);
3299 3298
 		}
3300
-		if (strlen($_searchString)>=$_searchStringLength && isset($this->mail_bo->icServer))
3299
+		if (strlen($_searchString) >= $_searchStringLength && isset($this->mail_bo->icServer))
3301 3300
 		{
3302 3301
 			//error_log(__METHOD__.__LINE__.':'.$this->mail_bo->icServer->ImapServerId);
3303 3302
 			$this->mail_bo->openConnection($this->mail_bo->icServer->ImapServerId);
3304 3303
 			//error_log(__METHOD__.__LINE__.array2string($_searchString).'<->'.$searchString);
3305
-			$folderObjects = $this->mail_bo->getFolderObjects(true,false,true,$useCacheIfPossible);
3306
-			if (count($folderObjects)<=1) {
3304
+			$folderObjects = $this->mail_bo->getFolderObjects(true, false, true, $useCacheIfPossible);
3305
+			if (count($folderObjects) <= 1) {
3307 3306
 				$useCacheIfPossible = false;
3308 3307
 			}
3309 3308
 			else
3310 3309
 			{
3311 3310
 				$useCacheIfPossible = true;
3312 3311
 			}
3313
-			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset,'UTF7-IMAP');
3312
+			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset, 'UTF7-IMAP');
3314 3313
 			foreach ($folderObjects as $k =>$fA)
3315 3314
 			{
3316 3315
 				//error_log(__METHOD__.__LINE__.$_searchString.'/'.$searchString.' in '.$k.'->'.$fA->displayName);
3317
-				$f=false;
3318
-				$key = $_noPrefixId?$k:$_mailaccountToSearch.'::'.$k;
3319
-				if ($_searchStringLength<=0)
3316
+				$f = false;
3317
+				$key = $_noPrefixId ? $k : $_mailaccountToSearch.'::'.$k;
3318
+				if ($_searchStringLength <= 0)
3320 3319
 				{
3321
-					$f=true;
3320
+					$f = true;
3322 3321
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3323 3322
 				}
3324
-				if ($f==false && stripos($fA->displayName,$_searchString)!==false)
3323
+				if ($f == false && stripos($fA->displayName, $_searchString) !== false)
3325 3324
 				{
3326
-					$f=true;
3325
+					$f = true;
3327 3326
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3328 3327
 				}
3329
-				if ($f==false && stripos($k,$searchString)!==false)
3328
+				if ($f == false && stripos($k, $searchString) !== false)
3330 3329
 				{
3331 3330
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3332 3331
 				}
@@ -3354,7 +3353,7 @@  discard block
 block discarded – undo
3354 3353
 		exit();
3355 3354
 	}
3356 3355
 
3357
-	public static function ajax_searchAddress($_searchStringLength=2) {
3356
+	public static function ajax_searchAddress($_searchStringLength = 2) {
3358 3357
 		//error_log(__METHOD__. "request from seachAddress " . $_REQUEST['query']);
3359 3358
 		$_searchString = trim($_REQUEST['query']);
3360 3359
 		$include_lists = (boolean)$_REQUEST['include_lists'];
@@ -3363,7 +3362,7 @@  discard block
 block discarded – undo
3363 3362
 		$results = array();
3364 3363
 
3365 3364
 		// Add up to 5 matching mailing lists
3366
-		if($include_lists)
3365
+		if ($include_lists)
3367 3366
 		{
3368 3367
 			$lists = array_filter(
3369 3368
 				$contacts_obj->get_lists(Acl::READ),
@@ -3372,7 +3371,7 @@  discard block
 block discarded – undo
3372 3371
 				}
3373 3372
 			);
3374 3373
 			$list_count = 0;
3375
-			foreach($lists as $key => $list_name)
3374
+			foreach ($lists as $key => $list_name)
3376 3375
 			{
3377 3376
 				$results[] = array(
3378 3377
 					'id'	=> $key,
@@ -3382,11 +3381,11 @@  discard block
 block discarded – undo
3382 3381
 					'title' => lang('Mailinglist'),
3383 3382
 					'data'	=> $key
3384 3383
 				);
3385
-				if($list_count++ > 5) break;
3384
+				if ($list_count++ > 5) break;
3386 3385
 			}
3387 3386
 		}
3388 3387
 
3389
-		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
3388
+		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString) >= $_searchStringLength)
3390 3389
 		{
3391 3390
 			//error_log(__METHOD__.__LINE__.array2string($_searchString));
3392 3391
 			$showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']);
@@ -3395,64 +3394,64 @@  discard block
 block discarded – undo
3395 3394
 			{
3396 3395
 				if (mb_strlen($v) < 3) unset($search[$k]);
3397 3396
 			}
3398
-			$search_str = implode(' +', $search);	// tell contacts/so_sql to AND search patterns
3397
+			$search_str = implode(' +', $search); // tell contacts/so_sql to AND search patterns
3399 3398
 			//error_log(__METHOD__.__LINE__.$_searchString);
3400 3399
 			$filter = $showAccounts ? array() : array('account_id' => null);
3401
-			$filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home');
3402
-			$cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home');
3403
-			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter);
3400
+			$filter['cols_to_search'] = array('n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3401
+			$cols = array('n_fn', 'n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3402
+			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3404 3403
 			// additionally search the accounts, if the contact storage is not the account storage
3405 3404
 			if ($showAccounts && $contacts_obj->so_accounts)
3406 3405
 			{
3407 3406
 				$filter['owner'] = 0;
3408
-				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false,'OR', array(0,100), $filter);
3407
+				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3409 3408
 
3410 3409
 				if ($contacts && $accounts)
3411 3410
 				{
3412
-					$contacts = array_merge($contacts,$accounts);
3413
-					usort($contacts,function($a, $b)
3411
+					$contacts = array_merge($contacts, $accounts);
3412
+					usort($contacts, function($a, $b)
3414 3413
 					{
3415 3414
 						return strcasecmp($a['n_fn'], $b['n_fn']);
3416 3415
 					});
3417 3416
 				}
3418
-				elseif($accounts)
3417
+				elseif ($accounts)
3419 3418
 				{
3420
-					$contacts =& $accounts;
3419
+					$contacts = & $accounts;
3421 3420
 				}
3422 3421
 				unset($accounts);
3423 3422
 			}
3424 3423
 		}
3425 3424
 		
3426
-		if(is_array($contacts)) {
3427
-			foreach($contacts as $contact) {
3428
-				foreach(array($contact['email'],$contact['email_home']) as $email) {
3425
+		if (is_array($contacts)) {
3426
+			foreach ($contacts as $contact) {
3427
+				foreach (array($contact['email'], $contact['email_home']) as $email) {
3429 3428
 					// avoid wrong addresses, if an rfc822 encoded address is in addressbook
3430 3429
 					//$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
3431 3430
 					$rfcAddr = Mail::parseAddressList($email);
3432
-					$_rfcAddr=$rfcAddr->first();
3431
+					$_rfcAddr = $rfcAddr->first();
3433 3432
 					if (!$_rfcAddr->valid)
3434 3433
 					{
3435 3434
 						continue; // skip address if we encounter an error here
3436 3435
 					}
3437 3436
 					$email = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
3438 3437
 
3439
-					if (method_exists($contacts_obj,'search'))
3438
+					if (method_exists($contacts_obj, 'search'))
3440 3439
 					{
3441
-						$contact['n_fn']='';
3440
+						$contact['n_fn'] = '';
3442 3441
 						if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
3443
-						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3444
-						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3445
-						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3446
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3442
+						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_given'];
3443
+						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_family'];
3444
+						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').'('.$contact['org_name'].')';
3445
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3447 3446
 					}
3448 3447
 					else
3449 3448
 					{
3450
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3449
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3451 3450
 					}
3452 3451
 					$args = explode('@', trim($email));
3453 3452
 					$args[] = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']);
3454 3453
 					$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
3455
-					if(!empty($email) && in_array($completeMailString ,$results) === false) {
3454
+					if (!empty($email) && in_array($completeMailString, $results) === false) {
3456 3455
 						$results[] = array(
3457 3456
 							'id'=>$completeMailString,
3458 3457
 							'label' => $completeMailString,
@@ -3468,10 +3467,10 @@  discard block
 block discarded – undo
3468 3467
 		// Add groups
3469 3468
 		$group_options = array('account_type' => 'groups');
3470 3469
 		$groups = $GLOBALS['egw']->accounts->link_query($_searchString, $group_options);
3471
-		foreach($groups as $g_id => $name)
3470
+		foreach ($groups as $g_id => $name)
3472 3471
 		{
3473 3472
 			$group = $GLOBALS['egw']->accounts->read($g_id);
3474
-			if(!$group['account_email']) continue;
3473
+			if (!$group['account_email']) continue;
3475 3474
 			$args = explode('@', trim($group['account_email']));
3476 3475
 			$args[] = $name;
3477 3476
 			$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
@@ -3501,7 +3500,7 @@  discard block
 block discarded – undo
3501 3500
 	public function ajax_merge($contact_id)
3502 3501
 	{
3503 3502
 		$response = Api\Json\Response::get();
3504
-		if(class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3503
+		if (class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3505 3504
 		{
3506 3505
 			$document_merge = new $_REQUEST['merge']();
3507 3506
 		}
@@ -3511,7 +3510,7 @@  discard block
 block discarded – undo
3511 3510
 		}
3512 3511
 		$this->mail_bo->openConnection();
3513 3512
 
3514
-		if(($error = $document_merge->check_document($_REQUEST['document'],'')))
3513
+		if (($error = $document_merge->check_document($_REQUEST['document'], '')))
3515 3514
 		{
3516 3515
 			$response->error($error);
3517 3516
 			return;
@@ -3522,11 +3521,11 @@  discard block
 block discarded – undo
3522 3521
 		try
3523 3522
 		{
3524 3523
 			$results = $this->mail_bo->importMessageToMergeAndSend(
3525
-				$document_merge, Vfs::PREFIX . $_REQUEST['document'],
3524
+				$document_merge, Vfs::PREFIX.$_REQUEST['document'],
3526 3525
 				// Send an extra non-numeric ID to force actual send of document
3527 3526
 				// instead of save as draft
3528 3527
 				array((int)$contact_id, ''),
3529
-				$folder,$merged_mail_id
3528
+				$folder, $merged_mail_id
3530 3529
 			);
3531 3530
 		}
3532 3531
 		catch (Exception $e)
@@ -3540,13 +3539,13 @@  discard block
 block discarded – undo
3540 3539
 			);
3541 3540
 		}
3542 3541
 
3543
-		if($results['success'])
3542
+		if ($results['success'])
3544 3543
 		{
3545
-			$response->data(implode(',',$results['success']));
3544
+			$response->data(implode(',', $results['success']));
3546 3545
 		}
3547
-		if($results['failed'])
3546
+		if ($results['failed'])
3548 3547
 		{
3549
-			$response->error(implode(',',$results['failed']));
3548
+			$response->error(implode(',', $results['failed']));
3550 3549
 		}
3551 3550
 	}
3552 3551
 }
Please login to merge, or discard this patch.