Completed
Push — 16.1 ( c49bdc...e62dd1 )
by Hadi
16:55
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,38 +1093,38 @@  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 1105
 			empty($signature['ident_signature']) ||
1107
-			trim($this->convertHTMLToText($signature['ident_signature'],true,true)) =='' ||
1106
+			trim($this->convertHTMLToText($signature['ident_signature'], true, true)) == '' ||
1108 1107
 			$this->mailPreferences['insertSignatureAtTopOfMessage'] == '1')
1109 1108
 		{
1110 1109
 			$disableRuler = true;
1111 1110
 		}
1112 1111
 		$font_span = $font_part = '';
1113
-		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1112
+		if ($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1114 1113
 			// User preferences for style
1115 1114
 			$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
1116 1115
 			$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
1117
-			$font_part = '<span style="width:100%; display: inline; '.($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'">';
1116
+			$font_part = '<span style="width:100%; display: inline; '.($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').'">';
1118 1117
 			$font_span = $font_part.'&#8203;</span>';
1119 1118
 			if (empty($font) && empty($font_size)) $font_span = '';
1120 1119
 		}
1121 1120
 		// 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
1122
-		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false) $font_span = '';
1121
+		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'], $font_part) === false) $font_span = '';
1123 1122
 		//remove possible html header stuff
1124
-		if (stripos($content['body'],'<html><head></head><body>')!==false) $content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1123
+		if (stripos($content['body'], '<html><head></head><body>') !== false) $content['body'] = str_ireplace(array('<html><head></head><body>', '</body></html>'), array('', ''), $content['body']);
1125 1124
 		//error_log(__METHOD__.__LINE__.array2string($this->mailPreferences));
1126
-		$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');
1127
-		if ($this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend' &&
1128
-			!(isset($_POST['mySigID']) && !empty($_POST['mySigID']) ) && !$suppressSigOnTop
1125
+		$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');
1126
+		if ($this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' &&
1127
+			!(isset($_POST['mySigID']) && !empty($_POST['mySigID'])) && !$suppressSigOnTop
1129 1128
 		)
1130 1129
 		{
1131 1130
 			// ON tOP OR BELOW? pREF CAN TELL
@@ -1135,57 +1134,57 @@  discard block
 block discarded – undo
1135 1134
 						'1' => 'before reply, visible during compose',
1136 1135
 						'no_belowaftersend'  => 'appended after reply before sending',
1137 1136
 			*/
1138
-			$insertSigOnTop = ($insertSigOnTop?$insertSigOnTop:($this->mailPreferences['insertSignatureAtTopOfMessage']?$this->mailPreferences['insertSignatureAtTopOfMessage']:'below'));
1139
-			$sigText = Mail::merge($signature['ident_signature'],array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
1137
+			$insertSigOnTop = ($insertSigOnTop ? $insertSigOnTop : ($this->mailPreferences['insertSignatureAtTopOfMessage'] ? $this->mailPreferences['insertSignatureAtTopOfMessage'] : 'below'));
1138
+			$sigText = Mail::merge($signature['ident_signature'], array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
1140 1139
 			if ($content['mimeType'] == 'html')
1141 1140
 			{
1142
-				$sigTextStartsWithBlockElement = ($disableRuler?false:true);
1143
-				foreach($blockElements as $e)
1141
+				$sigTextStartsWithBlockElement = ($disableRuler ?false:true);
1142
+				foreach ($blockElements as $e)
1144 1143
 				{
1145 1144
 					if ($sigTextStartsWithBlockElement) break;
1146
-					if (stripos(trim($sigText),'<'.$e)===0) $sigTextStartsWithBlockElement = true;
1145
+					if (stripos(trim($sigText), '<'.$e) === 0) $sigTextStartsWithBlockElement = true;
1147 1146
 				}
1148 1147
 			}
1149
-			if($content['mimeType'] == 'html') {
1148
+			if ($content['mimeType'] == 'html') {
1150 1149
 				$before = $disableRuler ? '' : '<hr style="border:1px dotted silver; width:100%;">';
1151 1150
 				$inbetween = '';
1152 1151
 			} else {
1153
-				$before = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
1152
+				$before = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
1154 1153
 				$inbetween = "\r\n";
1155 1154
 			}
1156 1155
 			if ($content['mimeType'] == 'html')
1157 1156
 			{
1158
-				$sigText = ($sigTextStartsWithBlockElement?'':"<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement?'':"</div>");
1157
+				$sigText = ($sigTextStartsWithBlockElement ? '' : "<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement ? '' : "</div>");
1159 1158
 			}
1160 1159
 
1161 1160
 			if ($insertSigOnTop === 'below')
1162 1161
 			{
1163
-				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true));
1162
+				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true));
1164 1163
 			}
1165 1164
 			else
1166 1165
 			{
1167
-				$content['body'] = $font_span.$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true)).$inbetween.$content['body'];
1166
+				$content['body'] = $font_span.$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true)).$inbetween.$content['body'];
1168 1167
 			}
1169 1168
 		}
1170 1169
 		else
1171 1170
 		{
1172
-			$content['body'] = ($font_span?($isFirstLoad === "switchedplaintohtml"?$font_part:$font_span):/*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml"?"</span>":"");
1171
+			$content['body'] = ($font_span ? ($isFirstLoad === "switchedplaintohtml" ? $font_part : $font_span) : /*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml" ? "</span>" : "");
1173 1172
 		}
1174 1173
 		//error_log(__METHOD__.__LINE__.$content['body']);
1175 1174
 
1176 1175
 		// prepare body
1177 1176
 		// 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
1178
-		$content['body'] = Api\Translation::convert_jsonsafe($content['body'],'utf-8');
1177
+		$content['body'] = Api\Translation::convert_jsonsafe($content['body'], 'utf-8');
1179 1178
 		//error_log(__METHOD__.__LINE__.array2string($content));
1180 1179
 
1181 1180
 		// get identities of all accounts as "$acc_id:$ident_id" => $identity
1182 1181
 		$sel_options['mailaccount'] = $identities = array();
1183
-		foreach(Mail\Account::search(true,false) as $acc_id => $account)
1182
+		foreach (Mail\Account::search(true, false) as $acc_id => $account)
1184 1183
 		{
1185 1184
 			// do NOT add SMTP only accounts as identities
1186 1185
 			if (!$account->is_imap(false)) continue;
1187 1186
 
1188
-			foreach($account->identities($acc_id) as $ident_id => $identity)
1187
+			foreach ($account->identities($acc_id) as $ident_id => $identity)
1189 1188
 			{
1190 1189
 				$sel_options['mailaccount'][$acc_id.':'.$ident_id] = $identity;
1191 1190
 				$identities[$ident_id] = $identity;
@@ -1196,7 +1195,7 @@  discard block
 block discarded – undo
1196 1195
 		//$content['bcc'] = array('[email protected]','[email protected]');
1197 1196
 		// address stuff like from, to, cc, replyto
1198 1197
 		$destinationRows = 0;
1199
-		foreach(self::$destinations as $destination) {
1198
+		foreach (self::$destinations as $destination) {
1200 1199
 			if (!is_array($content[$destination]))
1201 1200
 			{
1202 1201
 				if (!empty($content[$destination])) $content[$destination] = (array)$content[$destination];
@@ -1204,22 +1203,22 @@  discard block
 block discarded – undo
1204 1203
 			$addr_content = $content[strtolower($destination)];
1205 1204
 			// we clear the given address array and rebuild it
1206 1205
 			unset($content[strtolower($destination)]);
1207
-			foreach((array)$addr_content as $key => $value) {
1208
-				if ($value=="NIL@NIL") continue;
1209
-				if ($destination=='replyto' && str_replace('"','',$value) ==
1210
-					str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
1206
+			foreach ((array)$addr_content as $key => $value) {
1207
+				if ($value == "NIL@NIL") continue;
1208
+				if ($destination == 'replyto' && str_replace('"', '', $value) ==
1209
+					str_replace('"', '', $identities[$this->mail_bo->getDefaultIdentity()]))
1211 1210
 				{
1212 1211
 					// preserve/restore the value to content.
1213
-					$content[strtolower($destination)][]=$value;
1212
+					$content[strtolower($destination)][] = $value;
1214 1213
 					continue;
1215 1214
 				}
1216 1215
 				//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
1217
-				$value = str_replace("\"\"",'"', htmlspecialchars_decode($value, ENT_COMPAT));
1218
-				foreach(Mail::parseAddressList($value) as $addressObject) {
1216
+				$value = str_replace("\"\"", '"', htmlspecialchars_decode($value, ENT_COMPAT));
1217
+				foreach (Mail::parseAddressList($value) as $addressObject) {
1219 1218
 					if ($addressObject->host == '.SYNTAX-ERROR.') continue;
1220
-					$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
1219
+					$address = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
1221 1220
 					//$address = Mail::htmlentities($address, $this->displayCharset);
1222
-					$content[strtolower($destination)][]=$address;
1221
+					$content[strtolower($destination)][] = $address;
1223 1222
 					$destinationRows++;
1224 1223
 				}
1225 1224
 			}
@@ -1227,10 +1226,10 @@  discard block
 block discarded – undo
1227 1226
 		if ($_content)
1228 1227
 		{
1229 1228
 			//input array of _content had no signature information but was seeded later, and content has a valid setting
1230
-			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content)) unset($_content['mailidentity']);
1231
-			$content = array_merge($content,$_content);
1229
+			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity', $_content)) unset($_content['mailidentity']);
1230
+			$content = array_merge($content, $_content);
1232 1231
 
1233
-			if (!empty($content['folder'])) $sel_options['folder']=$this->ajax_searchFolder(0,true);
1232
+			if (!empty($content['folder'])) $sel_options['folder'] = $this->ajax_searchFolder(0, true);
1234 1233
 			if (empty($content['mailaccount'])) $content['mailaccount'] = $this->mail_bo->profileID;
1235 1234
 		}
1236 1235
 		else
@@ -1239,12 +1238,12 @@  discard block
 block discarded – undo
1239 1238
 			$content['mailaccount'] = $this->mail_bo->profileID;
1240 1239
 			//error_log(__METHOD__.__LINE__.$content['body']);
1241 1240
 		}
1242
-		$content['is_html'] = ($content['mimeType'] == 'html'?true:'');
1243
-		$content['is_plain'] = ($content['mimeType'] == 'html'?'':true);
1244
-		$content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text'] =$content['body'];
1245
-		$content['showtempname']=0;
1241
+		$content['is_html'] = ($content['mimeType'] == 'html' ?true:'');
1242
+		$content['is_plain'] = ($content['mimeType'] == 'html' ? '' : true);
1243
+		$content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text'] = $content['body'];
1244
+		$content['showtempname'] = 0;
1246 1245
 		//if (is_array($content['attachments']))error_log(__METHOD__.__LINE__.'before merging content with uploadforCompose:'.array2string($content['attachments']));
1247
-		$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
+		$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)));
1248 1247
 		//if (is_array($content['attachments'])) foreach($content['attachments'] as $k => &$file) $file['delete['.$file['tmp_name'].']']=0;
1249 1248
 		$content['no_griddata'] = empty($content['attachments']);
1250 1249
 		$preserv['attachments'] = $content['attachments'];
@@ -1278,12 +1277,12 @@  discard block
 block discarded – undo
1278 1277
 		$sel_options['mimeType'] = self::$mimeTypes;
1279 1278
 		$sel_options['priority'] = self::$priorities;
1280 1279
 		$sel_options['filemode'] = Vfs\Sharing::$modes;
1281
-		if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
1280
+		if (!isset($content['priority']) || empty($content['priority'])) $content['priority'] = 3;
1282 1281
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
1283 1282
 		$etpl = new Etemplate('mail.compose');
1284 1283
 
1285 1284
 		$etpl->setElementAttribute('composeToolbar', 'actions', $this->getToolbarActions($_content));
1286
-		if ($content['mimeType']=='html')
1285
+		if ($content['mimeType'] == 'html')
1287 1286
 		{
1288 1287
 			//mode="$cont[rtfEditorFeatures]" validation_rules="$cont[validation_rules]" base_href="$cont[upload_dir]"
1289 1288
 			$_htmlConfig = Mail::$htmLawed_config;
@@ -1293,23 +1292,23 @@  discard block
 block discarded – undo
1293 1292
 			// and not the eGroupware wide pref to prevent users from trying things that will potentially not work
1294 1293
 			// or not work as expected, as a full featured editor that may be wanted in other apps
1295 1294
 			// is way overloading the "normal" needs for composing mails
1296
-			$content['rtfEditorFeatures']='simple-withimage';//Api\Html\CkEditorConfig::get_ckeditor_config();
1295
+			$content['rtfEditorFeatures'] = 'simple-withimage'; //Api\Html\CkEditorConfig::get_ckeditor_config();
1297 1296
 			//$content['rtfEditorFeatures']='advanced';//Api\Html\CkEditorConfig::get_ckeditor_config();
1298
-			$content['validation_rules']= json_encode(Mail::$htmLawed_config);
1299
-			$etpl->setElementAttribute('mail_htmltext','mode',$content['rtfEditorFeatures']);
1300
-			$etpl->setElementAttribute('mail_htmltext','validation_rules',$content['validation_rules']);
1297
+			$content['validation_rules'] = json_encode(Mail::$htmLawed_config);
1298
+			$etpl->setElementAttribute('mail_htmltext', 'mode', $content['rtfEditorFeatures']);
1299
+			$etpl->setElementAttribute('mail_htmltext', 'validation_rules', $content['validation_rules']);
1301 1300
 			Mail::$htmLawed_config = $_htmlConfig;
1302 1301
 		}
1303 1302
 
1304
-		if (isset($content['composeID'])&&!empty($content['composeID']))
1303
+		if (isset($content['composeID']) && !empty($content['composeID']))
1305 1304
 		{
1306 1305
 			$composeCache = $content;
1307 1306
 			unset($composeCache['body']);
1308 1307
 			unset($composeCache['mail_htmltext']);
1309 1308
 			unset($composeCache['mail_plaintext']);
1310
-			Api\Cache::setCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID,$composeCache,$expiration=60*60*2);
1309
+			Api\Cache::setCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID, $composeCache, $expiration = 60 * 60 * 2);
1311 1310
 		}
1312
-		if (!isset($_content['serverID'])||empty($_content['serverID']))
1311
+		if (!isset($_content['serverID']) || empty($_content['serverID']))
1313 1312
 		{
1314 1313
 			$content['serverID'] = $this->mail_bo->profileID;
1315 1314
 		}
@@ -1325,13 +1324,13 @@  discard block
 block discarded – undo
1325 1324
 		$preserv['list-id'] = $content['list-id'];
1326 1325
 		$preserv['mode'] = $content['mode'];
1327 1326
 		// convert it back to checkbox expectations
1328
-		if($content['mimeType'] == 'html') {
1329
-			$content['mimeType']=1;
1327
+		if ($content['mimeType'] == 'html') {
1328
+			$content['mimeType'] = 1;
1330 1329
 		} else {
1331
-			$content['mimeType']=0;
1330
+			$content['mimeType'] = 0;
1332 1331
 		}
1333 1332
 		// set the current selected mailaccount as param for folderselection
1334
-		$etpl->setElementAttribute('folder','autocomplete_params',array('mailaccount'=>$content['mailaccount']));
1333
+		$etpl->setElementAttribute('folder', 'autocomplete_params', array('mailaccount'=>$content['mailaccount']));
1335 1334
 		// join again mailaccount and identity
1336 1335
 		$content['mailaccount'] .= ':'.$content['mailidentity'];
1337 1336
 		//Try to set the initial selected account to the first identity match found
@@ -1350,14 +1349,14 @@  discard block
 block discarded – undo
1350 1349
 			}
1351 1350
 		}
1352 1351
 		// Resolve distribution list before send content to client
1353
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $f)
1352
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $f)
1354 1353
 		{
1355
-			if (is_array($content[$f])) $content[$f]= self::resolveEmailAddressList ($content[$f]);
1354
+			if (is_array($content[$f])) $content[$f] = self::resolveEmailAddressList($content[$f]);
1356 1355
 		}
1357 1356
 
1358 1357
 		$content['to'] = self::resolveEmailAddressList($content['to']);
1359 1358
 		//error_log(__METHOD__.__LINE__.array2string($content));
1360
-		$etpl->exec('mail.mail_compose.compose',$content,$sel_options,array(),$preserv,2);
1359
+		$etpl->exec('mail.mail_compose.compose', $content, $sel_options, array(), $preserv, 2);
1361 1360
 	}
1362 1361
 
1363 1362
 	/**
@@ -1378,9 +1377,9 @@  discard block
 block discarded – undo
1378 1377
 		$content = array();
1379 1378
 		//error_log(__METHOD__.__LINE__.array2string($mail_id).", $part_id, $from, $_focusElement, $suppressSigOnTop, $isReply");
1380 1379
 		// on forward we may have to support multiple ids
1381
-		if ($from=='forward')
1380
+		if ($from == 'forward')
1382 1381
 		{
1383
-			$replyIds = explode(',',$mail_id);
1382
+			$replyIds = explode(',', $mail_id);
1384 1383
 			$mail_id = $replyIds[0];
1385 1384
 		}
1386 1385
 		$hA = mail_ui::splitRowID($mail_id);
@@ -1392,15 +1391,15 @@  discard block
 block discarded – undo
1392 1391
 			$this->changeProfile($icServerID);
1393 1392
 		}
1394 1393
 		$icServer = $this->mail_bo->icServer;
1395
-		if (!empty($folder) && !empty($msgUID) )
1394
+		if (!empty($folder) && !empty($msgUID))
1396 1395
 		{
1397 1396
 			// this fill the session data with the values from the original email
1398
-			switch($from)
1397
+			switch ($from)
1399 1398
 			{
1400 1399
 				case 'composefromdraft':
1401 1400
 				case 'composeasnew':
1402 1401
 					$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
1403
-					if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
1402
+					if ($from == 'composefromdraft') $content['mode'] = 'composefromdraft';
1404 1403
 					$content['processedmail_id'] = $mail_id;
1405 1404
 
1406 1405
 					$_focusElement = 'body';
@@ -1416,7 +1415,7 @@  discard block
 block discarded – undo
1416 1415
 					$isReply = true;
1417 1416
 					break;
1418 1417
 				case 'forward':
1419
-					$mode  = ($_GET['mode']=='forwardinline'?'inline':'asmail');
1418
+					$mode = ($_GET['mode'] == 'forwardinline' ? 'inline' : 'asmail');
1420 1419
 					// this fill the session data with the values from the original email
1421 1420
 					foreach ($replyIds as &$mail_id)
1422 1421
 					{
@@ -1426,14 +1425,14 @@  discard block
 block discarded – undo
1426 1425
 						$folder = $hA['folder'];
1427 1426
 						$content = $this->getForwardData($icServer, $folder, $msgUID, $part_id, $mode);
1428 1427
 					}
1429
-					$content['processedmail_id'] = implode(',',$replyIds);
1428
+					$content['processedmail_id'] = implode(',', $replyIds);
1430 1429
 					$content['mode'] = 'forward';
1431
-					$isReply = ($mode?$mode=='inline':$this->mailPreferences['message_forwarding'] == 'inline');
1432
-					$suppressSigOnTop = false;// ($mode && $mode=='inline'?true:false);// may be a better solution
1430
+					$isReply = ($mode ? $mode == 'inline' : $this->mailPreferences['message_forwarding'] == 'inline');
1431
+					$suppressSigOnTop = false; // ($mode && $mode=='inline'?true:false);// may be a better solution
1433 1432
 					$_focusElement = 'to';
1434 1433
 					break;
1435 1434
 				default:
1436
-					error_log('Unhandled compose source: ' . $from);
1435
+					error_log('Unhandled compose source: '.$from);
1437 1436
 			}
1438 1437
 		}
1439 1438
 		else if ($from == 'merge' && $_REQUEST['document'])
@@ -1448,12 +1447,12 @@  discard block
 block discarded – undo
1448 1447
 			$document_merge = new $merge_class();
1449 1448
 			$this->mail_bo->openConnection();
1450 1449
 			$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
1451
-			if (!is_array($merge_ids)) $merge_ids = explode(',',$merge_ids);
1450
+			if (!is_array($merge_ids)) $merge_ids = explode(',', $merge_ids);
1452 1451
 			try
1453 1452
 			{
1454 1453
 				$merged_mail_id = '';
1455 1454
 				$folder = '';
1456
-				if(($error = $document_merge->check_document($_REQUEST['document'],'')))
1455
+				if (($error = $document_merge->check_document($_REQUEST['document'], '')))
1457 1456
 				{
1458 1457
 					$content['msg'] = $error;
1459 1458
 					return $content;
@@ -1463,10 +1462,10 @@  discard block
 block discarded – undo
1463 1462
 				//$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
1464 1463
 
1465 1464
 				// Actually do the merge
1466
-				if(count($merge_ids) <= 1)
1465
+				if (count($merge_ids) <= 1)
1467 1466
 				{
1468 1467
 					$results = $this->mail_bo->importMessageToMergeAndSend(
1469
-						$document_merge, Vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1468
+						$document_merge, Vfs::PREFIX.$_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1470 1469
 					);
1471 1470
 
1472 1471
 					// Open compose
@@ -1477,9 +1476,9 @@  discard block
 block discarded – undo
1477 1476
 				}
1478 1477
 				else
1479 1478
 				{
1480
-					$success = implode(', ',$results['success']);
1479
+					$success = implode(', ', $results['success']);
1481 1480
 					$fail = implode(', ', $results['failed']);
1482
-					if($success) Framework::message($success, 'success');
1481
+					if ($success) Framework::message($success, 'success');
1483 1482
 					Framework::window_close($fail);
1484 1483
 				}
1485 1484
 			}
@@ -1507,22 +1506,22 @@  discard block
 block discarded – undo
1507 1506
 		return 1;
1508 1507
 	}
1509 1508
 
1510
-	function convertHTMLToText(&$_html,$sourceishtml = true, $stripcrl=false)
1509
+	function convertHTMLToText(&$_html, $sourceishtml = true, $stripcrl = false)
1511 1510
 	{
1512 1511
 		$stripalltags = true;
1513 1512
 		// third param is stripalltags, we may not need that, if the source is already in ascii
1514
-		if (!$sourceishtml) $stripalltags=false;
1515
-		return Api\Mail\Html::convertHTMLToText($_html,$this->displayCharset,$stripcrl,$stripalltags);
1513
+		if (!$sourceishtml) $stripalltags = false;
1514
+		return Api\Mail\Html::convertHTMLToText($_html, $this->displayCharset, $stripcrl, $stripalltags);
1516 1515
 	}
1517 1516
 
1518 1517
 	function generateRFC822Address($_addressObject)
1519 1518
 	{
1520
-		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1521
-			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1522
-		} elseif($_addressObject->mailbox && $_addressObject->host) {
1523
-			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1519
+		if ($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1520
+			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1521
+		} elseif ($_addressObject->mailbox && $_addressObject->host) {
1522
+			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1524 1523
 		} else {
1525
-			return $this->mail_bo->decode_header($_addressObject->mailbox,true);
1524
+			return $this->mail_bo->decode_header($_addressObject->mailbox, true);
1526 1525
 		}
1527 1526
 	}
1528 1527
 
@@ -1537,9 +1536,9 @@  discard block
 block discarded – undo
1537 1536
 	// $_mode can be:
1538 1537
 	// single: for a reply to one address
1539 1538
 	// all: for a reply to all
1540
-	function getDraftData($_icServer, $_folder, $_uid, $_partID=NULL)
1539
+	function getDraftData($_icServer, $_folder, $_uid, $_partID = NULL)
1541 1540
 	{
1542
-		unset($_icServer);	// not used
1541
+		unset($_icServer); // not used
1543 1542
 		$this->sessionData['to'] = array();
1544 1543
 
1545 1544
 		$mail_bo = $this->mail_bo;
@@ -1548,7 +1547,7 @@  discard block
 block discarded – undo
1548 1547
 
1549 1548
 		// get message headers for specified message
1550 1549
 		#$headers	= $mail_bo->getMessageHeader($_folder, $_uid);
1551
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID);
1550
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID);
1552 1551
 		$addHeadInfo = $mail_bo->getMessageHeader($_uid, $_partID);
1553 1552
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
1554 1553
 		// horde does not support the encoding of thread-topic, and probably will not no so in the future
@@ -1556,10 +1555,10 @@  discard block
 block discarded – undo
1556 1555
 
1557 1556
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1558 1557
 		if (!empty($addHeadInfo['X-MAILFOLDER'])) {
1559
-			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val ) {
1560
-				$fval=$val;
1558
+			foreach (explode('|', $addHeadInfo['X-MAILFOLDER']) as $val) {
1559
+				$fval = $val;
1561 1560
 				$icServerID = $mail_bo->icServer->ImapServerId;
1562
-				if (stripos($val,'::')!==false) list($icServerID,$fval) = explode('::',$val,2);
1561
+				if (stripos($val, '::') !== false) list($icServerID, $fval) = explode('::', $val, 2);
1563 1562
 				if ($icServerID != $mail_bo->icServer->ImapServerId) continue;
1564 1563
 				if ($mail_bo->folderExists($fval)) $this->sessionData['folder'][] = $val;
1565 1564
 			}
@@ -1595,71 +1594,71 @@  discard block
 block discarded – undo
1595 1594
 			}
1596 1595
 		}
1597 1596
 		// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
1598
-		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);//array('uid'=>$_uid,'folder'=>$_folder);
1597
+		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid); //array('uid'=>$_uid,'folder'=>$_folder);
1599 1598
 		$this->sessionData['uid'] = $_uid;
1600 1599
 		$this->sessionData['messageFolder'] = $_folder;
1601 1600
 		$this->sessionData['isDraft'] = true;
1602 1601
 		$foundAddresses = array();
1603
-		foreach((array)$headers['CC'] as $val) {
1604
-			$rfcAddr=Mail::parseAddressList($val);
1602
+		foreach ((array)$headers['CC'] as $val) {
1603
+			$rfcAddr = Mail::parseAddressList($val);
1605 1604
 			$_rfcAddr = $rfcAddr[0];
1606 1605
 			if (!$_rfcAddr->valid) continue;
1607
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1606
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1608 1607
 				continue;
1609 1608
 			}
1610
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1611
-			if(!$foundAddresses[$keyemail]) {
1612
-				$address = $this->mail_bo->decode_header($val,true);
1609
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1610
+			if (!$foundAddresses[$keyemail]) {
1611
+				$address = $this->mail_bo->decode_header($val, true);
1613 1612
 				$this->sessionData['cc'][] = $val;
1614 1613
 				$foundAddresses[$keyemail] = true;
1615 1614
 			}
1616 1615
 		}
1617 1616
 
1618
-		foreach((array)$headers['TO'] as $val) {
1619
-			if(!is_array($val))
1617
+		foreach ((array)$headers['TO'] as $val) {
1618
+			if (!is_array($val))
1620 1619
 			{
1621 1620
 				$this->sessionData['to'][] = $val;
1622 1621
 				continue;
1623 1622
 			}
1624
-			$rfcAddr=Mail::parseAddressList($val);
1623
+			$rfcAddr = Mail::parseAddressList($val);
1625 1624
 			$_rfcAddr = $rfcAddr[0];
1626 1625
 			if (!$_rfcAddr->valid) continue;
1627
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1626
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1628 1627
 				continue;
1629 1628
 			}
1630
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1631
-			if(!$foundAddresses[$keyemail]) {
1632
-				$address = $this->mail_bo->decode_header($val,true);
1629
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1630
+			if (!$foundAddresses[$keyemail]) {
1631
+				$address = $this->mail_bo->decode_header($val, true);
1633 1632
 				$this->sessionData['to'][] = $val;
1634 1633
 				$foundAddresses[$keyemail] = true;
1635 1634
 			}
1636 1635
 		}
1637 1636
 
1638
-		foreach((array)$headers['REPLY-TO'] as $val) {
1639
-			$rfcAddr=Mail::parseAddressList($val);
1637
+		foreach ((array)$headers['REPLY-TO'] as $val) {
1638
+			$rfcAddr = Mail::parseAddressList($val);
1640 1639
 			$_rfcAddr = $rfcAddr[0];
1641 1640
 			if (!$_rfcAddr->valid) continue;
1642
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1641
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1643 1642
 				continue;
1644 1643
 			}
1645
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1646
-			if(!$foundAddresses[$keyemail]) {
1647
-				$address = $this->mail_bo->decode_header($val,true);
1644
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1645
+			if (!$foundAddresses[$keyemail]) {
1646
+				$address = $this->mail_bo->decode_header($val, true);
1648 1647
 				$this->sessionData['replyto'][] = $val;
1649 1648
 				$foundAddresses[$keyemail] = true;
1650 1649
 			}
1651 1650
 		}
1652 1651
 
1653
-		foreach((array)$headers['BCC'] as $val) {
1654
-			$rfcAddr=Mail::parseAddressList($val);
1652
+		foreach ((array)$headers['BCC'] as $val) {
1653
+			$rfcAddr = Mail::parseAddressList($val);
1655 1654
 			$_rfcAddr = $rfcAddr[0];
1656 1655
 			if (!$_rfcAddr->valid) continue;
1657
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1656
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1658 1657
 				continue;
1659 1658
 			}
1660
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1661
-			if(!$foundAddresses[$keyemail]) {
1662
-				$address = $this->mail_bo->decode_header($val,true);
1659
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1660
+			if (!$foundAddresses[$keyemail]) {
1661
+				$address = $this->mail_bo->decode_header($val, true);
1663 1662
 				$this->sessionData['bcc'][] = $val;
1664 1663
 				$foundAddresses[$keyemail] = true;
1665 1664
 			}
@@ -1668,48 +1667,48 @@  discard block
 block discarded – undo
1668 1667
 		$this->sessionData['subject']	= $mail_bo->decode_header($headers['SUBJECT']);
1669 1668
 		// remove a printview tag if composing
1670 1669
 		$searchfor = '/^\['.lang('printview').':\]/';
1671
-		$this->sessionData['subject'] = preg_replace($searchfor,'',$this->sessionData['subject']);
1672
-		$bodyParts = $mail_bo->getMessageBody($_uid,'always_display', $_partID);
1670
+		$this->sessionData['subject'] = preg_replace($searchfor, '', $this->sessionData['subject']);
1671
+		$bodyParts = $mail_bo->getMessageBody($_uid, 'always_display', $_partID);
1673 1672
 		//_debug_array($bodyParts);
1674 1673
 		#$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
1675
-		if($bodyParts['0']['mimeType'] == 'text/html') {
1676
-			$this->sessionData['mimeType'] 	= 'html';
1674
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
1675
+			$this->sessionData['mimeType'] = 'html';
1677 1676
 
1678
-			for($i=0; $i<count($bodyParts); $i++) {
1679
-				if($i>0) {
1677
+			for ($i = 0; $i < count($bodyParts); $i++) {
1678
+				if ($i > 0) {
1680 1679
 					$this->sessionData['body'] .= '<hr>';
1681 1680
 				}
1682
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
1681
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
1683 1682
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']);
1684 1683
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
1685 1684
 				}
1686
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1685
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1687 1686
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1688 1687
 				#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1689
-				$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
1688
+				$this->sessionData['body'] .= ($i > 0 ? "<br>" : "").$bodyParts[$i]['body'];
1690 1689
 			}
1691 1690
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID);
1692 1691
 
1693 1692
 		} else {
1694
-			$this->sessionData['mimeType']	= 'plain';
1693
+			$this->sessionData['mimeType'] = 'plain';
1695 1694
 
1696
-			for($i=0; $i<count($bodyParts); $i++) {
1697
-				if($i>0) {
1695
+			for ($i = 0; $i < count($bodyParts); $i++) {
1696
+				if ($i > 0) {
1698 1697
 					$this->sessionData['body'] .= "<hr>";
1699 1698
 				}
1700
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1699
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1701 1700
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1702 1701
 				#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1703
-				$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
1702
+				$this->sessionData['body'] .= ($i > 0 ? "\r\n" : "").$bodyParts[$i]['body'];
1704 1703
 			}
1705
-			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID,'plain');
1704
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'plain');
1706 1705
 		}
1707 1706
 
1708
-		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID))) {
1709
-			foreach($attachments as $attachment) {
1707
+		if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID))) {
1708
+			foreach ($attachments as $attachment) {
1710 1709
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
1711 1710
 				$cid = $attachment['cid'];
1712
-				$match=null;
1711
+				$match = null;
1713 1712
 				preg_match("/cid:{$cid}/", $bodyParts['0']['body'], $match);
1714 1713
 				//error_log(__METHOD__.__LINE__.'searching for cid:'."/cid:{$cid}/".'#'.$r.'#'.array2string($match));
1715 1714
 				if (!$match || !$attachment['cid'])
@@ -1729,7 +1728,7 @@  discard block
 block discarded – undo
1729 1728
 
1730 1729
 	function getErrorInfo()
1731 1730
 	{
1732
-		if(isset($this->errorInfo)) {
1731
+		if (isset($this->errorInfo)) {
1733 1732
 			$errorInfo = $this->errorInfo;
1734 1733
 			unset($this->errorInfo);
1735 1734
 			return $errorInfo;
@@ -1737,39 +1736,39 @@  discard block
 block discarded – undo
1737 1736
 		return false;
1738 1737
 	}
1739 1738
 
1740
-	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode=false)
1739
+	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode = false)
1741 1740
 	{
1742 1741
 		if ($_mode)
1743 1742
 		{
1744 1743
 			$modebuff = $this->mailPreferences['message_forwarding'];
1745 1744
 			$this->mailPreferences['message_forwarding'] = $_mode;
1746 1745
 		}
1747
-		if  ($this->mailPreferences['message_forwarding'] == 'inline') {
1746
+		if ($this->mailPreferences['message_forwarding'] == 'inline') {
1748 1747
 			$this->getReplyData('forward', $_icServer, $_folder, $_uid, $_partID);
1749 1748
 		}
1750
-		$mail_bo    = $this->mail_bo;
1749
+		$mail_bo = $this->mail_bo;
1751 1750
 		$mail_bo->openConnection();
1752 1751
 		$mail_bo->reopen($_folder);
1753 1752
 
1754 1753
 		// get message headers for specified message
1755
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder);
1754
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder);
1756 1755
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1757 1756
 		//_debug_array($headers); exit;
1758 1757
 		// check for Re: in subject header
1759
-		$this->sessionData['subject'] 	= "[FWD] " . $mail_bo->decode_header($headers['SUBJECT']);
1758
+		$this->sessionData['subject'] = "[FWD] ".$mail_bo->decode_header($headers['SUBJECT']);
1760 1759
 		// the three attributes below are substituted by processedmail_id and mode
1761 1760
 		//$this->sessionData['sourceFolder']=$_folder;
1762 1761
 		//$this->sessionData['forwardFlag']='forwarded';
1763 1762
 		//$this->sessionData['forwardedUID']=$_uid;
1764
-		if  ($this->mailPreferences['message_forwarding'] == 'asmail') {
1765
-			$this->sessionData['mimeType']  = $this->mailPreferences['composeOptions'];
1766
-			if($headers['SIZE'])
1763
+		if ($this->mailPreferences['message_forwarding'] == 'asmail') {
1764
+			$this->sessionData['mimeType'] = $this->mailPreferences['composeOptions'];
1765
+			if ($headers['SIZE'])
1767 1766
 				$size				= $headers['SIZE'];
1768 1767
 			else
1769 1768
 				$size				= lang('unknown');
1770 1769
 
1771 1770
 			$this->addMessageAttachment($_uid, $_partID, $_folder,
1772
-				$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
1771
+				$mail_bo->decode_header(($headers['SUBJECT'] ? $headers['SUBJECT'] : lang('no subject'))).'.eml',
1773 1772
 				'MESSAGE/RFC822', $size);
1774 1773
 		}
1775 1774
 		else
@@ -1777,10 +1776,10 @@  discard block
 block discarded – undo
1777 1776
 			unset($this->sessionData['in-reply-to']);
1778 1777
 			unset($this->sessionData['to']);
1779 1778
 			unset($this->sessionData['cc']);
1780
-			if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false))) {
1779
+			if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID, null, true, false, false))) {
1781 1780
 				//error_log(__METHOD__.__LINE__.':'.array2string($attachments));
1782
-				foreach($attachments as $attachment) {
1783
-					if (!($attachment['cid'] && preg_match("/image\//",$attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1781
+				foreach ($attachments as $attachment) {
1782
+					if (!($attachment['cid'] && preg_match("/image\//", $attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1784 1783
 					{
1785 1784
 						$this->addMessageAttachment($_uid, $attachment['partID'],
1786 1785
 							$_folder,
@@ -1809,7 +1808,7 @@  discard block
 block discarded – undo
1809 1808
 	 * @param array $_content the content passed to the function and to be modified
1810 1809
 	 * @return void
1811 1810
 	 */
1812
-	function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false)
1811
+	function addAttachment($_formData, &$_content, $eliminateDoubleAttachments = false)
1813 1812
 	{
1814 1813
 		//error_log(__METHOD__.__LINE__.' Formdata:'.array2string($_formData).' Content:'.array2string($_content));
1815 1814
 
@@ -1818,7 +1817,7 @@  discard block
 block discarded – undo
1818 1817
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
1819 1818
 		try
1820 1819
 		{
1821
-			$tmpFileName = Mail::checkFileBasics($_formData,$this->composeID,false);
1820
+			$tmpFileName = Mail::checkFileBasics($_formData, $this->composeID, false);
1822 1821
 		}
1823 1822
 		catch (Api\Exception\WrongUserinput $e)
1824 1823
 		{
@@ -1834,8 +1833,8 @@  discard block
 block discarded – undo
1834 1833
 			foreach ((array)$_content['attachments'] as $attach)
1835 1834
 			{
1836 1835
 				if ($attach['name'] && $attach['name'] == $_formData['name'] &&
1837
-					strtolower($_formData['type'])== strtolower($attach['type']) &&
1838
-					stripos($_formData['file'],'vfs://') !== false) return;
1836
+					strtolower($_formData['type']) == strtolower($attach['type']) &&
1837
+					stripos($_formData['file'], 'vfs://') !== false) return;
1839 1838
 			}
1840 1839
 		}
1841 1840
 		if ($attachfailed === false)
@@ -1847,7 +1846,7 @@  discard block
 block discarded – undo
1847 1846
 				'tmp_name'	=> $tmpFileName,
1848 1847
 				'size'	=> $_formData['size']
1849 1848
 			);
1850
-			if (!is_array($_content['attachments'])) $_content['attachments']=array();
1849
+			if (!is_array($_content['attachments'])) $_content['attachments'] = array();
1851 1850
 			$_content['attachments'][] = $buffer;
1852 1851
 			unset($buffer);
1853 1852
 		}
@@ -1857,9 +1856,9 @@  discard block
 block discarded – undo
1857 1856
 		}
1858 1857
 	}
1859 1858
 
1860
-	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail= null)
1859
+	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail = null)
1861 1860
 	{
1862
-		$this->sessionData['attachments'][]=array (
1861
+		$this->sessionData['attachments'][] = array(
1863 1862
 			'uid'		=> $_uid,
1864 1863
 			'partID'	=> $_partID,
1865 1864
 			'name'		=> $_name,
@@ -1867,7 +1866,7 @@  discard block
 block discarded – undo
1867 1866
 			'size'		=> $_size,
1868 1867
 			'folder'	=> $_folder,
1869 1868
 			'winmailFlag' => $_is_winmail,
1870
-			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID)?$_partID:count($this->sessionData['attachments'])+1),
1869
+			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID) ? $_partID : count($this->sessionData['attachments']) + 1),
1871 1870
 		);
1872 1871
 	}
1873 1872
 
@@ -1876,7 +1875,7 @@  discard block
 block discarded – undo
1876 1875
 		// read attachment data from etemplate request, use tmpname only to identify it
1877 1876
 		if (($request = Etemplate\Request::read($_GET['etemplate_exec_id'])))
1878 1877
 		{
1879
-			foreach($request->preserv['attachments'] as $attachment)
1878
+			foreach ($request->preserv['attachments'] as $attachment)
1880 1879
 			{
1881 1880
 				if ($_GET['tmpname'] === $attachment['tmp_name']) break;
1882 1881
 			}
@@ -1888,7 +1887,7 @@  discard block
 block discarded – undo
1888 1887
 		}
1889 1888
 
1890 1889
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
1891
-		if (parse_url($attachment['tmp_name'],PHP_URL_SCHEME) == 'vfs')
1890
+		if (parse_url($attachment['tmp_name'], PHP_URL_SCHEME) == 'vfs')
1892 1891
 		{
1893 1892
 			Vfs::load_wrapper('vfs');
1894 1893
 		}
@@ -1897,7 +1896,7 @@  discard block
 block discarded – undo
1897 1896
 		{
1898 1897
 			$attachment['tmp_name'] = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['tmp_name']);
1899 1898
 		}
1900
-		if(!file_exists($attachment['tmp_name']))
1899
+		if (!file_exists($attachment['tmp_name']))
1901 1900
 		{
1902 1901
 			header('HTTP/1.1 404 Not found');
1903 1902
 			die('Attachment '.htmlspecialchars($attachment['tmp_name']).' NOT found!');
@@ -1910,7 +1909,7 @@  discard block
 block discarded – undo
1910 1909
 			if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY')
1911 1910
 			{
1912 1911
 				$sfxMimeType = $attachment['type'];
1913
-				$buff = explode('.',$attachment['tmp_name']);
1912
+				$buff = explode('.', $attachment['tmp_name']);
1914 1913
 				$suffix = '';
1915 1914
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
1916 1915
 				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -1922,10 +1921,10 @@  discard block
 block discarded – undo
1922 1921
 			{
1923 1922
 				//error_log(__METHOD__."about to call calendar_ical");
1924 1923
 				$calendar_ical = new calendar_ical();
1925
-				$eventid = $calendar_ical->search($attachment['attachment'],-1);
1924
+				$eventid = $calendar_ical->search($attachment['attachment'], -1);
1926 1925
 				//error_log(__METHOD__.array2string($eventid));
1927 1926
 				if (!$eventid) $eventid = -1;
1928
-				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
1927
+				$event = $calendar_ical->importVCal($attachment['attachment'], (is_array($eventid) ? $eventid[0] : $eventid), null, true);
1929 1928
 				//error_log(__METHOD__.$event);
1930 1929
 				if ((int)$event > 0)
1931 1930
 				{
@@ -1933,7 +1932,7 @@  discard block
 block discarded – undo
1933 1932
 						'menuaction'      => 'calendar.calendar_uiforms.edit',
1934 1933
 						'cal_id'      => $event,
1935 1934
 					);
1936
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1935
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1937 1936
 				}
1938 1937
 				//Import failed, download content anyway
1939 1938
 			}
@@ -1948,13 +1947,13 @@  discard block
 block discarded – undo
1948 1947
 				{
1949 1948
 					$vcard['uid'] = trim($vcard['uid']);
1950 1949
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
1951
-					$contact = $addressbook_vcal->find_contact($vcard,false);
1950
+					$contact = $addressbook_vcal->find_contact($vcard, false);
1952 1951
 				}
1953 1952
 				if (!$contact) $contact = null;
1954 1953
 				// 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))
1955
-				if ($contact || count($vcard)>2)
1954
+				if ($contact || count($vcard) > 2)
1956 1955
 				{
1957
-					$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true);
1956
+					$contact = $addressbook_vcal->addVCard($attachment['attachment'], (is_array($contact) ?array_shift($contact) : $contact), true);
1958 1957
 				}
1959 1958
 				if ((int)$contact > 0)
1960 1959
 				{
@@ -1962,13 +1961,13 @@  discard block
 block discarded – undo
1962 1961
 						'menuaction'	=> 'addressbook.addressbook_ui.edit',
1963 1962
 						'contact_id'	=> $contact,
1964 1963
 					);
1965
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1964
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1966 1965
 				}
1967 1966
 				//Import failed, download content anyway
1968 1967
 			}
1969 1968
 		}
1970 1969
 		//error_log(__METHOD__.__LINE__.'->'.array2string($attachment));
1971
-		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size=0, true, $_GET['mode'] == "save");
1970
+		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size = 0, true, $_GET['mode'] == "save");
1972 1971
 		echo $attachment['attachment'];
1973 1972
 
1974 1973
 		exit();
@@ -1981,11 +1980,11 @@  discard block
 block discarded – undo
1981 1980
 	 * @param string haystack
1982 1981
 	 * @return boolean
1983 1982
 	 */
1984
-	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack) {
1983
+	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst, $haystack) {
1985 1984
 		foreach (array_keys($arrayToTestAgainst) as $k)
1986 1985
 		{
1987 1986
 			//error_log(__METHOD__.__LINE__.':'.$k.'<->'.$haystack);
1988
-			if (stripos($haystack,$k)!==false)
1987
+			if (stripos($haystack, $k) !== false)
1989 1988
 			{
1990 1989
 				//error_log(__METHOD__.__LINE__.':FOUND:'.$k.'<->'.$haystack.function_backtrace());
1991 1990
 				return true;
@@ -2008,10 +2007,10 @@  discard block
 block discarded – undo
2008 2007
 	 */
2009 2008
 	function getReplyData($_mode, $_icServer, $_folder, $_uid, $_partID)
2010 2009
 	{
2011
-		unset($_icServer);	// not used
2010
+		unset($_icServer); // not used
2012 2011
 		$foundAddresses = array();
2013 2012
 
2014
-		$mail_bo  = $this->mail_bo;
2013
+		$mail_bo = $this->mail_bo;
2015 2014
 		$mail_bo->openConnection();
2016 2015
 		$mail_bo->reopen($_folder);
2017 2016
 
@@ -2019,20 +2018,20 @@  discard block
 block discarded – undo
2019 2018
 
2020 2019
 		// get message headers for specified message
2021 2020
 		//print "AAAA: $_folder, $_uid, $_partID<br>";
2022
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder,$useHeaderInsteadOfEnvelope=true);
2021
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder, $useHeaderInsteadOfEnvelope = true);
2023 2022
 		//$headers	= $mail_bo->getMessageHeader($_uid, $_partID, true, true, $_folder);
2024 2023
 		$this->sessionData['uid'] = $_uid;
2025 2024
 		$this->sessionData['messageFolder'] = $_folder;
2026
-		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO']?$headers['IN-REPLY-TO']:$headers['MESSAGE_ID']);
2027
-		$this->sessionData['references'] = ($headers['REFERENCES']?$headers['REFERENCES']:$headers['MESSAGE_ID']);
2025
+		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO'] ? $headers['IN-REPLY-TO'] : $headers['MESSAGE_ID']);
2026
+		$this->sessionData['references'] = ($headers['REFERENCES'] ? $headers['REFERENCES'] : $headers['MESSAGE_ID']);
2028 2027
 
2029 2028
 		// break reference into multiple lines if they're greater than 998 chars
2030 2029
 		// and remove comma seperation. Fix error serer does not support binary
2031 2030
 		// data due to long references.
2032
-		if (strlen($this->sessionData['references'])> 998)
2031
+		if (strlen($this->sessionData['references']) > 998)
2033 2032
 		{
2034
-			$temp_refs = explode(',',$this->sessionData['references']);
2035
-			$this->sessionData['references'] = implode(" ",$temp_refs);
2033
+			$temp_refs = explode(',', $this->sessionData['references']);
2034
+			$this->sessionData['references'] = implode(" ", $temp_refs);
2036 2035
 		}
2037 2036
 
2038 2037
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
@@ -2042,36 +2041,36 @@  discard block
 block discarded – undo
2042 2041
 		if ($headers['LIST-ID']) $this->sessionData['list-id'] = $headers['LIST-ID'];
2043 2042
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_mode.':'.array2string($headers));
2044 2043
 		// check for Reply-To: header and use if available
2045
-		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2046
-			foreach($headers['REPLY-TO'] as $val) {
2047
-				if(!$foundAddresses[$val]) {
2044
+		if (!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2045
+			foreach ($headers['REPLY-TO'] as $val) {
2046
+				if (!$foundAddresses[$val]) {
2048 2047
 					$oldTo[] = $val;
2049 2048
 					$foundAddresses[$val] = true;
2050 2049
 				}
2051 2050
 			}
2052
-			$oldToAddress	= (is_array($headers['REPLY-TO'])?$headers['REPLY-TO'][0]:$headers['REPLY-TO']);
2051
+			$oldToAddress = (is_array($headers['REPLY-TO']) ? $headers['REPLY-TO'][0] : $headers['REPLY-TO']);
2053 2052
 		} else {
2054
-			foreach($headers['FROM'] as $val) {
2055
-				if(!$foundAddresses[$val]) {
2053
+			foreach ($headers['FROM'] as $val) {
2054
+				if (!$foundAddresses[$val]) {
2056 2055
 					$oldTo[] = $val;
2057 2056
 					$foundAddresses[$val] = true;
2058 2057
 				}
2059 2058
 			}
2060
-			$oldToAddress	= (is_array($headers['FROM'])?$headers['FROM'][0]:$headers['FROM']);
2059
+			$oldToAddress = (is_array($headers['FROM']) ? $headers['FROM'][0] : $headers['FROM']);
2061 2060
 		}
2062 2061
 		//error_log(__METHOD__.__LINE__.' OldToAddress:'.$oldToAddress.'#');
2063
-		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) ) {
2062
+		if ($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $oldToAddress))) {
2064 2063
 			$this->sessionData['to'] = $oldTo;
2065 2064
 		}
2066 2065
 
2067
-		if($_mode == 'all') {
2066
+		if ($_mode == 'all') {
2068 2067
 			// reply to any address which is cc, but not to my self
2069 2068
 			#if($headers->cc) {
2070
-				foreach($headers['CC'] as $val) {
2071
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2069
+				foreach ($headers['CC'] as $val) {
2070
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2072 2071
 						continue;
2073 2072
 					}
2074
-					if(!$foundAddresses[$val]) {
2073
+					if (!$foundAddresses[$val]) {
2075 2074
 						$this->sessionData['cc'][] = $val;
2076 2075
 						$foundAddresses[$val] = true;
2077 2076
 					}
@@ -2080,11 +2079,11 @@  discard block
 block discarded – undo
2080 2079
 
2081 2080
 			// reply to any address which is to, but not to my self
2082 2081
 			#if($headers->to) {
2083
-				foreach($headers['TO'] as $val) {
2084
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2082
+				foreach ($headers['TO'] as $val) {
2083
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2085 2084
 						continue;
2086 2085
 					}
2087
-					if(!$foundAddresses[$val]) {
2086
+					if (!$foundAddresses[$val]) {
2088 2087
 						$this->sessionData['to'][] = $val;
2089 2088
 						$foundAddresses[$val] = true;
2090 2089
 					}
@@ -2092,12 +2091,12 @@  discard block
 block discarded – undo
2092 2091
 			#}
2093 2092
 
2094 2093
 			#if($headers->from) {
2095
-				foreach($headers['FROM'] as $val) {
2096
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2094
+				foreach ($headers['FROM'] as $val) {
2095
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2097 2096
 						continue;
2098 2097
 					}
2099 2098
 					//error_log(__METHOD__.__LINE__.' '.$val);
2100
-					if(!$foundAddresses[$val]) {
2099
+					if (!$foundAddresses[$val]) {
2101 2100
 						$this->sessionData['to'][] = $val;
2102 2101
 						$foundAddresses[$val] = true;
2103 2102
 					}
@@ -2106,59 +2105,59 @@  discard block
 block discarded – undo
2106 2105
 		}
2107 2106
 
2108 2107
 		// check for Re: in subject header
2109
-		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2108
+		if (strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2110 2109
 			$this->sessionData['subject'] = $mail_bo->decode_header($headers['SUBJECT']);
2111 2110
 		} else {
2112
-			$this->sessionData['subject'] = "Re: " . $mail_bo->decode_header($headers['SUBJECT']);
2111
+			$this->sessionData['subject'] = "Re: ".$mail_bo->decode_header($headers['SUBJECT']);
2113 2112
 		}
2114 2113
 
2115 2114
 		//_debug_array($headers);
2116 2115
 		//error_log(__METHOD__.__LINE__.'->'.array2string($this->mailPreferences['htmlOptions']));
2117
-		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions']?$this->mailPreferences['htmlOptions']:''), $_partID);
2116
+		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions'] ? $this->mailPreferences['htmlOptions'] : ''), $_partID);
2118 2117
 		//_debug_array($bodyParts);
2119 2118
 		$styles = Mail::getStyles($bodyParts);
2120 2119
 
2121
-		$fromAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$headers['FROM']));
2120
+		$fromAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $headers['FROM']));
2122 2121
 
2123 2122
 		$toAddressA = array();
2124 2123
 		$toAddress = '';
2125 2124
 		foreach ($headers['TO'] as $mailheader) {
2126
-			$toAddressA[] =  $mailheader;
2125
+			$toAddressA[] = $mailheader;
2127 2126
 		}
2128
-		if (count($toAddressA)>0)
2127
+		if (count($toAddressA) > 0)
2129 2128
 		{
2130
-			$toAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$toAddressA));
2131
-			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2129
+			$toAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $toAddressA));
2130
+			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2132 2131
 		}
2133 2132
 		$ccAddressA = array();
2134 2133
 		$ccAddress = '';
2135 2134
 		foreach ($headers['CC'] as $mailheader) {
2136
-			$ccAddressA[] =  $mailheader;
2135
+			$ccAddressA[] = $mailheader;
2137 2136
 		}
2138
-		if (count($ccAddressA)>0)
2137
+		if (count($ccAddressA) > 0)
2139 2138
 		{
2140
-			$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA));
2141
-			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2139
+			$ccAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $ccAddressA));
2140
+			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2142 2141
 		}
2143
-		if($bodyParts['0']['mimeType'] == 'text/html') {
2144
-			$this->sessionData['body']	= /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2142
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
2143
+			$this->sessionData['body'] = /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2145 2144
 				@htmlspecialchars(lang("from")).": ".$fromAddress."<br>".
2146 2145
 				$toAddress.$ccAddress.
2147
-				@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>".
2146
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."<br>".
2148 2147
 				'----------------------------------------------------------'."</div>";
2149
-			$this->sessionData['mimeType'] 	= 'html';
2148
+			$this->sessionData['mimeType'] = 'html';
2150 2149
 			if (!empty($styles)) $this->sessionData['body'] .= $styles;
2151
-			$this->sessionData['body']	.= '<blockquote type="cite">';
2150
+			$this->sessionData['body'] .= '<blockquote type="cite">';
2152 2151
 
2153
-			for($i=0; $i<count($bodyParts); $i++) {
2154
-				if($i>0) {
2152
+			for ($i = 0; $i < count($bodyParts); $i++) {
2153
+				if ($i > 0) {
2155 2154
 					$this->sessionData['body'] .= '<hr>';
2156 2155
 				}
2157
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
2156
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
2158 2157
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>";
2159 2158
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
2160 2159
 				}
2161
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2160
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2162 2161
 
2163 2162
 				$_htmlConfig = Mail::$htmLawed_config;
2164 2163
 				Mail::$htmLawed_config['comment'] = 2;
@@ -2168,30 +2167,30 @@  discard block
 block discarded – undo
2168 2167
 				#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2169 2168
 			}
2170 2169
 
2171
-			$this->sessionData['body']	.= '</blockquote><br>';
2172
-			$this->sessionData['body'] =  mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2170
+			$this->sessionData['body'] .= '</blockquote><br>';
2171
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2173 2172
 		} else {
2174 2173
 			//$this->sessionData['body']	= @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n";
2175 2174
 			// 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)
2176
-            $this->sessionData['body']  = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2175
+            $this->sessionData['body'] = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2177 2176
                 @htmlspecialchars(lang("from")).": ".$fromAddress."\r\n".
2178 2177
 				$toAddress.$ccAddress.
2179
-				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
2178
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."\r\n".
2180 2179
                 '-------------------------------------------------'."\r\n \r\n ";
2181
-			$this->sessionData['mimeType']	= 'plain';
2180
+			$this->sessionData['mimeType'] = 'plain';
2182 2181
 
2183
-			for($i=0; $i<count($bodyParts); $i++) {
2184
-				if($i>0) {
2182
+			for ($i = 0; $i < count($bodyParts); $i++) {
2183
+				if ($i > 0) {
2185 2184
 					$this->sessionData['body'] .= "<hr>";
2186 2185
 				}
2187 2186
 
2188 2187
 				// add line breaks to $bodyParts
2189
-				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']);
2188
+				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
2190 2189
 				#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2191 2190
 				$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
2192 2191
 				$this->sessionData['body'] .= "\r\n";
2193 2192
 				// create body new, with good line breaks and indention
2194
-				foreach(explode("\n",$newBody) as $value) {
2193
+				foreach (explode("\n", $newBody) as $value) {
2195 2194
 					// the explode is removing the character
2196 2195
 					if (trim($value) != '') {
2197 2196
 						#if ($value != "\r") $value .= "\n";
@@ -2199,12 +2198,12 @@  discard block
 block discarded – undo
2199 2198
 					$numberOfChars = strspn(trim($value), ">");
2200 2199
 					$appendString = str_repeat('>', $numberOfChars + 1);
2201 2200
 
2202
-					$bodyAppend = $this->mail_bo->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
2201
+					$bodyAppend = $this->mail_bo->wordwrap($value, 76 - strlen("\r\n$appendString "), "\r\n$appendString ", '>');
2203 2202
 
2204
-					if($bodyAppend[0] == '>') {
2205
-						$bodyAppend = '>'. $bodyAppend;
2203
+					if ($bodyAppend[0] == '>') {
2204
+						$bodyAppend = '>'.$bodyAppend;
2206 2205
 					} else {
2207
-						$bodyAppend = '> '. $bodyAppend;
2206
+						$bodyAppend = '> '.$bodyAppend;
2208 2207
 					}
2209 2208
 
2210 2209
 					$this->sessionData['body'] .= $bodyAppend;
@@ -2227,16 +2226,16 @@  discard block
 block discarded – undo
2227 2226
 	 */
2228 2227
 	static function _getCleanHTML($_body, $_useTidy = false)
2229 2228
 	{
2230
-		static $nonDisplayAbleCharacters = array('[\016]','[\017]',
2231
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2232
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
2229
+		static $nonDisplayAbleCharacters = array('[\016]', '[\017]',
2230
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
2231
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2233 2232
 
2234
-		if ($_useTidy && extension_loaded('tidy') )
2233
+		if ($_useTidy && extension_loaded('tidy'))
2235 2234
 		{
2236 2235
 			$tidy = new tidy();
2237
-			$cleaned = $tidy->repairString($_body, Mail::$tidy_config,'utf8');
2236
+			$cleaned = $tidy->repairString($_body, Mail::$tidy_config, 'utf8');
2238 2237
 			// Found errors. Strip it all so there's some output
2239
-			if($tidy->getStatus() == 2)
2238
+			if ($tidy->getStatus() == 2)
2240 2239
 			{
2241 2240
 				error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
2242 2241
 			}
@@ -2270,13 +2269,13 @@  discard block
 block discarded – undo
2270 2269
 	 *
2271 2270
 	 * @return array returns found inline images as attachment structure
2272 2271
 	 */
2273
-	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving=false)
2272
+	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving = false)
2274 2273
 	{
2275 2274
 		if (substr($_formData['body'], 0, 27) == '-----BEGIN PGP MESSAGE-----')
2276 2275
 		{
2277 2276
 			$_formData['mimeType'] = 'openpgp';
2278 2277
 		}
2279
-		$mail_bo	= $this->mail_bo;
2278
+		$mail_bo = $this->mail_bo;
2280 2279
 		$activeMailProfile = Mail\Account::read($this->mail_bo->profileID);
2281 2280
 
2282 2281
 		// you need to set the sender, if you work with different identities, since most smtp servers, dont allow
@@ -2285,37 +2284,37 @@  discard block
 block discarded – undo
2285 2284
 		{
2286 2285
 			error_log(__METHOD__.__LINE__.' Faking From/SenderInfo for '.$activeMailProfile['ident_email'].' with ID:'.$activeMailProfile['ident_id'].'. Identitiy to use for sending:'.array2string($_identity));
2287 2286
 		}
2288
-		$email_From =  $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2287
+		$email_From = $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2289 2288
 		// Try to fix identity email with no domain part set
2290 2289
 		$_mailObject->setFrom(Mail::fixInvalidAliasAddress(Api\Accounts::id2name($_identity['account_id'], 'account_email'), $email_From),
2291
-			Mail::generateIdentityString($_identity,false));
2290
+			Mail::generateIdentityString($_identity, false));
2292 2291
 
2293 2292
 		$_mailObject->addHeader('X-Priority', $_formData['priority']);
2294 2293
 		$_mailObject->addHeader('X-Mailer', 'EGroupware-Mail');
2295
-		if(!empty($_formData['in-reply-to'])) {
2296
-			if (stripos($_formData['in-reply-to'],'<')===false) $_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2294
+		if (!empty($_formData['in-reply-to'])) {
2295
+			if (stripos($_formData['in-reply-to'], '<') === false) $_formData['in-reply-to'] = '<'.trim($_formData['in-reply-to']).'>';
2297 2296
 			$_mailObject->addHeader('In-Reply-To', $_formData['in-reply-to']);
2298 2297
 		}
2299
-		if(!empty($_formData['references'])) {
2300
-			if (stripos($_formData['references'],'<')===false)
2298
+		if (!empty($_formData['references'])) {
2299
+			if (stripos($_formData['references'], '<') === false)
2301 2300
 			{
2302
-				$_formData['references']='<'.trim($_formData['references']).'>';
2301
+				$_formData['references'] = '<'.trim($_formData['references']).'>';
2303 2302
 			}
2304 2303
 			$_mailObject->addHeader('References', $_formData['references']);
2305 2304
 		}
2306 2305
 
2307
-		if(!empty($_formData['thread-index'])) {
2306
+		if (!empty($_formData['thread-index'])) {
2308 2307
 			$_mailObject->addHeader('Thread-Index', $_formData['thread-index']);
2309 2308
 		}
2310
-		if(!empty($_formData['list-id'])) {
2309
+		if (!empty($_formData['list-id'])) {
2311 2310
 			$_mailObject->addHeader('List-Id', $_formData['list-id']);
2312 2311
 		}
2313
-		if($_formData['disposition']=='on') {
2312
+		if ($_formData['disposition'] == 'on') {
2314 2313
 			$_mailObject->addHeader('Disposition-Notification-To', $_identity['ident_email']);
2315 2314
 		}
2316 2315
 
2317 2316
 		// Expand any mailing lists
2318
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $field)
2317
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $field)
2319 2318
 		{
2320 2319
 			if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2321 2320
 
@@ -2331,7 +2330,7 @@  discard block
 block discarded – undo
2331 2330
 		}
2332 2331
 		$disableRuler = false;
2333 2332
 		$signature = $_identity['ident_signature'];
2334
-		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend'?1:0;
2333
+		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' ? 1 : 0;
2335 2334
 		if ($sigAlreadyThere)
2336 2335
 		{
2337 2336
 			// note: if you use stationery ' s the insert signatures at the top does not apply here anymore, as the signature
@@ -2340,7 +2339,7 @@  discard block
 block discarded – undo
2340 2339
 		}
2341 2340
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
2342 2341
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
2343
-			empty($signature) || trim($this->convertHTMLToText($signature)) =='')
2342
+			empty($signature) || trim($this->convertHTMLToText($signature)) == '')
2344 2343
 		{
2345 2344
 			$disableRuler = true;
2346 2345
 		}
@@ -2351,7 +2350,7 @@  discard block
 block discarded – undo
2351 2350
 				array_unique(array_merge((array)$_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc'])),
2352 2351
 				$_formData['expiration'], $_formData['password']);
2353 2352
 		}
2354
-		if($_formData['mimeType'] == 'html')
2353
+		if ($_formData['mimeType'] == 'html')
2355 2354
 		{
2356 2355
 			$body = $_formData['body'];
2357 2356
 			if ($attachment_links)
@@ -2365,13 +2364,13 @@  discard block
 block discarded – undo
2365 2364
 					$body .= $attachment_links;
2366 2365
 				}
2367 2366
 			}
2368
-			if(!empty($signature))
2367
+			if (!empty($signature))
2369 2368
 			{
2370 2369
 				$_mailObject->setBody($this->convertHTMLToText($body, true, true).
2371 2370
 					($disableRuler ? "\r\n" : "\r\n-- \r\n").
2372 2371
 					$this->convertHTMLToText($signature, true, true));
2373 2372
 
2374
-				$body .= ($disableRuler ?'<br>':'<hr style="border:1px dotted silver; width:90%;">').$signature;
2373
+				$body .= ($disableRuler ? '<br>' : '<hr style="border:1px dotted silver; width:90%;">').$signature;
2375 2374
 			}
2376 2375
 			else
2377 2376
 			{
@@ -2379,11 +2378,11 @@  discard block
 block discarded – undo
2379 2378
 			}
2380 2379
 			// convert URL Images to inline images - if possible
2381 2380
 			if (!$_autosaving) $inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2382
-			if (strpos($body,"<!-- HTMLSIGBEGIN -->")!==false)
2381
+			if (strpos($body, "<!-- HTMLSIGBEGIN -->") !== false)
2383 2382
 			{
2384
-				$body = str_replace(array('<!-- HTMLSIGBEGIN -->','<!-- HTMLSIGEND -->'),'',$body);
2383
+				$body = str_replace(array('<!-- HTMLSIGBEGIN -->', '<!-- HTMLSIGEND -->'), '', $body);
2385 2384
 			}
2386
-			$_mailObject->setHtmlBody($body, null, false);	// false = no automatic alternative, we called setBody()
2385
+			$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
2387 2386
 		}
2388 2387
 		elseif ($_formData['mimeType'] == 'openpgp')
2389 2388
 		{
@@ -2391,14 +2390,14 @@  discard block
 block discarded – undo
2391 2390
 		}
2392 2391
 		else
2393 2392
 		{
2394
-			$body = $this->convertHTMLToText($_formData['body'],false);
2393
+			$body = $this->convertHTMLToText($_formData['body'], false);
2395 2394
 
2396 2395
 			if ($attachment_links) $body .= $attachment_links;
2397 2396
 
2398 2397
 			#$_mailObject->Body = $_formData['body'];
2399
-			if(!empty($signature)) {
2400
-				$body .= ($disableRuler ?"\r\n":"\r\n-- \r\n").
2401
-					$this->convertHTMLToText($signature,true,true);
2398
+			if (!empty($signature)) {
2399
+				$body .= ($disableRuler ? "\r\n" : "\r\n-- \r\n").
2400
+					$this->convertHTMLToText($signature, true, true);
2402 2401
 			}
2403 2402
 			$_mailObject->setBody($body);
2404 2403
 		}
@@ -2407,8 +2406,8 @@  discard block
 block discarded – undo
2407 2406
 		{
2408 2407
 			$connection_opened = false;
2409 2408
 			$tnfattachments = null;
2410
-			foreach((array)$_formData['attachments'] as $attachment) {
2411
-				if(is_array($attachment))
2409
+			foreach ((array)$_formData['attachments'] as $attachment) {
2410
+				if (is_array($attachment))
2412 2411
 				{
2413 2412
 					if (!empty($attachment['uid']) && !empty($attachment['folder'])) {
2414 2413
 						/* Example:
@@ -2426,20 +2425,20 @@  discard block
 block discarded – undo
2426 2425
 							$connection_opened = true;
2427 2426
 						}
2428 2427
 						$mail_bo->reopen($attachment['folder']);
2429
-						switch(strtoupper($attachment['type'])) {
2428
+						switch (strtoupper($attachment['type'])) {
2430 2429
 							case 'MESSAGE/RFC':
2431 2430
 							case 'MESSAGE/RFC822':
2432
-								$rawBody='';
2431
+								$rawBody = '';
2433 2432
 								if (isset($attachment['partID'])) {
2434
-									$eml = $mail_bo->getAttachment($attachment['uid'],$attachment['partID'],0,false,true,$attachment['folder']);
2435
-									$rawBody=$eml['attachment'];
2433
+									$eml = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false, true, $attachment['folder']);
2434
+									$rawBody = $eml['attachment'];
2436 2435
 								} else {
2437
-									$rawBody        = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'],$attachment['folder']);
2436
+									$rawBody = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'], $attachment['folder']);
2438 2437
 								}
2439 2438
 								$_mailObject->addStringAttachment($rawBody, $attachment['name'], 'message/rfc822');
2440 2439
 								break;
2441 2440
 							default:
2442
-								$attachmentData	= $mail_bo->getAttachment($attachment['uid'], $attachment['partID'],0,false);
2441
+								$attachmentData = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false);
2443 2442
 								if ($attachmentData['type'] == 'APPLICATION/MS-TNEF')
2444 2443
 								{
2445 2444
 									if (!is_array($tnfattachments)) $tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
@@ -2447,7 +2446,7 @@  discard block
 block discarded – undo
2447 2446
 									{
2448 2447
 										if ($k['name'] == $attachment['name'])
2449 2448
 										{
2450
-											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'],$k['is_winmail']);
2449
+											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'], $k['is_winmail']);
2451 2450
 											$attachmentData['attachment'] = $tnfpart['attachment'];
2452 2451
 											break;
2453 2452
 										}
@@ -2460,7 +2459,7 @@  discard block
 block discarded – undo
2460 2459
 					// attach files not for autosaving
2461 2460
 					elseif ($_formData['filemode'] == Vfs\Sharing::ATTACH && !$_autosaving)
2462 2461
 					{
2463
-						if (isset($attachment['file']) && parse_url($attachment['file'],PHP_URL_SCHEME) == 'vfs')
2462
+						if (isset($attachment['file']) && parse_url($attachment['file'], PHP_URL_SCHEME) == 'vfs')
2464 2463
 						{
2465 2464
 							Vfs::load_wrapper('vfs');
2466 2465
 							$tmp_path = $attachment['file'];
@@ -2469,7 +2468,7 @@  discard block
 block discarded – undo
2469 2468
 						{
2470 2469
 							$tmp_path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['file']);
2471 2470
 						}
2472
-						$_mailObject->addAttachment (
2471
+						$_mailObject->addAttachment(
2473 2472
 							$tmp_path,
2474 2473
 							$attachment['name'],
2475 2474
 							$attachment['type']
@@ -2479,7 +2478,7 @@  discard block
 block discarded – undo
2479 2478
 			}
2480 2479
 			if ($connection_opened) $mail_bo->closeConnection();
2481 2480
 		}
2482
-		return is_array($inline_images)?$inline_images:array();
2481
+		return is_array($inline_images) ? $inline_images : array();
2483 2482
 	}
2484 2483
 
2485 2484
 	/**
@@ -2495,16 +2494,16 @@  discard block
 block discarded – undo
2495 2494
 	 * @param string $password =null
2496 2495
 	 * @return string might be empty if no file attachments found
2497 2496
 	 */
2498
-	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
2497
+	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients = array(), $expiration = null, $password = null)
2499 2498
 	{
2500 2499
 		if ($filemode == Vfs\Sharing::ATTACH) return '';
2501 2500
 
2502 2501
 		$links = array();
2503
-		foreach($attachments as $attachment)
2502
+		foreach ($attachments as $attachment)
2504 2503
 		{
2505 2504
 			$path = $attachment['file'];
2506
-			if (empty($path)) continue;	// we only care about file attachments, not forwarded messages or parts
2507
-			if (parse_url($attachment['file'],PHP_URL_SCHEME) != 'vfs')
2505
+			if (empty($path)) continue; // we only care about file attachments, not forwarded messages or parts
2506
+			if (parse_url($attachment['file'], PHP_URL_SCHEME) != 'vfs')
2508 2507
 			{
2509 2508
 				$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($path);
2510 2509
 			}
@@ -2534,7 +2533,7 @@  discard block
 block discarded – undo
2534 2533
 		}
2535 2534
 		if (!$links)
2536 2535
 		{
2537
-			return null;	// no file attachments found
2536
+			return null; // no file attachments found
2538 2537
 		}
2539 2538
 		elseif ($html)
2540 2539
 		{
@@ -2549,7 +2548,7 @@  discard block
 block discarded – undo
2549 2548
 	 * @param array $content content sent from client-side
2550 2549
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2551 2550
 	 */
2552
-	public function ajax_saveAsDraft ($content, $action='button[saveAsDraft]')
2551
+	public function ajax_saveAsDraft($content, $action = 'button[saveAsDraft]')
2553 2552
 	{
2554 2553
 		//error_log(__METHOD__.__LINE__.array2string($content)."(, action=$action)");
2555 2554
 		$response = Api\Json\Response::get();
@@ -2563,8 +2562,8 @@  discard block
 block discarded – undo
2563 2562
 
2564 2563
 		$formData = array_merge($content, array(
2565 2564
 			'isDrafted' => 1,
2566
-			'body' => $content['mail_'.($content['mimeType']?'htmltext':'plaintext')],
2567
-			'mimeType' => $content['mimeType']?'html':'plain' // checkbox has only true|false value
2565
+			'body' => $content['mail_'.($content['mimeType'] ? 'htmltext' : 'plaintext')],
2566
+			'mimeType' => $content['mimeType'] ? 'html' : 'plain' // checkbox has only true|false value
2568 2567
 		));
2569 2568
 
2570 2569
 		//Saving draft procedure
@@ -2576,8 +2575,8 @@  discard block
 block discarded – undo
2576 2575
 			if (($messageUid = $this->saveAsDraft($formData, $folder, $action)))
2577 2576
 			{
2578 2577
 				// saving as draft, does not mean closing the message
2579
-				$messageUid = ($messageUid===true ? $status['uidnext'] : $messageUid);
2580
-				if (is_array($this->mail_bo->getMessageHeader($messageUid, '',false, false, $folder)))
2578
+				$messageUid = ($messageUid === true ? $status['uidnext'] : $messageUid);
2579
+				if (is_array($this->mail_bo->getMessageHeader($messageUid, '', false, false, $folder)))
2581 2580
 				{
2582 2581
 					$draft_id = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $messageUid);
2583 2582
 					if ($content['lastDrafted'] != $draft_id && isset($content['lastDrafted']))
@@ -2586,7 +2585,7 @@  discard block
 block discarded – undo
2586 2585
 						$duid = $dhA['msgUID'];
2587 2586
 						$dmailbox = $dhA['folder'];
2588 2587
 						// beware: do not delete the original mail as found in processedmail_id
2589
-						$pMuid='';
2588
+						$pMuid = '';
2590 2589
 						if ($content['processedmail_id'])
2591 2590
 						{
2592 2591
 							$pMhA = mail_ui::splitRowID($content['processedmail_id']);
@@ -2594,15 +2593,15 @@  discard block
 block discarded – undo
2594 2593
 						}
2595 2594
 						//error_log(__METHOD__.__LINE__."#$pMuid#$pMuid!=$duid#".array2string($content['attachments']));
2596 2595
 						// do not delete the original message if attachments are present
2597
-						if (empty($pMuid) || $pMuid!=$duid || empty($content['attachments']))
2596
+						if (empty($pMuid) || $pMuid != $duid || empty($content['attachments']))
2598 2597
 						{
2599 2598
 							try
2600 2599
 							{
2601
-								$this->mail_bo->deleteMessages($duid,$dmailbox,'remove_immediately');
2600
+								$this->mail_bo->deleteMessages($duid, $dmailbox, 'remove_immediately');
2602 2601
 							}
2603 2602
 							catch (Api\Exception $e)
2604 2603
 							{
2605
-								$msg = str_replace('"',"'",$e->getMessage());
2604
+								$msg = str_replace('"', "'", $e->getMessage());
2606 2605
 								$success = false;
2607 2606
 								error_log(__METHOD__.__LINE__.$msg);
2608 2607
 							}
@@ -2623,7 +2622,7 @@  discard block
 block discarded – undo
2623 2622
 		}
2624 2623
 		catch (Api\Exception\WrongUserinput $e)
2625 2624
 		{
2626
-			$msg = str_replace('"',"'",$e->getMessage());
2625
+			$msg = str_replace('"', "'", $e->getMessage());
2627 2626
 			error_log(__METHOD__.__LINE__.$msg);
2628 2627
 			$success = false;
2629 2628
 		}
@@ -2647,17 +2646,17 @@  discard block
 block discarded – undo
2647 2646
 	static function resolveEmailAddressList($_emailAddressList)
2648 2647
 	{
2649 2648
 		$contacts_obs = null;
2650
-		$addrFromList=array();
2651
-		foreach((array)$_emailAddressList as $ak => $address)
2649
+		$addrFromList = array();
2650
+		foreach ((array)$_emailAddressList as $ak => $address)
2652 2651
 		{
2653
-			if(is_int($address))
2652
+			if (is_int($address))
2654 2653
 			{
2655 2654
 				if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts();
2656 2655
 				// List was selected, expand to addresses
2657 2656
 				unset($_emailAddressList[$ak]);
2658
-				$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
+				$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));
2659 2658
 				// Just add email addresses, they'll be checked below
2660
-				foreach($list as $email)
2659
+				foreach ($list as $email)
2661 2660
 				{
2662 2661
 					$addrFromList[] = $email['email'] ? $email['email'] : $email['email_home'];
2663 2662
 				}
@@ -2667,7 +2666,7 @@  discard block
 block discarded – undo
2667 2666
 		{
2668 2667
 			foreach ($addrFromList as $addr)
2669 2668
 			{
2670
-				if (!empty($addr)) $_emailAddressList[]=$addr;
2669
+				if (!empty($addr)) $_emailAddressList[] = $addr;
2671 2670
 			}
2672 2671
 		}
2673 2672
 		return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList;
@@ -2681,15 +2680,15 @@  discard block
 block discarded – undo
2681 2680
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2682 2681
 	 * @return boolean return messageUID| false due to an error
2683 2682
 	 */
2684
-	function saveAsDraft($_formData, &$savingDestination='', $action='button[saveAsDraft]')
2683
+	function saveAsDraft($_formData, &$savingDestination = '', $action = 'button[saveAsDraft]')
2685 2684
 	{
2686 2685
 		//error_log(__METHOD__."(..., $savingDestination, action=$action)");
2687
-		$mail_bo	= $this->mail_bo;
2688
-		$mail		= new Api\Mailer($this->mail_bo->profileID);
2686
+		$mail_bo = $this->mail_bo;
2687
+		$mail = new Api\Mailer($this->mail_bo->profileID);
2689 2688
 
2690 2689
 		// preserve the bcc and if possible the save to folder information
2691
-		$this->sessionData['folder']    = $_formData['folder'];
2692
-		$this->sessionData['bcc']   = $_formData['bcc'];
2690
+		$this->sessionData['folder'] = $_formData['folder'];
2691
+		$this->sessionData['bcc'] = $_formData['bcc'];
2693 2692
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2694 2693
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2695 2694
 		$this->sessionData['mailaccount']  = $_formData['mailaccount'];
@@ -2698,11 +2697,11 @@  discard block
 block discarded – undo
2698 2697
 		{
2699 2698
 			$acc = Mail\Account::read($this->sessionData['mailaccount']);
2700 2699
 			//error_log(__METHOD__.__LINE__.array2string($acc));
2701
-			$identity = Mail\Account::read_identity($acc['ident_id'],true);
2700
+			$identity = Mail\Account::read_identity($acc['ident_id'], true);
2702 2701
 		}
2703 2702
 		catch (Exception $e)
2704 2703
 		{
2705
-			$identity=array();
2704
+			$identity = array();
2706 2705
 		}
2707 2706
 
2708 2707
 		$flags = '\\Seen \\Draft';
@@ -2712,7 +2711,7 @@  discard block
 block discarded – undo
2712 2711
 		// folder list as Customheader
2713 2712
 		if (!empty($this->sessionData['folder']))
2714 2713
 		{
2715
-			$folders = implode('|',array_unique($this->sessionData['folder']));
2714
+			$folders = implode('|', array_unique($this->sessionData['folder']));
2716 2715
 			$mail->addHeader('X-Mailfolder', $folders);
2717 2716
 		}
2718 2717
 		$mail->addHeader('X-Mailidentity', $this->sessionData['mailidentity']);
@@ -2732,25 +2731,25 @@  discard block
 block discarded – undo
2732 2731
 			$savingDestination = $this->sessionData['messageFolder'];
2733 2732
 			//error_log(__METHOD__.__LINE__.' SavingDestination:'.$savingDestination);
2734 2733
 		}
2735
-		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 ) $savingDestination = $mail_bo->getDraftFolder();
2734
+		if (!empty($_formData['printit']) && $_formData['printit'] == 0) $savingDestination = $mail_bo->getDraftFolder();
2736 2735
 
2737 2736
 		// normaly Bcc is only added to recipients, but not as header visible to all recipients
2738 2737
 		$mail->forceBccHeader();
2739 2738
 
2740 2739
 		$mail_bo->openConnection();
2741
-		if ($mail_bo->folderExists($savingDestination,true)) {
2740
+		if ($mail_bo->folderExists($savingDestination, true)) {
2742 2741
 			try
2743 2742
 			{
2744 2743
 				$messageUid = $mail_bo->appendMessage($savingDestination, $mail->getRaw(), null, $flags);
2745 2744
 			}
2746 2745
 			catch (Api\Exception\WrongUserinput $e)
2747 2746
 			{
2748
-				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
+				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", __METHOD__, $savingDestination, $e->getMessage()));
2749 2748
 				return false;
2750 2749
 			}
2751 2750
 
2752 2751
 		} else {
2753
-			error_log(__METHOD__.__LINE__."->".lang("folder")." ". $savingDestination." ".lang("does not exist on IMAP Server."));
2752
+			error_log(__METHOD__.__LINE__."->".lang("folder")." ".$savingDestination." ".lang("does not exist on IMAP Server."));
2754 2753
 			return false;
2755 2754
 		}
2756 2755
 		$mail_bo->closeConnection();
@@ -2759,26 +2758,26 @@  discard block
 block discarded – undo
2759 2758
 
2760 2759
 	function send($_formData)
2761 2760
 	{
2762
-		$mail_bo	= $this->mail_bo;
2763
-		$mail 		= new Api\Mailer($mail_bo->profileID);
2764
-		$messageIsDraft	=  false;
2761
+		$mail_bo = $this->mail_bo;
2762
+		$mail = new Api\Mailer($mail_bo->profileID);
2763
+		$messageIsDraft = false;
2765 2764
 
2766
-		$this->sessionData['mailaccount']	= $_formData['mailaccount'];
2765
+		$this->sessionData['mailaccount'] = $_formData['mailaccount'];
2767 2766
 		$this->sessionData['to']	= self::resolveEmailAddressList($_formData['to']);
2768 2767
 		$this->sessionData['cc']	= self::resolveEmailAddressList($_formData['cc']);
2769
-		$this->sessionData['bcc']	= self::resolveEmailAddressList($_formData['bcc']);
2770
-		$this->sessionData['folder']	= $_formData['folder'];
2768
+		$this->sessionData['bcc'] = self::resolveEmailAddressList($_formData['bcc']);
2769
+		$this->sessionData['folder'] = $_formData['folder'];
2771 2770
 		$this->sessionData['replyto']	= $_formData['replyto'];
2772 2771
 		$this->sessionData['subject']	= trim($_formData['subject']);
2773
-		$this->sessionData['body']	= $_formData['body'];
2774
-		$this->sessionData['priority']	= $_formData['priority'];
2772
+		$this->sessionData['body'] = $_formData['body'];
2773
+		$this->sessionData['priority'] = $_formData['priority'];
2775 2774
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2776 2775
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2777 2776
 		$this->sessionData['disposition'] = $_formData['disposition'];
2778
-		$this->sessionData['mimeType']	= $_formData['mimeType'];
2777
+		$this->sessionData['mimeType'] = $_formData['mimeType'];
2779 2778
 		$this->sessionData['to_infolog'] = $_formData['to_infolog'];
2780 2779
 		$this->sessionData['to_tracker'] = $_formData['to_tracker'];
2781
-		$this->sessionData['attachments']  = $_formData['attachments'];
2780
+		$this->sessionData['attachments'] = $_formData['attachments'];
2782 2781
 
2783 2782
 		if (isset($_formData['lastDrafted']) && !empty($_formData['lastDrafted']))
2784 2783
 		{
@@ -2787,11 +2786,11 @@  discard block
 block discarded – undo
2787 2786
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_formData['mode'].' PID:'.$_formData['processedmail_id']);
2788 2787
 		if (isset($_formData['mode']) && !empty($_formData['mode']))
2789 2788
 		{
2790
-			if ($_formData['mode']=='forward' && !empty($_formData['processedmail_id']))
2789
+			if ($_formData['mode'] == 'forward' && !empty($_formData['processedmail_id']))
2791 2790
 			{
2792
-				$this->sessionData['forwardFlag']='forwarded';
2793
-				$_formData['processedmail_id'] = explode(',',$_formData['processedmail_id']);
2794
-				$this->sessionData['uid']=array();
2791
+				$this->sessionData['forwardFlag'] = 'forwarded';
2792
+				$_formData['processedmail_id'] = explode(',', $_formData['processedmail_id']);
2793
+				$this->sessionData['uid'] = array();
2795 2794
 				foreach ($_formData['processedmail_id'] as $k =>$rowid)
2796 2795
 				{
2797 2796
 					$fhA = mail_ui::splitRowID($rowid);
@@ -2800,13 +2799,13 @@  discard block
 block discarded – undo
2800 2799
 					if (!empty($fhA['folder'])) $this->sessionData['sourceFolder'] = $fhA['folder'];
2801 2800
 				}
2802 2801
 			}
2803
-			if ($_formData['mode']=='reply' && !empty($_formData['processedmail_id']))
2802
+			if ($_formData['mode'] == 'reply' && !empty($_formData['processedmail_id']))
2804 2803
 			{
2805 2804
 				$rhA = mail_ui::splitRowID($_formData['processedmail_id']);
2806 2805
 				$this->sessionData['uid'] = $rhA['msgUID'];
2807 2806
 				$this->sessionData['messageFolder'] = $rhA['folder'];
2808 2807
 			}
2809
-			if ($_formData['mode']=='composefromdraft' && !empty($_formData['processedmail_id']))
2808
+			if ($_formData['mode'] == 'composefromdraft' && !empty($_formData['processedmail_id']))
2810 2809
 			{
2811 2810
 				$dhA = mail_ui::splitRowID($_formData['processedmail_id']);
2812 2811
 				$this->sessionData['uid'] = $dhA['msgUID'];
@@ -2815,26 +2814,26 @@  discard block
 block discarded – undo
2815 2814
 		}
2816 2815
 		// if the body is empty, maybe someone pasted something with scripts, into the message body
2817 2816
 		// this should not happen anymore, unless you call send directly, since the check was introduced with the action command
2818
-		if(empty($this->sessionData['body']))
2817
+		if (empty($this->sessionData['body']))
2819 2818
 		{
2820 2819
 			// this is to be found with the egw_unset_vars array for the _POST['body'] array
2821
-			$name='_POST';
2822
-			$key='body';
2820
+			$name = '_POST';
2821
+			$key = 'body';
2823 2822
 			#error_log($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2824 2823
 			if (isset($GLOBALS['egw_unset_vars'][$name.'['.$key.']']))
2825 2824
 			{
2826
-				$this->sessionData['body'] = self::_getCleanHTML( $GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2827
-				$_formData['body']=$this->sessionData['body'];
2825
+				$this->sessionData['body'] = self::_getCleanHTML($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2826
+				$_formData['body'] = $this->sessionData['body'];
2828 2827
 			}
2829 2828
 			#error_log($this->sessionData['body']);
2830 2829
 		}
2831
-		if(empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2830
+		if (empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2832 2831
 		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder'])) {
2833 2832
 		   	$messageIsDraft = true;
2834 2833
 		}
2835 2834
 		try
2836 2835
 		{
2837
-			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'],true);
2836
+			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'], true);
2838 2837
 		}
2839 2838
 		catch (Exception $e)
2840 2839
 		{
@@ -2845,7 +2844,7 @@  discard block
 block discarded – undo
2845 2844
 		// create the messages and store inline images
2846 2845
 		$inline_images = $this->createMessage($mail, $_formData, $identity);
2847 2846
 		// remember the identity
2848
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2847
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From; //$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2849 2848
 		#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
2850 2849
 		#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";
2851 2850
 		#exit;
@@ -2856,12 +2855,12 @@  discard block
 block discarded – undo
2856 2855
 		$folderOnMailAccount = array();
2857 2856
 		foreach ($folderToCheck as $k => $f)
2858 2857
 		{
2859
-			$fval=$f;
2860
-			$icServerID = $_formData['serverID'];//folders always assumed with serverID
2861
-			if (stripos($f,'::')!==false) list($icServerID,$fval) = explode('::',$f,2);
2862
-			if ($_formData['serverID']!=$_formData['mailaccount'])
2858
+			$fval = $f;
2859
+			$icServerID = $_formData['serverID']; //folders always assumed with serverID
2860
+			if (stripos($f, '::') !== false) list($icServerID, $fval) = explode('::', $f, 2);
2861
+			if ($_formData['serverID'] != $_formData['mailaccount'])
2863 2862
 			{
2864
-				if ($icServerID == $_formData['serverID'] )
2863
+				if ($icServerID == $_formData['serverID'])
2865 2864
 				{
2866 2865
 					$folder[$fval] = $fval;
2867 2866
 					$folderOnServerID[] = $fval;
@@ -2874,7 +2873,7 @@  discard block
 block discarded – undo
2874 2873
 			}
2875 2874
 			else
2876 2875
 			{
2877
-				if ($icServerID == $_formData['serverID'] )
2876
+				if ($icServerID == $_formData['serverID'])
2878 2877
 				{
2879 2878
 					$folder[$fval] = $fval;
2880 2879
 					$folderOnServerID[] = $fval;
@@ -2891,7 +2890,7 @@  discard block
 block discarded – undo
2891 2890
 		// we use the sentFolder settings of the choosen mailaccount
2892 2891
 		// sentFolder is account specific
2893 2892
 		$changeProfileOnSentFolderNeeded = false;
2894
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2893
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2895 2894
 		{
2896 2895
 			$this->changeProfile($_formData['mailaccount']);
2897 2896
 			//error_log(__METHOD__.__LINE__.'#'.$this->mail_bo->profileID.'<->'.$mail_bo->profileID.'#');
@@ -2899,30 +2898,30 @@  discard block
 block discarded – undo
2899 2898
 			// sentFolder is account specific
2900 2899
 			$sentFolder = $this->mail_bo->getSentFolder();
2901 2900
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2902
-			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2901
+			if ($sentFolder && $sentFolder != 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2903 2902
 		}
2904 2903
 		else
2905 2904
 		{
2906 2905
 			$sentFolder = $mail_bo->getSentFolder();
2907 2906
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2908
-			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2907
+			if ($sentFolder && $sentFolder != 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2909 2908
 		}
2910 2909
 		//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2911 2910
 
2912 2911
 		// we switch $this->mail_bo back to the account we used to work on
2913
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2912
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2914 2913
 		{
2915 2914
 			$this->changeProfile($_formData['serverID']);
2916 2915
 		}
2917 2916
 
2918 2917
 
2919
-		if(isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2918
+		if (isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2920 2919
 			$this->mailPreferences['sendOptions'] != 'send_only' &&
2921 2920
 			$messageIsDraft == false)
2922 2921
 		{
2923 2922
 			if ($sentFolder)
2924 2923
 			{
2925
-				if ($_formData['serverID']!=$_formData['mailaccount'])
2924
+				if ($_formData['serverID'] != $_formData['mailaccount'])
2926 2925
 				{
2927 2926
 					$folderOnMailAccount[] = $sentFolder;
2928 2927
 				}
@@ -2939,14 +2938,14 @@  discard block
 block discarded – undo
2939 2938
 		}
2940 2939
 		else
2941 2940
 		{
2942
-			if (((!isset($sentFolder)||$sentFolder==false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2941
+			if (((!isset($sentFolder) || $sentFolder == false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2943 2942
 				($this->mailPreferences['sendOptions'] != 'send_only' &&
2944 2943
 				$sentFolder != 'none')) $this->errorInfo = lang("No Send Folder set in preferences");
2945 2944
 		}
2946 2945
 		// draftFolder is on Server we start from
2947
-		if($messageIsDraft == true) {
2946
+		if ($messageIsDraft == true) {
2948 2947
 			$draftFolder = $mail_bo->getDraftFolder();
2949
-			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true)) {
2948
+			if (!empty($draftFolder) && $mail_bo->folderExists($draftFolder, true)) {
2950 2949
 				$this->sessionData['folder'] = array($draftFolder);
2951 2950
 				$folderOnServerID[] = $draftFolder;
2952 2951
 				$folder[$draftFolder] = $draftFolder;
@@ -2955,10 +2954,10 @@  discard block
 block discarded – undo
2955 2954
 		if ($folderOnServerID) $folderOnServerID = array_unique($folderOnServerID);
2956 2955
 		if ($folderOnMailAccount) $folderOnMailAccount = array_unique($folderOnMailAccount);
2957 2956
 		if (($this->mailPreferences['sendOptions'] != 'send_only' && $sentFolder != 'none') &&
2958
-			!( count($folder) > 0) &&
2959
-			!($_formData['to_infolog']=='on' || $_formData['to_tracker']=='on'))
2957
+			!(count($folder) > 0) &&
2958
+			!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on'))
2960 2959
 		{
2961
-			$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
+			$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 : '');
2962 2961
 			#error_log($this->errorInfo);
2963 2962
 			return false;
2964 2963
 		}
@@ -2967,18 +2966,18 @@  discard block
 block discarded – undo
2967 2966
 		@set_time_limit(120);
2968 2967
 		//$mail->SMTPDebug = 10;
2969 2968
 		//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']));
2970
-		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2969
+		if (count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2971 2970
 			try {
2972 2971
 				$mail->send();
2973 2972
 			}
2974
-			catch(Exception $e) {
2973
+			catch (Exception $e) {
2975 2974
 				_egw_log_exception($e);
2976 2975
 				//if( $e->details ) error_log(__METHOD__.__LINE__.array2string($e->details));
2977
-				$this->errorInfo = $e->getMessage().($e->details?'<br/>'.$e->details:'');
2976
+				$this->errorInfo = $e->getMessage().($e->details ? '<br/>'.$e->details : '');
2978 2977
 				return false;
2979 2978
 			}
2980 2979
 		} else {
2981
-			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder'])) {
2980
+			if (count(array($this->sessionData['folder'])) > 0 && !empty($this->sessionData['folder'])) {
2982 2981
 				//error_log(__METHOD__.__LINE__."Folders:".print_r($this->sessionData['folder'],true));
2983 2982
 			} else {
2984 2983
 				$this->errorInfo = lang("Error: ").lang("No Address TO/CC/BCC supplied, and no folder to save message to provided.");
@@ -3006,15 +3005,15 @@  discard block
 block discarded – undo
3006 3005
 		// copying mail to folder
3007 3006
 		if (count($folder) > 0)
3008 3007
 		{
3009
-			foreach($folderOnServerID as $folderName) {
3008
+			foreach ($folderOnServerID as $folderName) {
3010 3009
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3011 3010
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3012 3011
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3013 3012
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3014
-				if ($mail_bo->folderExists($folderName,true)) {
3015
-					if($mail_bo->isSentFolder($folderName)) {
3013
+				if ($mail_bo->folderExists($folderName, true)) {
3014
+					if ($mail_bo->isSentFolder($folderName)) {
3016 3015
 						$flags = '\\Seen';
3017
-					} elseif($mail_bo->isDraftFolder($folderName)) {
3016
+					} elseif ($mail_bo->isDraftFolder($folderName)) {
3018 3017
 						$flags = '\\Draft';
3019 3018
 					} else {
3020 3019
 						$flags = '\\Seen';
@@ -3030,25 +3029,25 @@  discard block
 block discarded – undo
3030 3029
 					}
3031 3030
 					catch (Api\Exception\WrongUserinput $e)
3032 3031
 					{
3033
-						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
+						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()));
3034 3033
 					}
3035 3034
 				}
3036 3035
 				else
3037 3036
 				{
3038
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3037
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3039 3038
 				}
3040 3039
 			}
3041 3040
 			// if we choose to send from a differing profile
3042 3041
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['mailaccount']);
3043
-			foreach($folderOnMailAccount as $folderName) {
3042
+			foreach ($folderOnMailAccount as $folderName) {
3044 3043
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3045 3044
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3046 3045
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3047 3046
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3048
-				if ($this->mail_bo->folderExists($folderName,true)) {
3049
-					if($this->mail_bo->isSentFolder($folderName)) {
3047
+				if ($this->mail_bo->folderExists($folderName, true)) {
3048
+					if ($this->mail_bo->isSentFolder($folderName)) {
3050 3049
 						$flags = '\\Seen';
3051
-					} elseif($this->mail_bo->isDraftFolder($folderName)) {
3050
+					} elseif ($this->mail_bo->isDraftFolder($folderName)) {
3052 3051
 						$flags = '\\Draft';
3053 3052
 					} else {
3054 3053
 						$flags = '\\Seen';
@@ -3064,12 +3063,12 @@  discard block
 block discarded – undo
3064 3063
 					}
3065 3064
 					catch (Api\Exception\WrongUserinput $e)
3066 3065
 					{
3067
-						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
+						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()));
3068 3067
 					}
3069 3068
 				}
3070 3069
 				else
3071 3070
 				{
3072
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3071
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3073 3072
 				}
3074 3073
 			}
3075 3074
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['serverID']);
@@ -3080,27 +3079,27 @@  discard block
 block discarded – undo
3080 3079
 		$lastDrafted = false;
3081 3080
 		if (isset($this->sessionData['lastDrafted']))
3082 3081
 		{
3083
-			$lastDrafted=array();
3082
+			$lastDrafted = array();
3084 3083
 			$dhA = mail_ui::splitRowID($this->sessionData['lastDrafted']);
3085 3084
 			$lastDrafted['uid'] = $dhA['msgUID'];
3086 3085
 			$lastDrafted['folder'] = $dhA['folder'];
3087
-			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
3086
+			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
3088 3087
 			// manually drafted, do not delete
3089 3088
 			// will be handled later on IF mode was $_formData['mode']=='composefromdraft'
3090
-			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
3089
+			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted = false;
3091 3090
 			//error_log(__METHOD__.__LINE__.array2string($lastDrafted));
3092 3091
 		}
3093 3092
 		if ($lastDrafted && is_array($lastDrafted) && $mail_bo->isDraftFolder($lastDrafted['folder']))
3094 3093
 		{
3095 3094
 			try
3096 3095
 			{
3097
-				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode']=='composefromdraft' &&
3098
-					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )&&$this->sessionData['attachments']))
3096
+				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode'] == 'composefromdraft' &&
3097
+					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3099 3098
 				{
3100 3099
 					//error_log(__METHOD__.__LINE__."#".$lastDrafted['uid'].'#'.$lastDrafted['folder'].array2string($_formData));
3101 3100
 					//error_log(__METHOD__.__LINE__."#".array2string($_formData));
3102 3101
 					//error_log(__METHOD__.__LINE__."#".array2string($this->sessionData));
3103
-					$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
3102
+					$mail_bo->deleteMessages($lastDrafted['uid'], $lastDrafted['folder'], 'remove_immediately');
3104 3103
 				}
3105 3104
 			}
3106 3105
 			catch (Api\Exception $e)
@@ -3112,22 +3111,22 @@  discard block
 block discarded – undo
3112 3111
 		unset($this->sessionData['lastDrafted']);
3113 3112
 
3114 3113
 		//error_log("handling draft messages, flagging and such");
3115
-		if((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3114
+		if ((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3116 3115
 			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3117 3116
 			// mark message as answered
3118 3117
 			$mail_bo->openConnection();
3119
-			$mail_bo->reopen(($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3118
+			$mail_bo->reopen(($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3120 3119
 			// if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send
3121 3120
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
3122 3121
 			if ($mail_bo->isDraftFolder($this->sessionData['messageFolder']) && !$mail_bo->isTemplateFolder($this->sessionData['messageFolder']))
3123 3122
 			{
3124 3123
 				try // message may be deleted already, as it maybe done by autosave
3125 3124
 				{
3126
-					if ($_formData['mode']=='composefromdraft' &&
3125
+					if ($_formData['mode'] == 'composefromdraft' &&
3127 3126
 						!(($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3128 3127
 					{
3129 3128
 						//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
3130
-						$mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder']);
3129
+						$mail_bo->deleteMessages(array($this->sessionData['uid']), $this->sessionData['messageFolder']);
3131 3130
 					}
3132 3131
 				}
3133 3132
 				catch (Api\Exception $e)
@@ -3136,14 +3135,14 @@  discard block
 block discarded – undo
3136 3135
 					unset($e);
3137 3136
 				}
3138 3137
 			} else {
3139
-				$mail_bo->flagMessages("answered", $this->sessionData['uid'],($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3138
+				$mail_bo->flagMessages("answered", $this->sessionData['uid'], ($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3140 3139
 				//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)).':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3141
-				if (array_key_exists('forwardFlag',$this->sessionData) && $this->sessionData['forwardFlag']=='forwarded')
3140
+				if (array_key_exists('forwardFlag', $this->sessionData) && $this->sessionData['forwardFlag'] == 'forwarded')
3142 3141
 				{
3143 3142
 					try
3144 3143
 					{
3145 3144
 						//error_log(__METHOD__.__LINE__.':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3146
-						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'],$this->sessionData['sourceFolder']);
3145
+						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'], $this->sessionData['sourceFolder']);
3147 3146
 					}
3148 3147
 					catch (Api\Exception $e)
3149 3148
 					{
@@ -3171,49 +3170,49 @@  discard block
 block discarded – undo
3171 3170
 		if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc'];
3172 3171
 		if (!empty($mailaddresses)) $mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3173 3172
 
3174
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )
3173
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on')
3175 3174
 		{
3176 3175
 			$this->sessionData['attachments'] = array_merge((array)$this->sessionData['attachments'], (array)$inline_images);
3177 3176
 
3178
-			foreach(array('to_infolog','to_tracker','to_calendar') as $app_key)
3177
+			foreach (array('to_infolog', 'to_tracker', 'to_calendar') as $app_key)
3179 3178
 			{
3180 3179
 				$entryid = $_formData['to_integrate_ids'][0][$app_key];
3181 3180
 				if ($_formData[$app_key] == 'on')
3182 3181
 				{
3183
-					$app_name = substr($app_key,3);
3182
+					$app_name = substr($app_key, 3);
3184 3183
 					// Get registered hook data of the app called for integration
3185
-					$hook = Api\Hooks::single(array('location'=> 'mail_import'),$app_name);
3184
+					$hook = Api\Hooks::single(array('location'=> 'mail_import'), $app_name);
3186 3185
 
3187 3186
 					// store mail / eml in temp. file to not have to download it from mail-server again
3188
-					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'mail_integrate');
3187
+					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'mail_integrate');
3189 3188
 					$eml_fp = fopen($eml, 'w');
3190 3189
 					stream_copy_to_stream($mail->getRaw(), $eml_fp);
3191 3190
 					fclose($eml_fp);
3192 3191
 					$target = array(
3193 3192
 						'menuaction' => $hook['menuaction'],
3194
-						'egw_data' => Link::set_data(null,'mail_integration::integrate',array(
3193
+						'egw_data' => Link::set_data(null, 'mail_integration::integrate', array(
3195 3194
 							$mailaddresses,
3196 3195
 							$this->sessionData['subject'],
3197 3196
 							$this->convertHTMLToText($this->sessionData['body']),
3198 3197
 							$this->sessionData['attachments'],
3199 3198
 							false, // date
3200 3199
 							$eml,
3201
-							$_formData['serverID']),true),
3200
+							$_formData['serverID']), true),
3202 3201
 						'app' => $app_name
3203 3202
 					);
3204 3203
 					if ($entryid) $target['entry_id'] = $entryid;
3205 3204
 					// Open the app called for integration in a popup
3206 3205
 					// and store the mail raw data as egw_data, in order to
3207 3206
 					// be stored from registered app method later
3208
-					Framework::popup(Egw::link('/index.php', $target),'_blank',$hook['popup']);
3207
+					Framework::popup(Egw::link('/index.php', $target), '_blank', $hook['popup']);
3209 3208
 				}
3210 3209
 			}
3211 3210
 		}
3212 3211
 		// only clean up temp-files, if we dont need them for mail_integration::integrate
3213
-		elseif(is_array($this->sessionData['attachments']))
3212
+		elseif (is_array($this->sessionData['attachments']))
3214 3213
 		{
3215
-			foreach($this->sessionData['attachments'] as $value) {
3216
-				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3214
+			foreach ($this->sessionData['attachments'] as $value) {
3215
+				if (!empty($value['file']) && parse_url($value['file'], PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3217 3216
 					unlink($GLOBALS['egw_info']['server']['temp_dir'].'/'.$value['file']);
3218 3217
 				}
3219 3218
 			}
@@ -3230,7 +3229,7 @@  discard block
 block discarded – undo
3230 3229
 	 * @param array $content
3231 3230
 	 * @return array - the input, enriched with some not set attributes
3232 3231
 	 */
3233
-	function setDefaults($content=array())
3232
+	function setDefaults($content = array())
3234 3233
 	{
3235 3234
 		// if there's not already an identity selected for current account
3236 3235
 		if (empty($content['mailidentity']))
@@ -3239,7 +3238,7 @@  discard block
 block discarded – undo
3239 3238
 			if (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed']))
3240 3239
 			{
3241 3240
 				$sigPref = $GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed'];
3242
-				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID]>0)
3241
+				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID] > 0)
3243 3242
 				{
3244 3243
 					$content['mailidentity'] = $sigPref[$this->mail_bo->profileID];
3245 3244
 				}
@@ -3248,7 +3247,7 @@  discard block
 block discarded – undo
3248 3247
 			if (empty($content['mailidentity']))
3249 3248
 			{
3250 3249
 				$default_identity = null;
3251
-				foreach(Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3250
+				foreach (Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3252 3251
 				{
3253 3252
 					if (!isset($default_identity)) $default_identity = $identity['ident_id'];
3254 3253
 					if (!empty($identity['ident_signature']))
@@ -3263,7 +3262,7 @@  discard block
 block discarded – undo
3263 3262
 		if (!isset($content['mimeType']) || empty($content['mimeType']))
3264 3263
 		{
3265 3264
 			$content['mimeType'] = 'html';
3266
-			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text") $content['mimeType']  = 'plain';
3265
+			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions'] == "text") $content['mimeType'] = 'plain';
3267 3266
 		}
3268 3267
 		return $content;
3269 3268
 
@@ -3286,7 +3285,7 @@  discard block
 block discarded – undo
3286 3285
 	 * @param boolean $_noPrefixId = false, if set to true folders name does not get prefixed by account id
3287 3286
 	 * @return type
3288 3287
 	 */
3289
-	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false) {
3288
+	function ajax_searchFolder($_searchStringLength = 2, $_returnList = false, $_mailaccountToSearch = null, $_noPrefixId = false) {
3290 3289
 		//error_log(__METHOD__.__LINE__.':'.array2string($_REQUEST));
3291 3290
 		static $useCacheIfPossible = null;
3292 3291
 		if (is_null($useCacheIfPossible)) $useCacheIfPossible = true;
@@ -3299,36 +3298,36 @@  discard block
 block discarded – undo
3299 3298
 		{
3300 3299
 			$this->changeProfile($_mailaccountToSearch);
3301 3300
 		}
3302
-		if (strlen($_searchString)>=$_searchStringLength && isset($this->mail_bo->icServer))
3301
+		if (strlen($_searchString) >= $_searchStringLength && isset($this->mail_bo->icServer))
3303 3302
 		{
3304 3303
 			//error_log(__METHOD__.__LINE__.':'.$this->mail_bo->icServer->ImapServerId);
3305 3304
 			$this->mail_bo->openConnection($this->mail_bo->icServer->ImapServerId);
3306 3305
 			//error_log(__METHOD__.__LINE__.array2string($_searchString).'<->'.$searchString);
3307
-			$folderObjects = $this->mail_bo->getFolderObjects(true,false,true,$useCacheIfPossible);
3308
-			if (count($folderObjects)<=1) {
3306
+			$folderObjects = $this->mail_bo->getFolderObjects(true, false, true, $useCacheIfPossible);
3307
+			if (count($folderObjects) <= 1) {
3309 3308
 				$useCacheIfPossible = false;
3310 3309
 			}
3311 3310
 			else
3312 3311
 			{
3313 3312
 				$useCacheIfPossible = true;
3314 3313
 			}
3315
-			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset,'UTF7-IMAP');
3314
+			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset, 'UTF7-IMAP');
3316 3315
 			foreach ($folderObjects as $k =>$fA)
3317 3316
 			{
3318 3317
 				//error_log(__METHOD__.__LINE__.$_searchString.'/'.$searchString.' in '.$k.'->'.$fA->displayName);
3319
-				$f=false;
3320
-				$key = $_noPrefixId?$k:$_mailaccountToSearch.'::'.$k;
3321
-				if ($_searchStringLength<=0)
3318
+				$f = false;
3319
+				$key = $_noPrefixId ? $k : $_mailaccountToSearch.'::'.$k;
3320
+				if ($_searchStringLength <= 0)
3322 3321
 				{
3323
-					$f=true;
3322
+					$f = true;
3324 3323
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3325 3324
 				}
3326
-				if ($f==false && stripos($fA->displayName,$_searchString)!==false)
3325
+				if ($f == false && stripos($fA->displayName, $_searchString) !== false)
3327 3326
 				{
3328
-					$f=true;
3327
+					$f = true;
3329 3328
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3330 3329
 				}
3331
-				if ($f==false && stripos($k,$searchString)!==false)
3330
+				if ($f == false && stripos($k, $searchString) !== false)
3332 3331
 				{
3333 3332
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3334 3333
 				}
@@ -3356,7 +3355,7 @@  discard block
 block discarded – undo
3356 3355
 		exit();
3357 3356
 	}
3358 3357
 
3359
-	public static function ajax_searchAddress($_searchStringLength=2) {
3358
+	public static function ajax_searchAddress($_searchStringLength = 2) {
3360 3359
 		//error_log(__METHOD__. "request from seachAddress " . $_REQUEST['query']);
3361 3360
 		$_searchString = trim($_REQUEST['query']);
3362 3361
 		$include_lists = (boolean)$_REQUEST['include_lists'];
@@ -3365,7 +3364,7 @@  discard block
 block discarded – undo
3365 3364
 		$results = array();
3366 3365
 
3367 3366
 		// Add up to 5 matching mailing lists
3368
-		if($include_lists)
3367
+		if ($include_lists)
3369 3368
 		{
3370 3369
 			$lists = array_filter(
3371 3370
 				$contacts_obj->get_lists(Acl::READ),
@@ -3374,7 +3373,7 @@  discard block
 block discarded – undo
3374 3373
 				}
3375 3374
 			);
3376 3375
 			$list_count = 0;
3377
-			foreach($lists as $key => $list_name)
3376
+			foreach ($lists as $key => $list_name)
3378 3377
 			{
3379 3378
 				$results[] = array(
3380 3379
 					'id'	=> $key,
@@ -3384,11 +3383,11 @@  discard block
 block discarded – undo
3384 3383
 					'title' => lang('Mailinglist'),
3385 3384
 					'data'	=> $key
3386 3385
 				);
3387
-				if($list_count++ > 5) break;
3386
+				if ($list_count++ > 5) break;
3388 3387
 			}
3389 3388
 		}
3390 3389
 
3391
-		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
3390
+		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString) >= $_searchStringLength)
3392 3391
 		{
3393 3392
 			//error_log(__METHOD__.__LINE__.array2string($_searchString));
3394 3393
 			$showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']);
@@ -3397,64 +3396,64 @@  discard block
 block discarded – undo
3397 3396
 			{
3398 3397
 				if (mb_strlen($v) < 3) unset($search[$k]);
3399 3398
 			}
3400
-			$search_str = implode(' +', $search);	// tell contacts/so_sql to AND search patterns
3399
+			$search_str = implode(' +', $search); // tell contacts/so_sql to AND search patterns
3401 3400
 			//error_log(__METHOD__.__LINE__.$_searchString);
3402 3401
 			$filter = $showAccounts ? array() : array('account_id' => null);
3403
-			$filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home');
3404
-			$cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home');
3405
-			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter);
3402
+			$filter['cols_to_search'] = array('n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3403
+			$cols = array('n_fn', 'n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3404
+			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3406 3405
 			// additionally search the accounts, if the contact storage is not the account storage
3407 3406
 			if ($showAccounts && $contacts_obj->so_accounts)
3408 3407
 			{
3409 3408
 				$filter['owner'] = 0;
3410
-				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false,'OR', array(0,100), $filter);
3409
+				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3411 3410
 
3412 3411
 				if ($contacts && $accounts)
3413 3412
 				{
3414
-					$contacts = array_merge($contacts,$accounts);
3415
-					usort($contacts,function($a, $b)
3413
+					$contacts = array_merge($contacts, $accounts);
3414
+					usort($contacts, function($a, $b)
3416 3415
 					{
3417 3416
 						return strcasecmp($a['n_fn'], $b['n_fn']);
3418 3417
 					});
3419 3418
 				}
3420
-				elseif($accounts)
3419
+				elseif ($accounts)
3421 3420
 				{
3422
-					$contacts =& $accounts;
3421
+					$contacts = & $accounts;
3423 3422
 				}
3424 3423
 				unset($accounts);
3425 3424
 			}
3426 3425
 		}
3427 3426
 		
3428
-		if(is_array($contacts)) {
3429
-			foreach($contacts as $contact) {
3430
-				foreach(array($contact['email'],$contact['email_home']) as $email) {
3427
+		if (is_array($contacts)) {
3428
+			foreach ($contacts as $contact) {
3429
+				foreach (array($contact['email'], $contact['email_home']) as $email) {
3431 3430
 					// avoid wrong addresses, if an rfc822 encoded address is in addressbook
3432 3431
 					//$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
3433 3432
 					$rfcAddr = Mail::parseAddressList($email);
3434
-					$_rfcAddr=$rfcAddr->first();
3433
+					$_rfcAddr = $rfcAddr->first();
3435 3434
 					if (!$_rfcAddr->valid)
3436 3435
 					{
3437 3436
 						continue; // skip address if we encounter an error here
3438 3437
 					}
3439 3438
 					$email = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
3440 3439
 
3441
-					if (method_exists($contacts_obj,'search'))
3440
+					if (method_exists($contacts_obj, 'search'))
3442 3441
 					{
3443
-						$contact['n_fn']='';
3442
+						$contact['n_fn'] = '';
3444 3443
 						if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
3445
-						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3446
-						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3447
-						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3448
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3444
+						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_given'];
3445
+						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_family'];
3446
+						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').'('.$contact['org_name'].')';
3447
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3449 3448
 					}
3450 3449
 					else
3451 3450
 					{
3452
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3451
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3453 3452
 					}
3454 3453
 					$args = explode('@', trim($email));
3455 3454
 					$args[] = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']);
3456 3455
 					$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
3457
-					if(!empty($email) && in_array($completeMailString ,$results) === false) {
3456
+					if (!empty($email) && in_array($completeMailString, $results) === false) {
3458 3457
 						$results[] = array(
3459 3458
 							'id'=>$completeMailString,
3460 3459
 							'label' => $completeMailString,
@@ -3470,10 +3469,10 @@  discard block
 block discarded – undo
3470 3469
 		// Add groups
3471 3470
 		$group_options = array('account_type' => 'groups');
3472 3471
 		$groups = $GLOBALS['egw']->accounts->link_query($_searchString, $group_options);
3473
-		foreach($groups as $g_id => $name)
3472
+		foreach ($groups as $g_id => $name)
3474 3473
 		{
3475 3474
 			$group = $GLOBALS['egw']->accounts->read($g_id);
3476
-			if(!$group['account_email']) continue;
3475
+			if (!$group['account_email']) continue;
3477 3476
 			$args = explode('@', trim($group['account_email']));
3478 3477
 			$args[] = $name;
3479 3478
 			$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
@@ -3503,7 +3502,7 @@  discard block
 block discarded – undo
3503 3502
 	public function ajax_merge($contact_id)
3504 3503
 	{
3505 3504
 		$response = Api\Json\Response::get();
3506
-		if(class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3505
+		if (class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3507 3506
 		{
3508 3507
 			$document_merge = new $_REQUEST['merge']();
3509 3508
 		}
@@ -3513,7 +3512,7 @@  discard block
 block discarded – undo
3513 3512
 		}
3514 3513
 		$this->mail_bo->openConnection();
3515 3514
 
3516
-		if(($error = $document_merge->check_document($_REQUEST['document'],'')))
3515
+		if (($error = $document_merge->check_document($_REQUEST['document'], '')))
3517 3516
 		{
3518 3517
 			$response->error($error);
3519 3518
 			return;
@@ -3524,11 +3523,11 @@  discard block
 block discarded – undo
3524 3523
 		try
3525 3524
 		{
3526 3525
 			$results = $this->mail_bo->importMessageToMergeAndSend(
3527
-				$document_merge, Vfs::PREFIX . $_REQUEST['document'],
3526
+				$document_merge, Vfs::PREFIX.$_REQUEST['document'],
3528 3527
 				// Send an extra non-numeric ID to force actual send of document
3529 3528
 				// instead of save as draft
3530 3529
 				array((int)$contact_id, ''),
3531
-				$folder,$merged_mail_id
3530
+				$folder, $merged_mail_id
3532 3531
 			);
3533 3532
 		}
3534 3533
 		catch (Exception $e)
@@ -3542,13 +3541,13 @@  discard block
 block discarded – undo
3542 3541
 			);
3543 3542
 		}
3544 3543
 
3545
-		if($results['success'])
3544
+		if ($results['success'])
3546 3545
 		{
3547
-			$response->data(implode(',',$results['success']));
3546
+			$response->data(implode(',', $results['success']));
3548 3547
 		}
3549
-		if($results['failed'])
3548
+		if ($results['failed'])
3550 3549
 		{
3551
-			$response->error(implode(',',$results['failed']));
3550
+			$response->error(implode(',', $results['failed']));
3552 3551
 		}
3553 3552
 	}
3554 3553
 }
Please login to merge, or discard this patch.