Completed
Push — 17.1 ( 453222...d7c539 )
by Hadi
11:57
created
mail/inc/class.mail_compose.inc.php 1 patch
Spacing   +634 added lines, -636 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
 
@@ -140,7 +139,7 @@  discard block
 block discarded – undo
140 139
 				'onExecute' => 'javaScript:app.mail.saveAsDraft',
141 140
 				'hint' => 'Save as Draft and Print'
142 141
 			),
143
-			'save2vfs' => array (
142
+			'save2vfs' => array(
144 143
 				'caption' => 'Save to filemanager',
145 144
 				'icon' => 'filesave',
146 145
 				'group' => $group,
@@ -179,7 +178,7 @@  discard block
 block discarded – undo
179 178
 				'checkbox' => true,
180 179
 				'hint' => 'check to save as tracker entry on send',
181 180
 				'onExecute' => 'javaScript:app.mail.compose_setToggle',
182
-				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'),
181
+				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'), 'tracker'),
183 182
 			),
184 183
 			'to_calendar' => array(
185 184
 				'caption' => 'Calendar',
@@ -219,7 +218,7 @@  discard block
 block discarded – undo
219 218
 		if ($acc_smime['acc_smime_password'])
220 219
 		{
221 220
 			$actions = array_merge($actions, array(
222
-				'smime_sign' => array (
221
+				'smime_sign' => array(
223 222
 					'caption' => 'SMIME Sign',
224 223
 					'icon' => 'smime_sign',
225 224
 					'group' => ++$group,
@@ -227,7 +226,7 @@  discard block
 block discarded – undo
227 226
 					'checkbox' => true,
228 227
 					'hint' => 'Sign your message with smime certificate'
229 228
 				),
230
-				'smime_encrypt' => array (
229
+				'smime_encrypt' => array(
231 230
 					'caption' => 'SMIME Encryption',
232 231
 					'icon' => 'smime_encrypt',
233 232
 					'group' => $group,
@@ -265,7 +264,7 @@  discard block
 block discarded – undo
265 264
 		{
266 265
 			foreach (array_keys($actions) as $key)
267 266
 			{
268
-				if (!in_array($key, array('send','button[saveAsDraft]','uploadForCompose' ))) {
267
+				if (!in_array($key, array('send', 'button[saveAsDraft]', 'uploadForCompose'))) {
269 268
 					$actions[$key]['toolbarDefault'] = false;
270 269
 				}
271 270
 			}
@@ -290,7 +289,7 @@  discard block
 block discarded – undo
290 289
 	 * @var boolean $suppressSigOnTop =false
291 290
 	 * @var boolean $isReply =false
292 291
 	 */
293
-	function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false)
292
+	function compose(array $_content = null, $msg = null, $_focusElement = 'to', $suppressSigOnTop = false, $isReply = false)
294 293
 	{
295 294
 		if ($msg) Framework::message($msg);
296 295
 
@@ -311,8 +310,8 @@  discard block
 block discarded – undo
311 310
 		//lang('compose'),lang('from') // needed to be found by translationtools
312 311
 		//error_log(__METHOD__.__LINE__.array2string($_REQUEST).function_backtrace());
313 312
 		//error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace());
314
-		$_contentHasSigID = $_content?array_key_exists('mailidentity',(array)$_content):false;
315
-		$_contentHasMimeType = $_content? array_key_exists('mimeType',(array)$_content):false;
313
+		$_contentHasSigID = $_content ?array_key_exists('mailidentity', (array)$_content) : false;
314
+		$_contentHasMimeType = $_content ? array_key_exists('mimeType', (array)$_content) : false;
316 315
 
317 316
 		// fetch appendix data which is an assistance input value consisiting of json data
318 317
 		if ($_content['appendix_data'])
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
 
342 341
 		// Process different places we can use as a start for composing an email
343 342
 		$actionToProcess = 'compose';
344
-		if($_GET['from'] && $replyID)
343
+		if ($_GET['from'] && $replyID)
345 344
 		{
346 345
 			$_content = array_merge((array)$_content, $this->getComposeFrom(
347 346
 				// Parameters needed for fetching appropriate data
@@ -369,10 +368,10 @@  discard block
 block discarded – undo
369 368
 		}
370 369
 
371 370
 		$composeCache = array();
372
-		if (isset($_content['composeID'])&&!empty($_content['composeID']))
371
+		if (isset($_content['composeID']) && !empty($_content['composeID']))
373 372
 		{
374 373
 			$isFirstLoad = false;
375
-			$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);
374
+			$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);
376 375
 			$this->composeID = $_content['composeID'];
377 376
 			//error_log(__METHOD__.__LINE__.array2string($composeCache));
378 377
 		}
@@ -382,7 +381,7 @@  discard block
 block discarded – undo
382 381
 			// respect that composeasnew may not want that, as we assume there
383 382
 			// is some style already set and our initalStyle always adds a span with &nbsp;
384 383
 			// and we want to avoid that
385
-			$isFirstLoad = !($actionToProcess=='composeasnew');//true;
384
+			$isFirstLoad = !($actionToProcess == 'composeasnew'); //true;
386 385
 			$this->composeID = $_content['composeID'] = $this->generateComposeID();
387 386
 			if (!is_array($_content))
388 387
 			{
@@ -417,7 +416,7 @@  discard block
 block discarded – undo
417 416
 				if (!isset($upload['file'])) $upload['file'] = $upload['tmp_name'];
418 417
 				try
419 418
 				{
420
-					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload,$this->composeID,false);
419
+					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload, $this->composeID, false);
421 420
 				}
422 421
 				catch (Api\Exception\WrongUserinput $e)
423 422
 				{
@@ -443,12 +442,12 @@  discard block
 block discarded – undo
443 442
 			unset($_content['attachments']['delete']);
444 443
 			$attachments = $_content['attachments'];
445 444
 			unset($_content['attachments']);
446
-			foreach($attachments as $i => $att)
445
+			foreach ($attachments as $i => $att)
447 446
 			{
448
-				$remove=false;
449
-				foreach(array_keys($toDelete) as $k)
447
+				$remove = false;
448
+				foreach (array_keys($toDelete) as $k)
450 449
 				{
451
-					if ($att['tmp_name']==$k) $remove=true;
450
+					if ($att['tmp_name'] == $k) $remove = true;
452 451
 				}
453 452
 				if (!$remove) $_content['attachments'][] = $att;
454 453
 			}
@@ -456,7 +455,7 @@  discard block
 block discarded – undo
456 455
 		// someone clicked something like send, or saveAsDraft
457 456
 		// make sure, we are connected to the correct server for sending and storing the send message
458 457
 		$activeProfile = $composeProfile = $this->mail_bo->profileID; // active profile may not be the profile uised in/for compose
459
-		$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);
458
+		$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);
460 459
 		if (!empty($activeFolderCache[$this->mail_bo->profileID]))
461 460
 		{
462 461
 			//error_log(__METHOD__.__LINE__.' CurrentFolder:'.$activeFolderCache[$this->mail_bo->profileID]);
@@ -464,7 +463,7 @@  discard block
 block discarded – undo
464 463
 		}
465 464
 		//error_log(__METHOD__.__LINE__.array2string($_content));
466 465
 		if (!empty($_content['serverID']) && $_content['serverID'] != $this->mail_bo->profileID &&
467
-			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft']||$_content['button']['saveAsDraftAndPrint'])
466
+			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft'] || $_content['button']['saveAsDraftAndPrint'])
468 467
 		)
469 468
 		{
470 469
 			$this->changeProfile($_content['serverID']);
@@ -478,19 +477,19 @@  discard block
 block discarded – undo
478 477
 		{
479 478
 			$buttonClicked = $suppressSigOnTop = true;
480 479
 			$sendOK = true;
481
-			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html'?'html':'plain').'text']);
480
+			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
482 481
 			/*
483 482
 			perform some simple checks, before trying to send on:
484 483
 			$_content['to'];$_content['cc'];$_content['bcc'];
485 484
 			trim($_content['subject']);
486 485
 			trim(strip_tags(str_replace('&nbsp;','',$_content['body'])));
487 486
 			*/
488
-			if (strlen(trim(strip_tags(str_replace('&nbsp;','',$_content['body']))))==0 && count($_content['attachments'])==0)
487
+			if (strlen(trim(strip_tags(str_replace('&nbsp;', '', $_content['body'])))) == 0 && count($_content['attachments']) == 0)
489 488
 			{
490 489
 				$sendOK = false;
491 490
 				$_content['msg'] = $message = lang("no message body supplied");
492 491
 			}
493
-			if ($sendOK && strlen(trim($_content['subject']))==0)
492
+			if ($sendOK && strlen(trim($_content['subject'])) == 0)
494 493
 			{
495 494
 				$sendOK = false;
496 495
 				$_content['msg'] = $message = lang("no subject supplied");
@@ -505,15 +504,15 @@  discard block
 block discarded – undo
505 504
 				try
506 505
 				{
507 506
 					$success = $this->send($_content);
508
-					if ($success==false)
507
+					if ($success == false)
509 508
 					{
510
-						$sendOK=false;
509
+						$sendOK = false;
511 510
 						$message = $this->errorInfo;
512 511
 					}
513 512
 					if (!empty($_content['mailidentity']) && $_content['mailidentity'] != $sigPref[$this->mail_bo->profileID])
514 513
 					{
515
-						$sigPref[$this->mail_bo->profileID]=$_content['mailidentity'];
516
-						$GLOBALS['egw']->preferences->add('mail','LastSignatureIDUsed',$sigPref,'user');
514
+						$sigPref[$this->mail_bo->profileID] = $_content['mailidentity'];
515
+						$GLOBALS['egw']->preferences->add('mail', 'LastSignatureIDUsed', $sigPref, 'user');
517 516
 						// save prefs
518 517
 						$GLOBALS['egw']->preferences->save_repository(true);
519 518
 					}
@@ -537,23 +536,23 @@  discard block
 block discarded – undo
537 536
 				if (isset($_content['mode']) && !empty($_content['mode']))
538 537
 				{
539 538
 					$mode = $_content['mode'];
540
-					if ($_content['mode']=='forward' && !empty($_content['processedmail_id']))
539
+					if ($_content['mode'] == 'forward' && !empty($_content['processedmail_id']))
541 540
 					{
542
-						$_content['processedmail_id'] = explode(',',$_content['processedmail_id']);
541
+						$_content['processedmail_id'] = explode(',', $_content['processedmail_id']);
543 542
 						foreach ($_content['processedmail_id'] as $k =>$rowid)
544 543
 						{
545 544
 							$fhA = mail_ui::splitRowID($rowid);
546 545
 							//$this->sessionData['uid'][] = $fhA['msgUID'];
547 546
 							//$this->sessionData['forwardedUID'][] = $fhA['msgUID'];
548
-							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp=false);
547
+							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp = false);
549 548
 							if (!empty($fhA['folder'])) $workingFolder = $fhA['folder'];
550 549
 						}
551 550
 					}
552
-					if ($_content['mode']=='reply' && !empty($_content['processedmail_id']))
551
+					if ($_content['mode'] == 'reply' && !empty($_content['processedmail_id']))
553 552
 					{
554 553
 						$rhA = mail_ui::splitRowID($_content['processedmail_id']);
555 554
 						//$this->sessionData['uid'] = $rhA['msgUID'];
556
-						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
555
+						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
557 556
 						$workingFolder = $rhA['folder'];
558 557
 					}
559 558
 				}
@@ -561,30 +560,30 @@  discard block
 block discarded – undo
561 560
 				if (empty($idsForRefresh) && !empty($_content['processedmail_id']))
562 561
 				{
563 562
 					$rhA = mail_ui::splitRowID($_content['processedmail_id']);
564
-					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
563
+					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
565 564
 				}
566 565
 				$response = Api\Json\Response::get();
567 566
 				if ($activeProfile != $composeProfile)
568 567
 				{
569 568
 					// we need a message only, when account ids (composeProfile vs. activeProfile) differ
570
-					$response->call('opener.egw_message',lang('Message send successfully.'));
569
+					$response->call('opener.egw_message', lang('Message send successfully.'));
571 570
 				}
572
-				elseif ($activeProfile == $composeProfile && ($workingFolder==$activeFolder['mailbox'] && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder)))
571
+				elseif ($activeProfile == $composeProfile && ($workingFolder == $activeFolder['mailbox'] && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder)))
573 572
 				{
574
-					if ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder))
573
+					if ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder))
575 574
 					{
576 575
 						// we may need a refresh when on sent folder or in drafts, as drafted messages will/should be deleted after succeeded send action
577
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail');
576
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail');
578 577
 					}
579 578
 					else
580 579
 					{
581 580
 						//error_log(__METHOD__.__LINE__.array2string($idsForRefresh));
582
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail',$idsForRefresh,'update');
581
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail', $idsForRefresh, 'update');
583 582
 					}
584 583
 				}
585 584
 				else
586 585
 				{
587
-					$response->call('opener.egw_message',lang('Message send successfully.'));
586
+					$response->call('opener.egw_message', lang('Message send successfully.'));
588 587
 				}
589 588
 				//egw_framework::refresh_opener(lang('Message send successfully.'),'mail');
590 589
 				Framework::window_close();
@@ -592,60 +591,60 @@  discard block
 block discarded – undo
592 591
 			if ($sendOK == false)
593 592
 			{
594 593
 				$response = Api\Json\Response::get();
595
-				Framework::message(lang('Message send failed: %1',$message),'error');// maybe error is more appropriate
594
+				Framework::message(lang('Message send failed: %1', $message), 'error'); // maybe error is more appropriate
596 595
 				$response->call('app.mail.clearIntevals');
597 596
 			}
598 597
 		}
599 598
 
600 599
 		if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile);
601 600
 		$insertSigOnTop = false;
602
-		$content = (is_array($_content)?$_content:array());
601
+		$content = (is_array($_content) ? $_content : array());
603 602
 		if ($_contentHasMimeType)
604 603
 		{
605 604
 			// mimeType is now a checkbox; convert it here to match expectations
606 605
 			// ToDo: match Code to meet checkbox value
607
-			if ($content['mimeType']==1)
606
+			if ($content['mimeType'] == 1)
608 607
 			{
609
-				$_content['mimeType'] = $content['mimeType']='html';
608
+				$_content['mimeType'] = $content['mimeType'] = 'html';
610 609
 			}
611 610
 			else
612 611
 			{
613
-				$_content['mimeType'] = $content['mimeType']='plain';
612
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
614 613
 			}
615 614
 
616 615
 		}
617 616
 		// user might have switched desired mimetype, so we should convert
618
-		if ($content['is_html'] && $content['mimeType']=='plain')
617
+		if ($content['is_html'] && $content['mimeType'] == 'plain')
619 618
 		{
620 619
 			//error_log(__METHOD__.__LINE__.$content['mail_htmltext']);
621 620
 			$suppressSigOnTop = true;
622
-			if (stripos($content['mail_htmltext'],'<pre>')!==false)
621
+			if (stripos($content['mail_htmltext'], '<pre>') !== false)
623 622
 			{
624 623
 				$contentArr = Api\Mail\Html::splithtmlByPRE($content['mail_htmltext']);
625 624
 				if (is_array($contentArr))
626 625
 				{
627 626
 					foreach ($contentArr as $k =>&$elem)
628 627
 					{
629
-						if (stripos($elem,'<pre>')!==false) $elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
628
+						if (stripos($elem, '<pre>') !== false) $elem = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $elem);
630 629
 					}
631
-					$content['mail_htmltext'] = implode('',$contentArr);
630
+					$content['mail_htmltext'] = implode('', $contentArr);
632 631
 				}
633 632
 			}
634 633
 			$content['mail_htmltext'] = $this->_getCleanHTML($content['mail_htmltext']);
635
-			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'],$charset=false,false,true);
634
+			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'], $charset = false, false, true);
636 635
 
637 636
 			$content['body'] = $content['mail_htmltext'];
638 637
 			unset($content['mail_htmltext']);
639 638
 			$content['is_html'] = false;
640 639
 			$content['is_plain'] = true;
641 640
 		}
642
-		if ($content['is_plain'] && $content['mimeType']=='html')
641
+		if ($content['is_plain'] && $content['mimeType'] == 'html')
643 642
 		{
644 643
 			// the possible font span should only be applied on first load or on switch plain->html
645 644
 			$isFirstLoad = "switchedplaintohtml";
646 645
 			//error_log(__METHOD__.__LINE__.$content['mail_plaintext']);
647 646
 			$suppressSigOnTop = true;
648
-			$content['mail_plaintext'] = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$content['mail_plaintext']);
647
+			$content['mail_plaintext'] = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $content['mail_plaintext']);
649 648
 			//$this->replaceEmailAdresses($content['mail_plaintext']);
650 649
 			$content['body'] = $content['mail_plaintext'];
651 650
 			unset($content['mail_plaintext']);
@@ -653,7 +652,7 @@  discard block
 block discarded – undo
653 652
 			$content['is_plain'] = false;
654 653
 		}
655 654
 
656
-		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text']);
655
+		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
657 656
 		unset($_content['body']);
658 657
 		unset($_content['mail_htmltext']);
659 658
 		unset($_content['mail_plaintext']);
@@ -665,7 +664,7 @@  discard block
 block discarded – undo
665 664
 
666 665
 		// form was submitted either by clicking a button or by changing one of the triggering selectboxes
667 666
 		// identity and signatureid; this might trigger that the signature in mail body may have to be altered
668
-		if ( !empty($content['body']) &&
667
+		if (!empty($content['body']) &&
669 668
 			(!empty($composeCache['mailaccount']) && !empty($_content['mailaccount']) && $_content['mailaccount'] != $composeCache['mailaccount']) ||
670 669
 			(!empty($composeCache['mailidentity']) && !empty($_content['mailidentity']) && $_content['mailidentity'] != $composeCache['mailidentity'])
671 670
 		)
@@ -676,7 +675,7 @@  discard block
 block discarded – undo
676 675
 			{
677 676
 				$acc = Mail\Account::read($_content['mailaccount']);
678 677
 				//error_log(__METHOD__.__LINE__.array2string($acc));
679
-				$Identities = Mail\Account::read_identity($acc['ident_id'],true);
678
+				$Identities = Mail\Account::read_identity($acc['ident_id'], true);
680 679
 				//error_log(__METHOD__.__LINE__.array2string($Identities));
681 680
 				if ($Identities['ident_id'])
682 681
 				{
@@ -689,41 +688,41 @@  discard block
 block discarded – undo
689 688
 				}
690 689
 			}
691 690
 			$_oldSig = $composeCache['mailidentity'];
692
-			$_signatureid = ($newSig?$newSig:$_content['mailidentity']);
691
+			$_signatureid = ($newSig ? $newSig : $_content['mailidentity']);
693 692
 
694 693
 			if ($_oldSig != $_signatureid)
695 694
 			{
696
-				if($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
695
+				if ($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
697 696
 				// prepare signatures, the selected sig may be used on top of the body
698 697
 				try
699 698
 				{
700
-					$oldSignature = Mail\Account::read_identity($_oldSig,true);
699
+					$oldSignature = Mail\Account::read_identity($_oldSig, true);
701 700
 					//error_log(__METHOD__.__LINE__.'Old:'.array2string($oldSignature).'#');
702 701
 					$oldSigText = $oldSignature['ident_signature'];
703 702
 				}
704 703
 				catch (Exception $e)
705 704
 				{
706
-					$oldSignature=array();
705
+					$oldSignature = array();
707 706
 					$oldSigText = null;
708 707
 				}
709 708
 				try
710 709
 				{
711
-					$signature = Mail\Account::read_identity($_signatureid,true);
710
+					$signature = Mail\Account::read_identity($_signatureid, true);
712 711
 					//error_log(__METHOD__.__LINE__.'New:'.array2string($signature).'#');
713 712
 					$sigText = $signature['ident_signature'];
714 713
 				}
715 714
 				catch (Exception $e)
716 715
 				{
717
-					$signature=array();
716
+					$signature = array();
718 717
 					$sigText = null;
719 718
 				}
720 719
 				//error_log(__METHOD__.'Old:'.$oldSigText.'#');
721 720
 				//error_log(__METHOD__.'New:'.$sigText.'#');
722 721
 				if ($_currentMode == 'plain')
723 722
 				{
724
-					$oldSigText = $this->convertHTMLToText($oldSigText,true,true);
725
-					$sigText = $this->convertHTMLToText($sigText,true,true);
726
-					if($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
723
+					$oldSigText = $this->convertHTMLToText($oldSigText, true, true);
724
+					$sigText = $this->convertHTMLToText($sigText, true, true);
725
+					if ($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
727 726
 				}
728 727
 
729 728
 				//$oldSigText = Mail::merge($oldSigText,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
@@ -737,9 +736,9 @@  discard block
 block discarded – undo
737 736
 				//error_log(__METHOD__.'Old(clean):'.$oldSigTextCleaned.'#');
738 737
 				if ($_currentMode == 'html')
739 738
 				{
740
-					$content['body'] = str_replace("\n",'\n',$content['body']);	// dont know why, but \n screws up preg_replace
739
+					$content['body'] = str_replace("\n", '\n', $content['body']); // dont know why, but \n screws up preg_replace
741 740
 					$styles = Mail::getStyles(array(array('body'=>$content['body'])));
742
-					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
741
+					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
743 742
 				}
744 743
 				$content['body'] = str_replace(array("\r", "\t", "<br />\n", ": "), array("", "", "<br />", ":"),
745 744
 					$_currentMode == 'html' ? Api\Html::purify($content['body'], Mail::$htmLawed_config, array(), true) : $content['body']);
@@ -747,9 +746,9 @@  discard block
 block discarded – undo
747 746
 				if ($_currentMode == 'html')
748 747
 				{
749 748
 					$replaced = null;
750
-					$content['body'] = preg_replace($reg='|'.preg_quote('<!-- HTMLSIGBEGIN -->','|').'.*'.preg_quote('<!-- HTMLSIGEND -->','|').'|u',
751
-						$rep='<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in=$content['body'], -1, $replaced);
752
-					$content['body'] = str_replace(array('\n',"\xe2\x80\x93","\xe2\x80\x94","\xe2\x82\xac"),array("\n",'&ndash;','&mdash;','&euro;'),$content['body']);
749
+					$content['body'] = preg_replace($reg = '|'.preg_quote('<!-- HTMLSIGBEGIN -->', '|').'.*'.preg_quote('<!-- HTMLSIGEND -->', '|').'|u',
750
+						$rep = '<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in = $content['body'], -1, $replaced);
751
+					$content['body'] = str_replace(array('\n', "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x82\xac"), array("\n", '&ndash;', '&mdash;', '&euro;'), $content['body']);
753 752
 					//error_log(__METHOD__."() preg_replace('$reg', '$rep', '$in', -1)='".$content['body']."', replaced=$replaced");
754 753
 					unset($rep, $in);
755 754
 					if ($replaced)
@@ -760,32 +759,32 @@  discard block
 block discarded – undo
760 759
 					else
761 760
 					{
762 761
 						// try the old way
763
-						$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
762
+						$found = (strlen(trim($oldSigTextCleaned)) > 0 ?strpos($content['body'], trim($oldSigTextCleaned)) : false);
764 763
 					}
765 764
 				}
766 765
 				else
767 766
 				{
768
-					$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
767
+					$found = (strlen(trim($oldSigTextCleaned)) > 0 ?strpos($content['body'], trim($oldSigTextCleaned)) : false);
769 768
 				}
770 769
 
771
-				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
770
+				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
772 771
 				{
773 772
 					//error_log(__METHOD__.'Old Content:'.$content['body'].'#');
774
-					$_oldSigText = preg_quote($oldSigTextCleaned,'~');
773
+					$_oldSigText = preg_quote($oldSigTextCleaned, '~');
775 774
 					//error_log(__METHOD__.'Old(masked):'.$_oldSigText.'#');
776
-					$content['body'] = preg_replace('~'.$_oldSigText.'~mi',$sigText,$content['body'],1);
775
+					$content['body'] = preg_replace('~'.$_oldSigText.'~mi', $sigText, $content['body'], 1);
777 776
 					//error_log(__METHOD__.'new Content:'.$content['body'].'#');
778 777
 				}
779 778
 
780
-				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
779
+				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
781 780
 				{
782 781
 					// if there is no sig selected, there is no way to replace a signature
783 782
 				}
784 783
 
785 784
 				if ($found === false)
786 785
 				{
787
-					if($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
788
-					if($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
786
+					if ($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
787
+					if ($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
789 788
 				}
790 789
 				else
791 790
 				{
@@ -820,7 +819,7 @@  discard block
 block discarded – undo
820 819
 		if ($isFirstLoad)
821 820
 		{
822 821
 			$alwaysAttachVCardAtCompose = false; // we use this to eliminate double attachments, if users VCard is already present/attached
823
-			if ( isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
822
+			if (isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
824 823
 				$this->mailPreferences['attachVCardAtCompose']))
825 824
 			{
826 825
 				$alwaysAttachVCardAtCompose = true;
@@ -829,7 +828,7 @@  discard block
 block discarded – undo
829 828
 					$f = $_REQUEST['preset']['file'];
830 829
 					$_REQUEST['preset']['file'] = array($f);
831 830
 				}
832
-				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')."/.entry";
831
+				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')."/.entry";
833 832
 			}
834 833
 			// an app passed the request for fetching and mailing an entry
835 834
 			if (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id']))
@@ -838,33 +837,33 @@  discard block
 block discarded – undo
838 837
 				$mt = $_REQUEST['method'];
839 838
 				$id = $_REQUEST['id'];
840 839
 				// passed method MUST be registered
841
-				$method = Link::get_registry($app,$mt);
840
+				$method = Link::get_registry($app, $mt);
842 841
 				//error_log(__METHOD__.__LINE__.array2string($method));
843 842
 				if ($method)
844 843
 				{
845
-					$res = ExecMethod($method,array($id,'html'));
844
+					$res = ExecMethod($method, array($id, 'html'));
846 845
 					//error_log(__METHOD__.__LINE__.array2string($res));
847 846
 					if (!empty($res))
848 847
 					{
849 848
 						$insertSigOnTop = 'below';
850 849
 						if (isset($res['attachments']) && is_array($res['attachments']))
851 850
 						{
852
-							foreach($res['attachments'] as $f)
851
+							foreach ($res['attachments'] as $f)
853 852
 							{
854 853
 								$_REQUEST['preset']['file'][] = $f;
855 854
 							}
856 855
 						}
857 856
 						$content['subject'] = lang($app).' #'.$res['id'].': ';
858
-						foreach(array('subject','body','mimetype') as $name) {
857
+						foreach (array('subject', 'body', 'mimetype') as $name) {
859 858
 							$sName = $name;
860
-							if ($name=='mimetype'&&$res[$name])
859
+							if ($name == 'mimetype' && $res[$name])
861 860
 							{
862 861
 								$sName = 'mimeType';
863 862
 								$content[$sName] = $res[$name];
864 863
 							}
865 864
 							else
866 865
 							{
867
-								if ($res[$name]) $content[$sName] .= (strlen($content[$sName])>0 ? ' ':'') .$res[$name];
866
+								if ($res[$name]) $content[$sName] .= (strlen($content[$sName]) > 0 ? ' ' : '').$res[$name];
868 867
 							}
869 868
 						}
870 869
 					}
@@ -873,46 +872,46 @@  discard block
 block discarded – undo
873 872
 			// handle preset info/values
874 873
 			if (is_array($_REQUEST['preset']))
875 874
 			{
876
-				$alreadyProcessed=array();
875
+				$alreadyProcessed = array();
877 876
 				//_debug_array($_REQUEST);
878 877
 				if ($_REQUEST['preset']['mailto']) {
879 878
 					// handle mailto strings such as
880 879
 					// mailto:larry,dan?cc=mike&bcc=sue&subject=test&body=type+your&body=message+here
881 880
 					// the above string may be htmlentyty encoded, then multiple body tags are supported
882 881
 					// first, strip the mailto: string out of the mailto URL
883
-					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'],'mailto')===false?$_REQUEST['preset']['mailto']:trim(substr(html_entity_decode($_REQUEST['preset']['mailto']),7)));
882
+					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'], 'mailto') === false ? $_REQUEST['preset']['mailto'] : trim(substr(html_entity_decode($_REQUEST['preset']['mailto']), 7)));
884 883
 					// check if there is more than the to address
885
-					$mailtoArray = explode('?',$tmp_send_to,2);
884
+					$mailtoArray = explode('?', $tmp_send_to, 2);
886 885
 					if ($mailtoArray[1]) {
887 886
 						// check if there are more than one requests
888
-						$addRequests = explode('&',$mailtoArray[1]);
887
+						$addRequests = explode('&', $mailtoArray[1]);
889 888
 						foreach ($addRequests as $key => $reqval) {
890 889
 							// the additional requests should have a =, to separate key from value.
891 890
 							$reqval = preg_replace('/__AMPERSAND__/i', "&", $reqval);
892
-							$keyValuePair = explode('=',$reqval,2);
893
-							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]])>0 ? ' ':'') . $keyValuePair[1];
891
+							$keyValuePair = explode('=', $reqval, 2);
892
+							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]]) > 0 ? ' ' : '').$keyValuePair[1];
894 893
 						}
895 894
 					}
896
-					$content['to']= preg_replace('/__AMPERSAND__/i', "&", $mailtoArray[0]);
897
-					$alreadyProcessed['to']='to';
895
+					$content['to'] = preg_replace('/__AMPERSAND__/i', "&", $mailtoArray[0]);
896
+					$alreadyProcessed['to'] = 'to';
898 897
 					// if the mailto string is not htmlentity decoded the arguments are passed as simple requests
899
-					foreach(array('cc','bcc','subject','body') as $name) {
900
-						$alreadyProcessed[$name]=$name;
901
-						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name])>0 ? ( $name == 'cc' || $name == 'bcc' ? ',' : ' ') : '') . $_REQUEST[$name];
898
+					foreach (array('cc', 'bcc', 'subject', 'body') as $name) {
899
+						$alreadyProcessed[$name] = $name;
900
+						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name]) > 0 ? ($name == 'cc' || $name == 'bcc' ? ',' : ' ') : '').$_REQUEST[$name];
902 901
 					}
903 902
 				}
904 903
 
905 904
 				if ($_REQUEST['preset']['mailtocontactbyid']) {
906 905
 					if ($GLOBALS['egw_info']['user']['apps']['addressbook']) {
907 906
 						$contacts_obj = new Api\Contacts();
908
-						$addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
909
-						if (method_exists($contacts_obj,'search')) {
907
+						$addressbookprefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook'];
908
+						if (method_exists($contacts_obj, 'search')) {
910 909
 
911
-							$addressArray = explode(',',$_REQUEST['preset']['mailtocontactbyid']);
910
+							$addressArray = explode(',', $_REQUEST['preset']['mailtocontactbyid']);
912 911
 							foreach ((array)$addressArray as $id => $addressID)
913 912
 							{
914
-								$addressID = (int) $addressID;
915
-								if (!($addressID>0))
913
+								$addressID = (int)$addressID;
914
+								if (!($addressID > 0))
916 915
 								{
917 916
 									unset($addressArray[$id]);
918 917
 								}
@@ -921,47 +920,47 @@  discard block
 block discarded – undo
921 920
 							{
922 921
 								$_searchCond = array('contact_id'=>$addressArray);
923 922
 								//error_log(__METHOD__.__LINE__.$_searchString);
924
-								$showAccounts= $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== '1';
925
-								$filter = ($showAccounts?array():array('account_id' => null));
926
-								$filter['cols_to_search']=array('n_fn','email','email_home');
927
-								$contacts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter);
923
+								$showAccounts = $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== '1';
924
+								$filter = ($showAccounts ? array() : array('account_id' => null));
925
+								$filter['cols_to_search'] = array('n_fn', 'email', 'email_home');
926
+								$contacts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
928 927
 								// additionally search the accounts, if the contact storage is not the account storage
929 928
 								if ($showAccounts &&
930 929
 									$GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
931 930
 									$GLOBALS['egw_info']['server']['contact_repository'] == 'sql')
932 931
 								{
933
-									$accounts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),array('owner' => 0));
932
+									$accounts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), array('owner' => 0));
934 933
 
935 934
 									if ($contacts && $accounts)
936 935
 									{
937
-										$contacts = array_merge($contacts,$accounts);
936
+										$contacts = array_merge($contacts, $accounts);
938 937
 										usort($contacts, function($a, $b)
939 938
 										{
940 939
 											return strcasecmp($a['n_fn'], $b['n_fn']);
941 940
 										});
942 941
 									}
943
-									elseif($accounts)
942
+									elseif ($accounts)
944 943
 									{
945
-										$contacts =& $accounts;
944
+										$contacts = & $accounts;
946 945
 									}
947 946
 									unset($accounts);
948 947
 								}
949 948
 							}
950
-							if(is_array($contacts)) {
949
+							if (is_array($contacts)) {
951 950
 								$mailtoArray = array();
952 951
 								$primary = $addressbookprefs['distributionListPreferredMail'];
953 952
 								if ($primary != 'email' && $primary != 'email_home') $primary = 'email';
954
-								$secondary = ($primary == 'email'?'email_home':'email');
953
+								$secondary = ($primary == 'email' ? 'email_home' : 'email');
955 954
 								//error_log(__METHOD__.__LINE__.array2string($contacts));
956
-								foreach($contacts as $contact) {
957
-									$innerCounter=0;
958
-									foreach(array($contact[$primary],$contact[$secondary]) as $email) {
955
+								foreach ($contacts as $contact) {
956
+									$innerCounter = 0;
957
+									foreach (array($contact[$primary], $contact[$secondary]) as $email) {
959 958
 										// use pref distributionListPreferredMail for the primary address
960 959
 										// avoid wrong addresses, if an rfc822 encoded address is in addressbook
961
-										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
962
-										$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
963
-										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>');
964
-										if($innerCounter==0 && !empty($email) && in_array($completeMailString ,$mailtoArray) === false) {
960
+										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/", '$2', $email);
961
+										$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
962
+										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']).' <'.trim($email).'>');
963
+										if ($innerCounter == 0 && !empty($email) && in_array($completeMailString, $mailtoArray) === false) {
965 964
 											$i++;
966 965
 											$innerCounter++;
967 966
 											$mailtoArray[$i] = $completeMailString;
@@ -970,8 +969,8 @@  discard block
 block discarded – undo
970 969
 								}
971 970
 							}
972 971
 							//error_log(__METHOD__.__LINE__.array2string($mailtoArray));
973
-							$alreadyProcessed['to']='to';
974
-							$content['to']=$mailtoArray;
972
+							$alreadyProcessed['to'] = 'to';
973
+							$content['to'] = $mailtoArray;
975 974
 						}
976 975
 					}
977 976
 				}
@@ -986,23 +985,23 @@  discard block
 block discarded – undo
986 985
 					$remember = array();
987 986
 					if (isset($_REQUEST['preset']['mailto']) || (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id'])))
988 987
 					{
989
-						foreach(array_keys($content) as $k)
988
+						foreach (array_keys($content) as $k)
990 989
 						{
991
-							if (in_array($k,array('to','cc','bcc','subject','body','mimeType'))&&isset($this->sessionData[$k]))
990
+							if (in_array($k, array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType')) && isset($this->sessionData[$k]))
992 991
 							{
993
-								$alreadyProcessed[$k]=$k;
992
+								$alreadyProcessed[$k] = $k;
994 993
 								$remember[$k] = $this->sessionData[$k];
995 994
 							}
996 995
 						}
997 996
 					}
998
-					if(!empty($remember)) $content = array_merge($content,$remember);
997
+					if (!empty($remember)) $content = array_merge($content, $remember);
999 998
 				}
1000
-				foreach(array('to','cc','bcc','subject','body','mimeType') as $name)
999
+				foreach (array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType') as $name)
1001 1000
 				{
1002 1001
 					//always handle mimeType
1003
-					if ($name=='mimeType' && $_REQUEST['preset'][$name])
1002
+					if ($name == 'mimeType' && $_REQUEST['preset'][$name])
1004 1003
 					{
1005
-						$_content[$name]=$content[$name]=$_REQUEST['preset'][$name];
1004
+						$_content[$name] = $content[$name] = $_REQUEST['preset'][$name];
1006 1005
 					}
1007 1006
 					//skip if already processed by "preset Routines"
1008 1007
 					if ($alreadyProcessed[$name]) continue;
@@ -1015,36 +1014,36 @@  discard block
 block discarded – undo
1015 1014
 			{
1016 1015
 				$content['to'] = base64_decode($_REQUEST['send_to']);
1017 1016
 				// first check if there is a questionmark or ampersand
1018
-				if (strpos($content['to'],'?')!== false) list($content['to'],$rest) = explode('?',$content['to'],2);
1017
+				if (strpos($content['to'], '?') !== false) list($content['to'], $rest) = explode('?', $content['to'], 2);
1019 1018
 				$content['to'] = html_entity_decode($content['to']);
1020
-				if (($at_pos = strpos($content['to'],'@')) !== false)
1019
+				if (($at_pos = strpos($content['to'], '@')) !== false)
1021 1020
 				{
1022
-					if (($amp_pos = strpos(substr($content['to'],$at_pos),'&')) !== false)
1021
+					if (($amp_pos = strpos(substr($content['to'], $at_pos), '&')) !== false)
1023 1022
 					{
1024 1023
 						//list($email,$addoptions) = explode('&',$value,2);
1025
-						$email = substr($content['to'],0,$amp_pos+$at_pos);
1026
-						$rest = substr($content['to'], $amp_pos+$at_pos+1);
1024
+						$email = substr($content['to'], 0, $amp_pos + $at_pos);
1025
+						$rest = substr($content['to'], $amp_pos + $at_pos + 1);
1027 1026
 						//error_log(__METHOD__.__LINE__.$email.' '.$rest);
1028 1027
 						$content['to'] = $email;
1029 1028
 					}
1030 1029
 				}
1031
-				if (strpos($content['to'],'%40')!== false) $content['to'] = Api\Html::purify(str_replace('%40','@',$content['to']));
1030
+				if (strpos($content['to'], '%40') !== false) $content['to'] = Api\Html::purify(str_replace('%40', '@', $content['to']));
1032 1031
 				$rarr = array(Api\Html::purify($rest));
1033
-				if (isset($rest)&&!empty($rest) && strpos($rest,'&')!== false) $rarr = explode('&',$rest);
1032
+				if (isset($rest) && !empty($rest) && strpos($rest, '&') !== false) $rarr = explode('&', $rest);
1034 1033
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($rarr));
1035 1034
 				$karr = array();
1036 1035
 				foreach ($rarr as &$rval)
1037 1036
 				{
1038 1037
 					//must contain =
1039
-					if (strpos($rval,'=')!== false)
1038
+					if (strpos($rval, '=') !== false)
1040 1039
 					{
1041
-						list($k,$v) = explode('=',$rval,2);
1040
+						list($k, $v) = explode('=', $rval, 2);
1042 1041
 						$karr[$k] = (string)$v;
1043
-						unset($k,$v);
1042
+						unset($k, $v);
1044 1043
 					}
1045 1044
 				}
1046 1045
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($karr));
1047
-				foreach(array('cc','bcc','subject','body') as $name)
1046
+				foreach (array('cc', 'bcc', 'subject', 'body') as $name)
1048 1047
 				{
1049 1048
 					if ($karr[$name]) $content[$name] = $karr[$name];
1050 1049
 				}
@@ -1056,17 +1055,17 @@  discard block
 block discarded – undo
1056 1055
 		if ($isFirstLoad && !empty($_REQUEST['mimeType']))
1057 1056
 		{
1058 1057
 			$_content['mimeType'] = $content['mimeType'];
1059
-			if (($_REQUEST['mimeType']=="text" ||$_REQUEST['mimeType']=="plain") && $content['mimeType'] == 'html')
1058
+			if (($_REQUEST['mimeType'] == "text" || $_REQUEST['mimeType'] == "plain") && $content['mimeType'] == 'html')
1060 1059
 			{
1061
-				$_content['mimeType'] = $content['mimeType']  = 'plain';
1062
-				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1060
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
1061
+				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1063 1062
 			}
1064
-			if ($_REQUEST['mimeType']=="html" && $content['mimeType'] != 'html')
1063
+			if ($_REQUEST['mimeType'] == "html" && $content['mimeType'] != 'html')
1065 1064
 			{
1066
-				$_content['mimeType'] = $content['mimeType']  = 'html';
1065
+				$_content['mimeType'] = $content['mimeType'] = 'html';
1067 1066
 				$content['body'] = "<pre>".$content['body']."</pre>";
1068 1067
 				// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1069
-				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);
1068
+				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);
1070 1069
 			}
1071 1070
 		}
1072 1071
 		else
@@ -1074,24 +1073,24 @@  discard block
 block discarded – undo
1074 1073
 			// try to enforce a mimeType on reply ( if type is not of the wanted type )
1075 1074
 			if ($isReply)
1076 1075
 			{
1077
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="text" &&
1076
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "text" &&
1078 1077
 					$content['mimeType'] == 'html')
1079 1078
 				{
1080
-					$_content['mimeType'] = $content['mimeType']  = 'plain';
1081
-					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1079
+					$_content['mimeType'] = $content['mimeType'] = 'plain';
1080
+					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1082 1081
 				}
1083
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="html" &&
1082
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "html" &&
1084 1083
 					$content['mimeType'] != 'html')
1085 1084
 				{
1086
-					$_content['mimeType'] = $content['mimeType']  = 'html';
1085
+					$_content['mimeType'] = $content['mimeType'] = 'html';
1087 1086
 					$content['body'] = "<pre>".$content['body']."</pre>";
1088 1087
 					// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1089
-					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);
1088
+					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);
1090 1089
 				}
1091 1090
 			}
1092 1091
 		}
1093 1092
 
1094
-		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible()===false)
1093
+		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible() === false)
1095 1094
 		{
1096 1095
 			$_content['mimeType'] = $content['mimeType'] = 'plain';
1097 1096
 			$content['body'] = $this->convertHTMLToText($content['body']);
@@ -1110,38 +1109,38 @@  discard block
 block discarded – undo
1110 1109
 		//_debug_array(($presetSig ? $presetSig : $content['mailidentity']));
1111 1110
 		try
1112 1111
 		{
1113
-			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig,true);
1112
+			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig, true);
1114 1113
 		}
1115 1114
 		catch (Exception $e)
1116 1115
 		{
1117 1116
 			//PROBABLY NOT FOUND
1118
-			$signature=array();
1117
+			$signature = array();
1119 1118
 		}
1120 1119
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
1121 1120
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
1122 1121
 			empty($signature['ident_signature']) ||
1123
-			trim($this->convertHTMLToText($signature['ident_signature'],true,true)) =='' ||
1122
+			trim($this->convertHTMLToText($signature['ident_signature'], true, true)) == '' ||
1124 1123
 			$this->mailPreferences['insertSignatureAtTopOfMessage'] == '1')
1125 1124
 		{
1126 1125
 			$disableRuler = true;
1127 1126
 		}
1128 1127
 		$font_span = $font_part = '';
1129
-		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1128
+		if ($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1130 1129
 			// User preferences for style
1131 1130
 			$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
1132 1131
 			$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
1133
-			$font_part = '<span style="width:100%; display: inline; '.($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'">';
1132
+			$font_part = '<span style="width:100%; display: inline; '.($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').'">';
1134 1133
 			$font_span = $font_part.'&#8203;</span>';
1135 1134
 			if (empty($font) && empty($font_size)) $font_span = '';
1136 1135
 		}
1137 1136
 		// 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
1138
-		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false) $font_span = '';
1137
+		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'], $font_part) === false) $font_span = '';
1139 1138
 		//remove possible html header stuff
1140
-		if (stripos($content['body'],'<html><head></head><body>')!==false) $content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1139
+		if (stripos($content['body'], '<html><head></head><body>') !== false) $content['body'] = str_ireplace(array('<html><head></head><body>', '</body></html>'), array('', ''), $content['body']);
1141 1140
 		//error_log(__METHOD__.__LINE__.array2string($this->mailPreferences));
1142
-		$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');
1143
-		if ($this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend' &&
1144
-			!(isset($_POST['mySigID']) && !empty($_POST['mySigID']) ) && !$suppressSigOnTop
1141
+		$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');
1142
+		if ($this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' &&
1143
+			!(isset($_POST['mySigID']) && !empty($_POST['mySigID'])) && !$suppressSigOnTop
1145 1144
 		)
1146 1145
 		{
1147 1146
 			// ON tOP OR BELOW? pREF CAN TELL
@@ -1151,57 +1150,57 @@  discard block
 block discarded – undo
1151 1150
 						'1' => 'before reply, visible during compose',
1152 1151
 						'no_belowaftersend'  => 'appended after reply before sending',
1153 1152
 			*/
1154
-			$insertSigOnTop = ($insertSigOnTop?$insertSigOnTop:($this->mailPreferences['insertSignatureAtTopOfMessage']?$this->mailPreferences['insertSignatureAtTopOfMessage']:'below'));
1155
-			$sigText = Mail::merge($signature['ident_signature'],array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
1153
+			$insertSigOnTop = ($insertSigOnTop ? $insertSigOnTop : ($this->mailPreferences['insertSignatureAtTopOfMessage'] ? $this->mailPreferences['insertSignatureAtTopOfMessage'] : 'below'));
1154
+			$sigText = Mail::merge($signature['ident_signature'], array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
1156 1155
 			if ($content['mimeType'] == 'html')
1157 1156
 			{
1158
-				$sigTextStartsWithBlockElement = ($disableRuler?false:true);
1159
-				foreach($blockElements as $e)
1157
+				$sigTextStartsWithBlockElement = ($disableRuler ?false:true);
1158
+				foreach ($blockElements as $e)
1160 1159
 				{
1161 1160
 					if ($sigTextStartsWithBlockElement) break;
1162
-					if (stripos(trim($sigText),'<'.$e)===0) $sigTextStartsWithBlockElement = true;
1161
+					if (stripos(trim($sigText), '<'.$e) === 0) $sigTextStartsWithBlockElement = true;
1163 1162
 				}
1164 1163
 			}
1165
-			if($content['mimeType'] == 'html') {
1164
+			if ($content['mimeType'] == 'html') {
1166 1165
 				$before = $disableRuler ? '' : '<hr style="border:1px dotted silver; width:100%;">';
1167 1166
 				$inbetween = '';
1168 1167
 			} else {
1169
-				$before = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
1168
+				$before = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
1170 1169
 				$inbetween = "\r\n";
1171 1170
 			}
1172 1171
 			if ($content['mimeType'] == 'html')
1173 1172
 			{
1174
-				$sigText = ($sigTextStartsWithBlockElement?'':"<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement?'':"</div>");
1173
+				$sigText = ($sigTextStartsWithBlockElement ? '' : "<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement ? '' : "</div>");
1175 1174
 			}
1176 1175
 
1177 1176
 			if ($insertSigOnTop === 'below')
1178 1177
 			{
1179
-				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true));
1178
+				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true));
1180 1179
 			}
1181 1180
 			else
1182 1181
 			{
1183
-				$content['body'] = $font_span.$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true)).$inbetween.$content['body'];
1182
+				$content['body'] = $font_span.$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true)).$inbetween.$content['body'];
1184 1183
 			}
1185 1184
 		}
1186 1185
 		else
1187 1186
 		{
1188
-			$content['body'] = ($font_span?($isFirstLoad === "switchedplaintohtml"?$font_part:$font_span):/*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml"?"</span>":"");
1187
+			$content['body'] = ($font_span ? ($isFirstLoad === "switchedplaintohtml" ? $font_part : $font_span) : /*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml" ? "</span>" : "");
1189 1188
 		}
1190 1189
 		//error_log(__METHOD__.__LINE__.$content['body']);
1191 1190
 
1192 1191
 		// prepare body
1193 1192
 		// 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
1194
-		$content['body'] = Api\Translation::convert_jsonsafe($content['body'],'utf-8');
1193
+		$content['body'] = Api\Translation::convert_jsonsafe($content['body'], 'utf-8');
1195 1194
 		//error_log(__METHOD__.__LINE__.array2string($content));
1196 1195
 
1197 1196
 		// get identities of all accounts as "$acc_id:$ident_id" => $identity
1198 1197
 		$sel_options['mailaccount'] = $identities = array();
1199
-		foreach(Mail\Account::search(true,false) as $acc_id => $account)
1198
+		foreach (Mail\Account::search(true, false) as $acc_id => $account)
1200 1199
 		{
1201 1200
 			// do NOT add SMTP only accounts as identities
1202 1201
 			if (!$account->is_imap(false)) continue;
1203 1202
 
1204
-			foreach($account->identities($acc_id) as $ident_id => $identity)
1203
+			foreach ($account->identities($acc_id) as $ident_id => $identity)
1205 1204
 			{
1206 1205
 				$sel_options['mailaccount'][$acc_id.':'.$ident_id] = $identity;
1207 1206
 				$identities[$ident_id] = $identity;
@@ -1212,7 +1211,7 @@  discard block
 block discarded – undo
1212 1211
 		//$content['bcc'] = array('[email protected]','[email protected]');
1213 1212
 		// address stuff like from, to, cc, replyto
1214 1213
 		$destinationRows = 0;
1215
-		foreach(self::$destinations as $destination) {
1214
+		foreach (self::$destinations as $destination) {
1216 1215
 			if (!is_array($content[$destination]))
1217 1216
 			{
1218 1217
 				if (!empty($content[$destination])) $content[$destination] = (array)$content[$destination];
@@ -1220,22 +1219,22 @@  discard block
 block discarded – undo
1220 1219
 			$addr_content = $content[strtolower($destination)];
1221 1220
 			// we clear the given address array and rebuild it
1222 1221
 			unset($content[strtolower($destination)]);
1223
-			foreach((array)$addr_content as $key => $value) {
1224
-				if ($value=="NIL@NIL") continue;
1225
-				if ($destination=='replyto' && str_replace('"','',$value) ==
1226
-					str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
1222
+			foreach ((array)$addr_content as $key => $value) {
1223
+				if ($value == "NIL@NIL") continue;
1224
+				if ($destination == 'replyto' && str_replace('"', '', $value) ==
1225
+					str_replace('"', '', $identities[$this->mail_bo->getDefaultIdentity()]))
1227 1226
 				{
1228 1227
 					// preserve/restore the value to content.
1229
-					$content[strtolower($destination)][]=$value;
1228
+					$content[strtolower($destination)][] = $value;
1230 1229
 					continue;
1231 1230
 				}
1232 1231
 				//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
1233
-				$value = str_replace("\"\"",'"', htmlspecialchars_decode($value, ENT_COMPAT));
1234
-				foreach(Mail::parseAddressList($value) as $addressObject) {
1232
+				$value = str_replace("\"\"", '"', htmlspecialchars_decode($value, ENT_COMPAT));
1233
+				foreach (Mail::parseAddressList($value) as $addressObject) {
1235 1234
 					if ($addressObject->host == '.SYNTAX-ERROR.') continue;
1236
-					$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
1235
+					$address = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
1237 1236
 					//$address = Mail::htmlentities($address, $this->displayCharset);
1238
-					$content[strtolower($destination)][]=$address;
1237
+					$content[strtolower($destination)][] = $address;
1239 1238
 					$destinationRows++;
1240 1239
 				}
1241 1240
 			}
@@ -1243,10 +1242,10 @@  discard block
 block discarded – undo
1243 1242
 		if ($_content)
1244 1243
 		{
1245 1244
 			//input array of _content had no signature information but was seeded later, and content has a valid setting
1246
-			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content)) unset($_content['mailidentity']);
1247
-			$content = array_merge($content,$_content);
1245
+			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity', $_content)) unset($_content['mailidentity']);
1246
+			$content = array_merge($content, $_content);
1248 1247
 
1249
-			if (!empty($content['folder'])) $sel_options['folder']=$this->ajax_searchFolder(0,true);
1248
+			if (!empty($content['folder'])) $sel_options['folder'] = $this->ajax_searchFolder(0, true);
1250 1249
 			if (empty($content['mailaccount'])) $content['mailaccount'] = $this->mail_bo->profileID;
1251 1250
 		}
1252 1251
 		else
@@ -1255,12 +1254,12 @@  discard block
 block discarded – undo
1255 1254
 			$content['mailaccount'] = $this->mail_bo->profileID;
1256 1255
 			//error_log(__METHOD__.__LINE__.$content['body']);
1257 1256
 		}
1258
-		$content['is_html'] = ($content['mimeType'] == 'html'?true:'');
1259
-		$content['is_plain'] = ($content['mimeType'] == 'html'?'':true);
1260
-		$content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text'] =$content['body'];
1261
-		$content['showtempname']=0;
1257
+		$content['is_html'] = ($content['mimeType'] == 'html' ?true:'');
1258
+		$content['is_plain'] = ($content['mimeType'] == 'html' ? '' : true);
1259
+		$content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text'] = $content['body'];
1260
+		$content['showtempname'] = 0;
1262 1261
 		//if (is_array($content['attachments']))error_log(__METHOD__.__LINE__.'before merging content with uploadforCompose:'.array2string($content['attachments']));
1263
-		$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)));
1262
+		$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)));
1264 1263
 		//if (is_array($content['attachments'])) foreach($content['attachments'] as $k => &$file) $file['delete['.$file['tmp_name'].']']=0;
1265 1264
 		$content['no_griddata'] = empty($content['attachments']);
1266 1265
 		$preserv['attachments'] = $content['attachments'];
@@ -1294,12 +1293,12 @@  discard block
 block discarded – undo
1294 1293
 		$sel_options['mimeType'] = self::$mimeTypes;
1295 1294
 		$sel_options['priority'] = self::$priorities;
1296 1295
 		$sel_options['filemode'] = Vfs\Sharing::$modes;
1297
-		if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
1296
+		if (!isset($content['priority']) || empty($content['priority'])) $content['priority'] = 3;
1298 1297
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
1299 1298
 		$etpl = new Etemplate('mail.compose');
1300 1299
 
1301 1300
 		$etpl->setElementAttribute('composeToolbar', 'actions', self::getToolbarActions($content));
1302
-		if ($content['mimeType']=='html')
1301
+		if ($content['mimeType'] == 'html')
1303 1302
 		{
1304 1303
 			//mode="$cont[rtfEditorFeatures]" validation_rules="$cont[validation_rules]" base_href="$cont[upload_dir]"
1305 1304
 			$_htmlConfig = Mail::$htmLawed_config;
@@ -1309,23 +1308,23 @@  discard block
 block discarded – undo
1309 1308
 			// and not the eGroupware wide pref to prevent users from trying things that will potentially not work
1310 1309
 			// or not work as expected, as a full featured editor that may be wanted in other apps
1311 1310
 			// is way overloading the "normal" needs for composing mails
1312
-			$content['rtfEditorFeatures']='simple-withimage';//Api\Html\CkEditorConfig::get_ckeditor_config();
1311
+			$content['rtfEditorFeatures'] = 'simple-withimage'; //Api\Html\CkEditorConfig::get_ckeditor_config();
1313 1312
 			//$content['rtfEditorFeatures']='advanced';//Api\Html\CkEditorConfig::get_ckeditor_config();
1314
-			$content['validation_rules']= json_encode(Mail::$htmLawed_config);
1315
-			$etpl->setElementAttribute('mail_htmltext','mode',$content['rtfEditorFeatures']);
1316
-			$etpl->setElementAttribute('mail_htmltext','validation_rules',$content['validation_rules']);
1313
+			$content['validation_rules'] = json_encode(Mail::$htmLawed_config);
1314
+			$etpl->setElementAttribute('mail_htmltext', 'mode', $content['rtfEditorFeatures']);
1315
+			$etpl->setElementAttribute('mail_htmltext', 'validation_rules', $content['validation_rules']);
1317 1316
 			Mail::$htmLawed_config = $_htmlConfig;
1318 1317
 		}
1319 1318
 
1320
-		if (isset($content['composeID'])&&!empty($content['composeID']))
1319
+		if (isset($content['composeID']) && !empty($content['composeID']))
1321 1320
 		{
1322 1321
 			$composeCache = $content;
1323 1322
 			unset($composeCache['body']);
1324 1323
 			unset($composeCache['mail_htmltext']);
1325 1324
 			unset($composeCache['mail_plaintext']);
1326
-			Api\Cache::setCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID,$composeCache,$expiration=60*60*2);
1325
+			Api\Cache::setCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID, $composeCache, $expiration = 60 * 60 * 2);
1327 1326
 		}
1328
-		if (!isset($_content['serverID'])||empty($_content['serverID']))
1327
+		if (!isset($_content['serverID']) || empty($_content['serverID']))
1329 1328
 		{
1330 1329
 			$content['serverID'] = $this->mail_bo->profileID;
1331 1330
 		}
@@ -1341,13 +1340,13 @@  discard block
 block discarded – undo
1341 1340
 		$preserv['list-id'] = $content['list-id'];
1342 1341
 		$preserv['mode'] = $content['mode'];
1343 1342
 		// convert it back to checkbox expectations
1344
-		if($content['mimeType'] == 'html') {
1345
-			$content['mimeType']=1;
1343
+		if ($content['mimeType'] == 'html') {
1344
+			$content['mimeType'] = 1;
1346 1345
 		} else {
1347
-			$content['mimeType']=0;
1346
+			$content['mimeType'] = 0;
1348 1347
 		}
1349 1348
 		// set the current selected mailaccount as param for folderselection
1350
-		$etpl->setElementAttribute('folder','autocomplete_params',array('mailaccount'=>$content['mailaccount']));
1349
+		$etpl->setElementAttribute('folder', 'autocomplete_params', array('mailaccount'=>$content['mailaccount']));
1351 1350
 		// join again mailaccount and identity
1352 1351
 		$content['mailaccount'] .= ':'.$content['mailidentity'];
1353 1352
 		//Try to set the initial selected account to the first identity match found
@@ -1366,14 +1365,14 @@  discard block
 block discarded – undo
1366 1365
 			}
1367 1366
 		}
1368 1367
 		// Resolve distribution list before send content to client
1369
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $f)
1368
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $f)
1370 1369
 		{
1371
-			if (is_array($content[$f])) $content[$f]= self::resolveEmailAddressList ($content[$f]);
1370
+			if (is_array($content[$f])) $content[$f] = self::resolveEmailAddressList($content[$f]);
1372 1371
 		}
1373 1372
 
1374 1373
 		$content['to'] = self::resolveEmailAddressList($content['to']);
1375 1374
 		//error_log(__METHOD__.__LINE__.array2string($content));
1376
-		$etpl->exec('mail.mail_compose.compose',$content,$sel_options,array(),$preserv,2);
1375
+		$etpl->exec('mail.mail_compose.compose', $content, $sel_options, array(), $preserv, 2);
1377 1376
 	}
1378 1377
 
1379 1378
 	/**
@@ -1388,7 +1387,7 @@  discard block
 block discarded – undo
1388 1387
 	 * @param string $_insertSigOnTop
1389 1388
 	 * @param boolean $_eliminateDoubleAttachments
1390 1389
 	 */
1391
-	function addPresetFiles (&$_content, &$_insertSigOnTop, $_eliminateDoubleAttachments)
1390
+	function addPresetFiles(&$_content, &$_insertSigOnTop, $_eliminateDoubleAttachments)
1392 1391
 	{
1393 1392
 		// check if JSON was used
1394 1393
 		if (!is_array($_REQUEST['preset']['file']) &&
@@ -1410,19 +1409,19 @@  discard block
 block discarded – undo
1410 1409
 				(array)$_REQUEST['preset']['name'] : array();
1411 1410
 		}
1412 1411
 
1413
-		foreach($files as $k => $path)
1412
+		foreach ($files as $k => $path)
1414 1413
 		{
1415
-			if (!empty($types[$k]) && stripos($types[$k],'text/calendar')!==false)
1414
+			if (!empty($types[$k]) && stripos($types[$k], 'text/calendar') !== false)
1416 1415
 			{
1417 1416
 				$_insertSigOnTop = 'below';
1418 1417
 			}
1419 1418
 			//error_log(__METHOD__.__LINE__.$path.'->'.array2string(parse_url($path,PHP_URL_SCHEME == 'vfs')));
1420
-			if (($scheme = parse_url($path,PHP_URL_SCHEME)) === 'vfs')
1419
+			if (($scheme = parse_url($path, PHP_URL_SCHEME)) === 'vfs')
1421 1420
 			{
1422 1421
 				$type = Vfs::mime_content_type($path);
1423 1422
 				// special handling for attaching vCard of iCal --> use their link-title as name
1424
-				if (substr($path,-7) != '/.entry' ||
1425
-					!(list($app,$id) = array_slice(explode('/',$path),-3)) ||
1423
+				if (substr($path, -7) != '/.entry' ||
1424
+					!(list($app, $id) = array_slice(explode('/', $path), -3)) ||
1426 1425
 					!($name = Link::title($app, $id)))
1427 1426
 				{
1428 1427
 					$name = Vfs::decodePath(Vfs::basename($path));
@@ -1436,7 +1435,7 @@  discard block
 block discarded – undo
1436 1435
 				{
1437 1436
 					$type = $types[$k];
1438 1437
 				}
1439
-				$path = str_replace('+','%2B',$path);
1438
+				$path = str_replace('+', '%2B', $path);
1440 1439
 				$formData = array(
1441 1440
 					'name' => $name,
1442 1441
 					'type' => $type,
@@ -1454,7 +1453,7 @@  discard block
 block discarded – undo
1454 1453
 			{
1455 1454
 				error_log(__METHOD__."() Attaching '$path' outside configured temp. directory '{$GLOBALS['egw_info']['server']['temp_dir']}' denied!");
1456 1455
 			}
1457
-			elseif(is_readable($path))
1456
+			elseif (is_readable($path))
1458 1457
 			{
1459 1458
 				$formData = array(
1460 1459
 					'name' => isset($names[$k]) ? $names[$k] : basename($path),
@@ -1467,7 +1466,7 @@  discard block
 block discarded – undo
1467 1466
 			{
1468 1467
 				continue;
1469 1468
 			}
1470
-			$this->addAttachment($formData,$_content, $_eliminateDoubleAttachments);
1469
+			$this->addAttachment($formData, $_content, $_eliminateDoubleAttachments);
1471 1470
 		}
1472 1471
 	}
1473 1472
 
@@ -1489,9 +1488,9 @@  discard block
 block discarded – undo
1489 1488
 		$content = array();
1490 1489
 		//error_log(__METHOD__.__LINE__.array2string($mail_id).", $part_id, $from, $_focusElement, $suppressSigOnTop, $isReply");
1491 1490
 		// on forward we may have to support multiple ids
1492
-		if ($from=='forward')
1491
+		if ($from == 'forward')
1493 1492
 		{
1494
-			$replyIds = explode(',',$mail_id);
1493
+			$replyIds = explode(',', $mail_id);
1495 1494
 			$mail_id = $replyIds[0];
1496 1495
 		}
1497 1496
 		$hA = mail_ui::splitRowID($mail_id);
@@ -1503,15 +1502,15 @@  discard block
 block discarded – undo
1503 1502
 			$this->changeProfile($icServerID);
1504 1503
 		}
1505 1504
 		$icServer = $this->mail_bo->icServer;
1506
-		if (!empty($folder) && !empty($msgUID) )
1505
+		if (!empty($folder) && !empty($msgUID))
1507 1506
 		{
1508 1507
 			// this fill the session data with the values from the original email
1509
-			switch($from)
1508
+			switch ($from)
1510 1509
 			{
1511 1510
 				case 'composefromdraft':
1512 1511
 				case 'composeasnew':
1513 1512
 					$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
1514
-					if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
1513
+					if ($from == 'composefromdraft') $content['mode'] = 'composefromdraft';
1515 1514
 					$content['processedmail_id'] = $mail_id;
1516 1515
 
1517 1516
 					$_focusElement = 'body';
@@ -1527,7 +1526,7 @@  discard block
 block discarded – undo
1527 1526
 					$isReply = true;
1528 1527
 					break;
1529 1528
 				case 'forward':
1530
-					$mode  = ($_GET['mode']=='forwardinline'?'inline':'asmail');
1529
+					$mode = ($_GET['mode'] == 'forwardinline' ? 'inline' : 'asmail');
1531 1530
 					// this fill the session data with the values from the original email
1532 1531
 					foreach ($replyIds as &$mail_id)
1533 1532
 					{
@@ -1537,14 +1536,14 @@  discard block
 block discarded – undo
1537 1536
 						$folder = $hA['folder'];
1538 1537
 						$content = $this->getForwardData($icServer, $folder, $msgUID, $part_id, $mode);
1539 1538
 					}
1540
-					$content['processedmail_id'] = implode(',',$replyIds);
1539
+					$content['processedmail_id'] = implode(',', $replyIds);
1541 1540
 					$content['mode'] = 'forward';
1542
-					$isReply = ($mode?$mode=='inline':$this->mailPreferences['message_forwarding'] == 'inline');
1543
-					$suppressSigOnTop = false;// ($mode && $mode=='inline'?true:false);// may be a better solution
1541
+					$isReply = ($mode ? $mode == 'inline' : $this->mailPreferences['message_forwarding'] == 'inline');
1542
+					$suppressSigOnTop = false; // ($mode && $mode=='inline'?true:false);// may be a better solution
1544 1543
 					$_focusElement = 'to';
1545 1544
 					break;
1546 1545
 				default:
1547
-					error_log('Unhandled compose source: ' . $from);
1546
+					error_log('Unhandled compose source: '.$from);
1548 1547
 			}
1549 1548
 		}
1550 1549
 		else if ($from == 'merge' && $_REQUEST['document'])
@@ -1559,12 +1558,12 @@  discard block
 block discarded – undo
1559 1558
 			$document_merge = new $merge_class();
1560 1559
 			$this->mail_bo->openConnection();
1561 1560
 			$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
1562
-			if (!is_array($merge_ids)) $merge_ids = explode(',',$merge_ids);
1561
+			if (!is_array($merge_ids)) $merge_ids = explode(',', $merge_ids);
1563 1562
 			try
1564 1563
 			{
1565 1564
 				$merged_mail_id = '';
1566 1565
 				$folder = '';
1567
-				if(($error = $document_merge->check_document($_REQUEST['document'],'')))
1566
+				if (($error = $document_merge->check_document($_REQUEST['document'], '')))
1568 1567
 				{
1569 1568
 					$content['msg'] = $error;
1570 1569
 					return $content;
@@ -1574,10 +1573,10 @@  discard block
 block discarded – undo
1574 1573
 				//$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
1575 1574
 
1576 1575
 				// Actually do the merge
1577
-				if(count($merge_ids) <= 1)
1576
+				if (count($merge_ids) <= 1)
1578 1577
 				{
1579 1578
 					$results = $this->mail_bo->importMessageToMergeAndSend(
1580
-						$document_merge, Vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1579
+						$document_merge, Vfs::PREFIX.$_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1581 1580
 					);
1582 1581
 
1583 1582
 					// Open compose
@@ -1588,9 +1587,9 @@  discard block
 block discarded – undo
1588 1587
 				}
1589 1588
 				else
1590 1589
 				{
1591
-					$success = implode(', ',$results['success']);
1590
+					$success = implode(', ', $results['success']);
1592 1591
 					$fail = implode(', ', $results['failed']);
1593
-					if($success) Framework::message($success, 'success');
1592
+					if ($success) Framework::message($success, 'success');
1594 1593
 					Framework::window_close($fail);
1595 1594
 				}
1596 1595
 			}
@@ -1618,22 +1617,22 @@  discard block
 block discarded – undo
1618 1617
 		return 1;
1619 1618
 	}
1620 1619
 
1621
-	function convertHTMLToText(&$_html,$sourceishtml = true, $stripcrl=false, $noRepEmailAddr = false)
1620
+	function convertHTMLToText(&$_html, $sourceishtml = true, $stripcrl = false, $noRepEmailAddr = false)
1622 1621
 	{
1623 1622
 		$stripalltags = true;
1624 1623
 		// third param is stripalltags, we may not need that, if the source is already in ascii
1625
-		if (!$sourceishtml) $stripalltags=false;
1626
-		return Api\Mail\Html::convertHTMLToText($_html,$this->displayCharset,$stripcrl,$stripalltags, $noRepEmailAddr);
1624
+		if (!$sourceishtml) $stripalltags = false;
1625
+		return Api\Mail\Html::convertHTMLToText($_html, $this->displayCharset, $stripcrl, $stripalltags, $noRepEmailAddr);
1627 1626
 	}
1628 1627
 
1629 1628
 	function generateRFC822Address($_addressObject)
1630 1629
 	{
1631
-		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1632
-			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1633
-		} elseif($_addressObject->mailbox && $_addressObject->host) {
1634
-			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1630
+		if ($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1631
+			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1632
+		} elseif ($_addressObject->mailbox && $_addressObject->host) {
1633
+			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1635 1634
 		} else {
1636
-			return $this->mail_bo->decode_header($_addressObject->mailbox,true);
1635
+			return $this->mail_bo->decode_header($_addressObject->mailbox, true);
1637 1636
 		}
1638 1637
 	}
1639 1638
 
@@ -1648,9 +1647,9 @@  discard block
 block discarded – undo
1648 1647
 	// $_mode can be:
1649 1648
 	// single: for a reply to one address
1650 1649
 	// all: for a reply to all
1651
-	function getDraftData($_icServer, $_folder, $_uid, $_partID=NULL)
1650
+	function getDraftData($_icServer, $_folder, $_uid, $_partID = NULL)
1652 1651
 	{
1653
-		unset($_icServer);	// not used
1652
+		unset($_icServer); // not used
1654 1653
 		$this->sessionData['to'] = array();
1655 1654
 
1656 1655
 		$mail_bo = $this->mail_bo;
@@ -1659,7 +1658,7 @@  discard block
 block discarded – undo
1659 1658
 
1660 1659
 		// get message headers for specified message
1661 1660
 		#$headers	= $mail_bo->getMessageHeader($_folder, $_uid);
1662
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID);
1661
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID);
1663 1662
 		$addHeadInfo = $mail_bo->getMessageHeader($_uid, $_partID);
1664 1663
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
1665 1664
 		// horde does not support the encoding of thread-topic, and probably will not no so in the future
@@ -1667,10 +1666,10 @@  discard block
 block discarded – undo
1667 1666
 
1668 1667
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1669 1668
 		if (!empty($addHeadInfo['X-MAILFOLDER'])) {
1670
-			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val ) {
1671
-				$fval=$val;
1669
+			foreach (explode('|', $addHeadInfo['X-MAILFOLDER']) as $val) {
1670
+				$fval = $val;
1672 1671
 				$icServerID = $mail_bo->icServer->ImapServerId;
1673
-				if (stripos($val,'::')!==false) list($icServerID,$fval) = explode('::',$val,2);
1672
+				if (stripos($val, '::') !== false) list($icServerID, $fval) = explode('::', $val, 2);
1674 1673
 				if ($icServerID != $mail_bo->icServer->ImapServerId) continue;
1675 1674
 				if ($mail_bo->folderExists($fval)) $this->sessionData['folder'][] = $val;
1676 1675
 			}
@@ -1706,72 +1705,72 @@  discard block
 block discarded – undo
1706 1705
 			}
1707 1706
 		}
1708 1707
 		// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
1709
-		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);//array('uid'=>$_uid,'folder'=>$_folder);
1708
+		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid); //array('uid'=>$_uid,'folder'=>$_folder);
1710 1709
 		$this->sessionData['uid'] = $_uid;
1711 1710
 		$this->sessionData['messageFolder'] = $_folder;
1712 1711
 		$this->sessionData['isDraft'] = true;
1713 1712
 		$foundAddresses = array();
1714
-		foreach((array)$headers['CC'] as $val) {
1715
-			$rfcAddr=Mail::parseAddressList($val);
1713
+		foreach ((array)$headers['CC'] as $val) {
1714
+			$rfcAddr = Mail::parseAddressList($val);
1716 1715
 			$_rfcAddr = $rfcAddr[0];
1717 1716
 			if (!$_rfcAddr->valid) continue;
1718
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1717
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1719 1718
 				continue;
1720 1719
 			}
1721
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1722
-			if(!$foundAddresses[$keyemail]) {
1723
-				$address = $this->mail_bo->decode_header($val,true);
1720
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1721
+			if (!$foundAddresses[$keyemail]) {
1722
+				$address = $this->mail_bo->decode_header($val, true);
1724 1723
 				$this->sessionData['cc'][] = $val;
1725 1724
 				$foundAddresses[$keyemail] = true;
1726 1725
 			}
1727 1726
 		}
1728 1727
 
1729
-		foreach((array)$headers['TO'] as $val) {
1730
-			if(!is_array($val))
1728
+		foreach ((array)$headers['TO'] as $val) {
1729
+			if (!is_array($val))
1731 1730
 			{
1732 1731
 				$this->sessionData['to'][] = $val;
1733 1732
 				continue;
1734 1733
 			}
1735
-			$rfcAddr=Mail::parseAddressList($val);
1734
+			$rfcAddr = Mail::parseAddressList($val);
1736 1735
 			$_rfcAddr = $rfcAddr[0];
1737 1736
 			if (!$_rfcAddr->valid) continue;
1738
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1737
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1739 1738
 				continue;
1740 1739
 			}
1741
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1742
-			if(!$foundAddresses[$keyemail]) {
1743
-				$address = $this->mail_bo->decode_header($val,true);
1740
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1741
+			if (!$foundAddresses[$keyemail]) {
1742
+				$address = $this->mail_bo->decode_header($val, true);
1744 1743
 				$this->sessionData['to'][] = $val;
1745 1744
 				$foundAddresses[$keyemail] = true;
1746 1745
 			}
1747 1746
 		}
1748 1747
 
1749 1748
 		$fromAddr = Mail::parseAddressList($addHeadInfo['FROM'])[0];
1750
-		foreach((array)$headers['REPLY-TO'] as $val) {
1751
-			$rfcAddr=Mail::parseAddressList($val);
1749
+		foreach ((array)$headers['REPLY-TO'] as $val) {
1750
+			$rfcAddr = Mail::parseAddressList($val);
1752 1751
 			$_rfcAddr = $rfcAddr[0];
1753 1752
 			if (!$_rfcAddr->valid || ($_rfcAddr->mailbox == $fromAddr->mailbox && $_rfcAddr->host == $fromAddr->host)) continue;
1754
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1753
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1755 1754
 				continue;
1756 1755
 			}
1757
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1758
-			if(!$foundAddresses[$keyemail]) {
1759
-				$address = $this->mail_bo->decode_header($val,true);
1756
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1757
+			if (!$foundAddresses[$keyemail]) {
1758
+				$address = $this->mail_bo->decode_header($val, true);
1760 1759
 				$this->sessionData['replyto'][] = $val;
1761 1760
 				$foundAddresses[$keyemail] = true;
1762 1761
 			}
1763 1762
 		}
1764 1763
 
1765
-		foreach((array)$headers['BCC'] as $val) {
1766
-			$rfcAddr=Mail::parseAddressList($val);
1764
+		foreach ((array)$headers['BCC'] as $val) {
1765
+			$rfcAddr = Mail::parseAddressList($val);
1767 1766
 			$_rfcAddr = $rfcAddr[0];
1768 1767
 			if (!$_rfcAddr->valid) continue;
1769
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1768
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1770 1769
 				continue;
1771 1770
 			}
1772
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1773
-			if(!$foundAddresses[$keyemail]) {
1774
-				$address = $this->mail_bo->decode_header($val,true);
1771
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1772
+			if (!$foundAddresses[$keyemail]) {
1773
+				$address = $this->mail_bo->decode_header($val, true);
1775 1774
 				$this->sessionData['bcc'][] = $val;
1776 1775
 				$foundAddresses[$keyemail] = true;
1777 1776
 			}
@@ -1780,48 +1779,48 @@  discard block
 block discarded – undo
1780 1779
 		$this->sessionData['subject']	= $mail_bo->decode_header($headers['SUBJECT']);
1781 1780
 		// remove a printview tag if composing
1782 1781
 		$searchfor = '/^\['.lang('printview').':\]/';
1783
-		$this->sessionData['subject'] = preg_replace($searchfor,'',$this->sessionData['subject']);
1784
-		$bodyParts = $mail_bo->getMessageBody($_uid,'always_display', $_partID);
1782
+		$this->sessionData['subject'] = preg_replace($searchfor, '', $this->sessionData['subject']);
1783
+		$bodyParts = $mail_bo->getMessageBody($_uid, 'always_display', $_partID);
1785 1784
 		//_debug_array($bodyParts);
1786 1785
 		#$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
1787
-		if($bodyParts['0']['mimeType'] == 'text/html') {
1788
-			$this->sessionData['mimeType'] 	= 'html';
1786
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
1787
+			$this->sessionData['mimeType'] = 'html';
1789 1788
 
1790
-			for($i=0; $i<count($bodyParts); $i++) {
1791
-				if($i>0) {
1789
+			for ($i = 0; $i < count($bodyParts); $i++) {
1790
+				if ($i > 0) {
1792 1791
 					$this->sessionData['body'] .= '<hr>';
1793 1792
 				}
1794
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
1793
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
1795 1794
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']);
1796 1795
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
1797 1796
 				}
1798
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1797
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1799 1798
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1800 1799
 				#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1801
-				$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
1800
+				$this->sessionData['body'] .= ($i > 0 ? "<br>" : "").$bodyParts[$i]['body'];
1802 1801
 			}
1803 1802
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID);
1804 1803
 
1805 1804
 		} else {
1806
-			$this->sessionData['mimeType']	= 'plain';
1805
+			$this->sessionData['mimeType'] = 'plain';
1807 1806
 
1808
-			for($i=0; $i<count($bodyParts); $i++) {
1809
-				if($i>0) {
1807
+			for ($i = 0; $i < count($bodyParts); $i++) {
1808
+				if ($i > 0) {
1810 1809
 					$this->sessionData['body'] .= "<hr>";
1811 1810
 				}
1812
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1811
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1813 1812
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1814 1813
 				#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1815
-				$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
1814
+				$this->sessionData['body'] .= ($i > 0 ? "\r\n" : "").$bodyParts[$i]['body'];
1816 1815
 			}
1817
-			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID,'plain');
1816
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'plain');
1818 1817
 		}
1819 1818
 
1820
-		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID))) {
1821
-			foreach($attachments as $attachment) {
1819
+		if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID))) {
1820
+			foreach ($attachments as $attachment) {
1822 1821
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
1823 1822
 				$cid = $attachment['cid'];
1824
-				$match=null;
1823
+				$match = null;
1825 1824
 				preg_match("/cid:{$cid}/", $bodyParts['0']['body'], $match);
1826 1825
 				//error_log(__METHOD__.__LINE__.'searching for cid:'."/cid:{$cid}/".'#'.$r.'#'.array2string($match));
1827 1826
 				if (!$match || !$attachment['cid'])
@@ -1841,7 +1840,7 @@  discard block
 block discarded – undo
1841 1840
 
1842 1841
 	function getErrorInfo()
1843 1842
 	{
1844
-		if(isset($this->errorInfo)) {
1843
+		if (isset($this->errorInfo)) {
1845 1844
 			$errorInfo = $this->errorInfo;
1846 1845
 			unset($this->errorInfo);
1847 1846
 			return $errorInfo;
@@ -1849,39 +1848,39 @@  discard block
 block discarded – undo
1849 1848
 		return false;
1850 1849
 	}
1851 1850
 
1852
-	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode=false)
1851
+	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode = false)
1853 1852
 	{
1854 1853
 		if ($_mode)
1855 1854
 		{
1856 1855
 			$modebuff = $this->mailPreferences['message_forwarding'];
1857 1856
 			$this->mailPreferences['message_forwarding'] = $_mode;
1858 1857
 		}
1859
-		if  ($this->mailPreferences['message_forwarding'] == 'inline') {
1858
+		if ($this->mailPreferences['message_forwarding'] == 'inline') {
1860 1859
 			$this->getReplyData('forward', $_icServer, $_folder, $_uid, $_partID);
1861 1860
 		}
1862
-		$mail_bo    = $this->mail_bo;
1861
+		$mail_bo = $this->mail_bo;
1863 1862
 		$mail_bo->openConnection();
1864 1863
 		$mail_bo->reopen($_folder);
1865 1864
 
1866 1865
 		// get message headers for specified message
1867
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder);
1866
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder);
1868 1867
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1869 1868
 		//_debug_array($headers); exit;
1870 1869
 		// check for Re: in subject header
1871
-		$this->sessionData['subject'] 	= "[FWD] " . $mail_bo->decode_header($headers['SUBJECT']);
1870
+		$this->sessionData['subject'] = "[FWD] ".$mail_bo->decode_header($headers['SUBJECT']);
1872 1871
 		// the three attributes below are substituted by processedmail_id and mode
1873 1872
 		//$this->sessionData['sourceFolder']=$_folder;
1874 1873
 		//$this->sessionData['forwardFlag']='forwarded';
1875 1874
 		//$this->sessionData['forwardedUID']=$_uid;
1876
-		if  ($this->mailPreferences['message_forwarding'] == 'asmail') {
1877
-			$this->sessionData['mimeType']  = $this->mailPreferences['composeOptions'];
1878
-			if($headers['SIZE'])
1875
+		if ($this->mailPreferences['message_forwarding'] == 'asmail') {
1876
+			$this->sessionData['mimeType'] = $this->mailPreferences['composeOptions'];
1877
+			if ($headers['SIZE'])
1879 1878
 				$size				= $headers['SIZE'];
1880 1879
 			else
1881 1880
 				$size				= lang('unknown');
1882 1881
 
1883 1882
 			$this->addMessageAttachment($_uid, $_partID, $_folder,
1884
-				$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
1883
+				$mail_bo->decode_header(($headers['SUBJECT'] ? $headers['SUBJECT'] : lang('no subject'))).'.eml',
1885 1884
 				'MESSAGE/RFC822', $size);
1886 1885
 		}
1887 1886
 		else
@@ -1891,10 +1890,10 @@  discard block
 block discarded – undo
1891 1890
 			unset($this->sessionData['cc']);
1892 1891
 			try
1893 1892
 			{
1894
-				if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false))) {
1893
+				if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID, null, true, false, false))) {
1895 1894
 					//error_log(__METHOD__.__LINE__.':'.array2string($attachments));
1896
-					foreach($attachments as $attachment) {
1897
-						if (!($attachment['cid'] && preg_match("/image\//",$attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1895
+					foreach ($attachments as $attachment) {
1896
+						if (!($attachment['cid'] && preg_match("/image\//", $attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1898 1897
 						{
1899 1898
 							$this->addMessageAttachment($_uid, $attachment['partID'],
1900 1899
 								$_folder,
@@ -1912,7 +1911,7 @@  discard block
 block discarded – undo
1912 1911
 						' because the content of this message seems to be encrypted'.
1913 1912
 						' and can not be decrypted properly. If you still wish to'.
1914 1913
 						' forward content of this encrypted message, you may try'.
1915
-						' to use forward as attachment instead.'),'error');
1914
+						' to use forward as attachment instead.'), 'error');
1916 1915
 			}
1917 1916
 		}
1918 1917
 		$mail_bo->closeConnection();
@@ -1933,7 +1932,7 @@  discard block
 block discarded – undo
1933 1932
 	 * @param array $_content the content passed to the function and to be modified
1934 1933
 	 * @return void
1935 1934
 	 */
1936
-	function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false)
1935
+	function addAttachment($_formData, &$_content, $eliminateDoubleAttachments = false)
1937 1936
 	{
1938 1937
 		//error_log(__METHOD__.__LINE__.' Formdata:'.array2string($_formData).' Content:'.array2string($_content));
1939 1938
 
@@ -1942,7 +1941,7 @@  discard block
 block discarded – undo
1942 1941
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
1943 1942
 		try
1944 1943
 		{
1945
-			$tmpFileName = Mail::checkFileBasics($_formData,$this->composeID,false);
1944
+			$tmpFileName = Mail::checkFileBasics($_formData, $this->composeID, false);
1946 1945
 		}
1947 1946
 		catch (Api\Exception\WrongUserinput $e)
1948 1947
 		{
@@ -1958,8 +1957,8 @@  discard block
 block discarded – undo
1958 1957
 			foreach ((array)$_content['attachments'] as $attach)
1959 1958
 			{
1960 1959
 				if ($attach['name'] && $attach['name'] == $_formData['name'] &&
1961
-					strtolower($_formData['type'])== strtolower($attach['type']) &&
1962
-					stripos($_formData['file'],'vfs://') !== false) return;
1960
+					strtolower($_formData['type']) == strtolower($attach['type']) &&
1961
+					stripos($_formData['file'], 'vfs://') !== false) return;
1963 1962
 			}
1964 1963
 		}
1965 1964
 		if ($attachfailed === false)
@@ -1971,7 +1970,7 @@  discard block
 block discarded – undo
1971 1970
 				'tmp_name'	=> $tmpFileName,
1972 1971
 				'size'	=> $_formData['size']
1973 1972
 			);
1974
-			if (!is_array($_content['attachments'])) $_content['attachments']=array();
1973
+			if (!is_array($_content['attachments'])) $_content['attachments'] = array();
1975 1974
 			$_content['attachments'][] = $buffer;
1976 1975
 			unset($buffer);
1977 1976
 		}
@@ -1981,9 +1980,9 @@  discard block
 block discarded – undo
1981 1980
 		}
1982 1981
 	}
1983 1982
 
1984
-	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail= null)
1983
+	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail = null)
1985 1984
 	{
1986
-		$this->sessionData['attachments'][]=array (
1985
+		$this->sessionData['attachments'][] = array(
1987 1986
 			'uid'		=> $_uid,
1988 1987
 			'partID'	=> $_partID,
1989 1988
 			'name'		=> $_name,
@@ -1991,7 +1990,7 @@  discard block
 block discarded – undo
1991 1990
 			'size'		=> $_size,
1992 1991
 			'folder'	=> $_folder,
1993 1992
 			'winmailFlag' => $_is_winmail,
1994
-			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID)?$_partID:count($this->sessionData['attachments'])+1),
1993
+			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID) ? $_partID : count($this->sessionData['attachments']) + 1),
1995 1994
 		);
1996 1995
 	}
1997 1996
 
@@ -2000,7 +1999,7 @@  discard block
 block discarded – undo
2000 1999
 		// read attachment data from etemplate request, use tmpname only to identify it
2001 2000
 		if (($request = Etemplate\Request::read($_GET['etemplate_exec_id'])))
2002 2001
 		{
2003
-			foreach($request->preserv['attachments'] as $attachment)
2002
+			foreach ($request->preserv['attachments'] as $attachment)
2004 2003
 			{
2005 2004
 				if ($_GET['tmpname'] === $attachment['tmp_name']) break;
2006 2005
 			}
@@ -2012,7 +2011,7 @@  discard block
 block discarded – undo
2012 2011
 		}
2013 2012
 
2014 2013
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
2015
-		if (parse_url($attachment['tmp_name'],PHP_URL_SCHEME) == 'vfs')
2014
+		if (parse_url($attachment['tmp_name'], PHP_URL_SCHEME) == 'vfs')
2016 2015
 		{
2017 2016
 			Vfs::load_wrapper('vfs');
2018 2017
 		}
@@ -2021,7 +2020,7 @@  discard block
 block discarded – undo
2021 2020
 		{
2022 2021
 			$attachment['tmp_name'] = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['tmp_name']);
2023 2022
 		}
2024
-		if(!file_exists($attachment['tmp_name']))
2023
+		if (!file_exists($attachment['tmp_name']))
2025 2024
 		{
2026 2025
 			header('HTTP/1.1 404 Not found');
2027 2026
 			die('Attachment '.htmlspecialchars($attachment['tmp_name']).' NOT found!');
@@ -2034,7 +2033,7 @@  discard block
 block discarded – undo
2034 2033
 			if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY')
2035 2034
 			{
2036 2035
 				$sfxMimeType = $attachment['type'];
2037
-				$buff = explode('.',$attachment['tmp_name']);
2036
+				$buff = explode('.', $attachment['tmp_name']);
2038 2037
 				$suffix = '';
2039 2038
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
2040 2039
 				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -2046,10 +2045,10 @@  discard block
 block discarded – undo
2046 2045
 			{
2047 2046
 				//error_log(__METHOD__."about to call calendar_ical");
2048 2047
 				$calendar_ical = new calendar_ical();
2049
-				$eventid = $calendar_ical->search($attachment['attachment'],-1);
2048
+				$eventid = $calendar_ical->search($attachment['attachment'], -1);
2050 2049
 				//error_log(__METHOD__.array2string($eventid));
2051 2050
 				if (!$eventid) $eventid = -1;
2052
-				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
2051
+				$event = $calendar_ical->importVCal($attachment['attachment'], (is_array($eventid) ? $eventid[0] : $eventid), null, true);
2053 2052
 				//error_log(__METHOD__.$event);
2054 2053
 				if ((int)$event > 0)
2055 2054
 				{
@@ -2057,7 +2056,7 @@  discard block
 block discarded – undo
2057 2056
 						'menuaction'      => 'calendar.calendar_uiforms.edit',
2058 2057
 						'cal_id'      => $event,
2059 2058
 					);
2060
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
2059
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
2061 2060
 				}
2062 2061
 				//Import failed, download content anyway
2063 2062
 			}
@@ -2072,13 +2071,13 @@  discard block
 block discarded – undo
2072 2071
 				{
2073 2072
 					$vcard['uid'] = trim($vcard['uid']);
2074 2073
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
2075
-					$contact = $addressbook_vcal->find_contact($vcard,false);
2074
+					$contact = $addressbook_vcal->find_contact($vcard, false);
2076 2075
 				}
2077 2076
 				if (!$contact) $contact = null;
2078 2077
 				// 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))
2079
-				if ($contact || count($vcard)>2)
2078
+				if ($contact || count($vcard) > 2)
2080 2079
 				{
2081
-					$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true);
2080
+					$contact = $addressbook_vcal->addVCard($attachment['attachment'], (is_array($contact) ?array_shift($contact) : $contact), true);
2082 2081
 				}
2083 2082
 				if ((int)$contact > 0)
2084 2083
 				{
@@ -2086,13 +2085,13 @@  discard block
 block discarded – undo
2086 2085
 						'menuaction'	=> 'addressbook.addressbook_ui.edit',
2087 2086
 						'contact_id'	=> $contact,
2088 2087
 					);
2089
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
2088
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
2090 2089
 				}
2091 2090
 				//Import failed, download content anyway
2092 2091
 			}
2093 2092
 		}
2094 2093
 		//error_log(__METHOD__.__LINE__.'->'.array2string($attachment));
2095
-		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size=0, true, $_GET['mode'] == "save");
2094
+		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size = 0, true, $_GET['mode'] == "save");
2096 2095
 		echo $attachment['attachment'];
2097 2096
 
2098 2097
 		exit();
@@ -2105,11 +2104,11 @@  discard block
 block discarded – undo
2105 2104
 	 * @param string haystack
2106 2105
 	 * @return boolean
2107 2106
 	 */
2108
-	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack) {
2107
+	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst, $haystack) {
2109 2108
 		foreach (array_keys($arrayToTestAgainst) as $k)
2110 2109
 		{
2111 2110
 			//error_log(__METHOD__.__LINE__.':'.$k.'<->'.$haystack);
2112
-			if (stripos($haystack,$k)!==false)
2111
+			if (stripos($haystack, $k) !== false)
2113 2112
 			{
2114 2113
 				//error_log(__METHOD__.__LINE__.':FOUND:'.$k.'<->'.$haystack.function_backtrace());
2115 2114
 				return true;
@@ -2132,10 +2131,10 @@  discard block
 block discarded – undo
2132 2131
 	 */
2133 2132
 	function getReplyData($_mode, $_icServer, $_folder, $_uid, $_partID)
2134 2133
 	{
2135
-		unset($_icServer);	// not used
2134
+		unset($_icServer); // not used
2136 2135
 		$foundAddresses = array();
2137 2136
 
2138
-		$mail_bo  = $this->mail_bo;
2137
+		$mail_bo = $this->mail_bo;
2139 2138
 		$mail_bo->openConnection();
2140 2139
 		$mail_bo->reopen($_folder);
2141 2140
 
@@ -2143,20 +2142,20 @@  discard block
 block discarded – undo
2143 2142
 
2144 2143
 		// get message headers for specified message
2145 2144
 		//print "AAAA: $_folder, $_uid, $_partID<br>";
2146
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder,$useHeaderInsteadOfEnvelope=true);
2145
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder, $useHeaderInsteadOfEnvelope = true);
2147 2146
 		//$headers	= $mail_bo->getMessageHeader($_uid, $_partID, true, true, $_folder);
2148 2147
 		$this->sessionData['uid'] = $_uid;
2149 2148
 		$this->sessionData['messageFolder'] = $_folder;
2150
-		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO']?$headers['IN-REPLY-TO']:$headers['MESSAGE_ID']);
2151
-		$this->sessionData['references'] = ($headers['REFERENCES']?$headers['REFERENCES']:$headers['MESSAGE_ID']);
2149
+		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO'] ? $headers['IN-REPLY-TO'] : $headers['MESSAGE_ID']);
2150
+		$this->sessionData['references'] = ($headers['REFERENCES'] ? $headers['REFERENCES'] : $headers['MESSAGE_ID']);
2152 2151
 
2153 2152
 		// break reference into multiple lines if they're greater than 998 chars
2154 2153
 		// and remove comma seperation. Fix error serer does not support binary
2155 2154
 		// data due to long references.
2156
-		if (strlen($this->sessionData['references'])> 998)
2155
+		if (strlen($this->sessionData['references']) > 998)
2157 2156
 		{
2158
-			$temp_refs = explode(',',$this->sessionData['references']);
2159
-			$this->sessionData['references'] = implode(" ",$temp_refs);
2157
+			$temp_refs = explode(',', $this->sessionData['references']);
2158
+			$this->sessionData['references'] = implode(" ", $temp_refs);
2160 2159
 		}
2161 2160
 
2162 2161
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
@@ -2166,36 +2165,36 @@  discard block
 block discarded – undo
2166 2165
 		if ($headers['LIST-ID']) $this->sessionData['list-id'] = $headers['LIST-ID'];
2167 2166
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_mode.':'.array2string($headers));
2168 2167
 		// check for Reply-To: header and use if available
2169
-		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2170
-			foreach($headers['REPLY-TO'] as $val) {
2171
-				if(!$foundAddresses[$val]) {
2168
+		if (!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2169
+			foreach ($headers['REPLY-TO'] as $val) {
2170
+				if (!$foundAddresses[$val]) {
2172 2171
 					$oldTo[] = $val;
2173 2172
 					$foundAddresses[$val] = true;
2174 2173
 				}
2175 2174
 			}
2176
-			$oldToAddress	= (is_array($headers['REPLY-TO'])?$headers['REPLY-TO'][0]:$headers['REPLY-TO']);
2175
+			$oldToAddress = (is_array($headers['REPLY-TO']) ? $headers['REPLY-TO'][0] : $headers['REPLY-TO']);
2177 2176
 		} else {
2178
-			foreach($headers['FROM'] as $val) {
2179
-				if(!$foundAddresses[$val]) {
2177
+			foreach ($headers['FROM'] as $val) {
2178
+				if (!$foundAddresses[$val]) {
2180 2179
 					$oldTo[] = $val;
2181 2180
 					$foundAddresses[$val] = true;
2182 2181
 				}
2183 2182
 			}
2184
-			$oldToAddress	= (is_array($headers['FROM'])?$headers['FROM'][0]:$headers['FROM']);
2183
+			$oldToAddress = (is_array($headers['FROM']) ? $headers['FROM'][0] : $headers['FROM']);
2185 2184
 		}
2186 2185
 		//error_log(__METHOD__.__LINE__.' OldToAddress:'.$oldToAddress.'#');
2187
-		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) ) {
2186
+		if ($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $oldToAddress))) {
2188 2187
 			$this->sessionData['to'] = $oldTo;
2189 2188
 		}
2190 2189
 
2191
-		if($_mode == 'all') {
2190
+		if ($_mode == 'all') {
2192 2191
 			// reply to any address which is cc, but not to my self
2193 2192
 			#if($headers->cc) {
2194
-				foreach($headers['CC'] as $val) {
2195
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2193
+				foreach ($headers['CC'] as $val) {
2194
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2196 2195
 						continue;
2197 2196
 					}
2198
-					if(!$foundAddresses[$val]) {
2197
+					if (!$foundAddresses[$val]) {
2199 2198
 						$this->sessionData['cc'][] = $val;
2200 2199
 						$foundAddresses[$val] = true;
2201 2200
 					}
@@ -2204,11 +2203,11 @@  discard block
 block discarded – undo
2204 2203
 
2205 2204
 			// reply to any address which is to, but not to my self
2206 2205
 			#if($headers->to) {
2207
-				foreach($headers['TO'] as $val) {
2208
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2206
+				foreach ($headers['TO'] as $val) {
2207
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2209 2208
 						continue;
2210 2209
 					}
2211
-					if(!$foundAddresses[$val]) {
2210
+					if (!$foundAddresses[$val]) {
2212 2211
 						$this->sessionData['to'][] = $val;
2213 2212
 						$foundAddresses[$val] = true;
2214 2213
 					}
@@ -2216,12 +2215,12 @@  discard block
 block discarded – undo
2216 2215
 			#}
2217 2216
 
2218 2217
 			#if($headers->from) {
2219
-				foreach($headers['FROM'] as $val) {
2220
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2218
+				foreach ($headers['FROM'] as $val) {
2219
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2221 2220
 						continue;
2222 2221
 					}
2223 2222
 					//error_log(__METHOD__.__LINE__.' '.$val);
2224
-					if(!$foundAddresses[$val]) {
2223
+					if (!$foundAddresses[$val]) {
2225 2224
 						$this->sessionData['to'][] = $val;
2226 2225
 						$foundAddresses[$val] = true;
2227 2226
 					}
@@ -2230,16 +2229,16 @@  discard block
 block discarded – undo
2230 2229
 		}
2231 2230
 
2232 2231
 		// check for Re: in subject header
2233
-		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2232
+		if (strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2234 2233
 			$this->sessionData['subject'] = $mail_bo->decode_header($headers['SUBJECT']);
2235 2234
 		} else {
2236
-			$this->sessionData['subject'] = "Re: " . $mail_bo->decode_header($headers['SUBJECT']);
2235
+			$this->sessionData['subject'] = "Re: ".$mail_bo->decode_header($headers['SUBJECT']);
2237 2236
 		}
2238 2237
 
2239 2238
 		//_debug_array($headers);
2240 2239
 		//error_log(__METHOD__.__LINE__.'->'.array2string($this->mailPreferences['htmlOptions']));
2241 2240
 		try {
2242
-			$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions']?$this->mailPreferences['htmlOptions']:''), $_partID);
2241
+			$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions'] ? $this->mailPreferences['htmlOptions'] : ''), $_partID);
2243 2242
 		}
2244 2243
 		catch (Mail\Smime\PassphraseMissing $e)
2245 2244
 		{
@@ -2249,52 +2248,52 @@  discard block
 block discarded – undo
2249 2248
 				' because the content of this message seems to be encrypted'.
2250 2249
 				' and can not be decrypted properly. If you still wish to include'.
2251 2250
 				' content of this encrypted message, you may try to use forward as'.
2252
-				' attachment instead.'),'error');
2251
+				' attachment instead.'), 'error');
2253 2252
 		}
2254 2253
 		//_debug_array($bodyParts);
2255 2254
 		$styles = Mail::getStyles($bodyParts);
2256 2255
 
2257
-		$fromAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$headers['FROM']));
2256
+		$fromAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $headers['FROM']));
2258 2257
 
2259 2258
 		$toAddressA = array();
2260 2259
 		$toAddress = '';
2261 2260
 		foreach ($headers['TO'] as $mailheader) {
2262
-			$toAddressA[] =  $mailheader;
2261
+			$toAddressA[] = $mailheader;
2263 2262
 		}
2264
-		if (count($toAddressA)>0)
2263
+		if (count($toAddressA) > 0)
2265 2264
 		{
2266
-			$toAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$toAddressA));
2267
-			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2265
+			$toAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $toAddressA));
2266
+			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2268 2267
 		}
2269 2268
 		$ccAddressA = array();
2270 2269
 		$ccAddress = '';
2271 2270
 		foreach ($headers['CC'] as $mailheader) {
2272
-			$ccAddressA[] =  $mailheader;
2271
+			$ccAddressA[] = $mailheader;
2273 2272
 		}
2274
-		if (count($ccAddressA)>0)
2273
+		if (count($ccAddressA) > 0)
2275 2274
 		{
2276
-			$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA));
2277
-			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2275
+			$ccAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $ccAddressA));
2276
+			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2278 2277
 		}
2279
-		if($bodyParts['0']['mimeType'] == 'text/html') {
2280
-			$this->sessionData['body']	= /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2278
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
2279
+			$this->sessionData['body'] = /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2281 2280
 				@htmlspecialchars(lang("from")).": ".$fromAddress."<br>".
2282 2281
 				$toAddress.$ccAddress.
2283
-				@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>".
2282
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."<br>".
2284 2283
 				'----------------------------------------------------------'."</div>";
2285
-			$this->sessionData['mimeType'] 	= 'html';
2284
+			$this->sessionData['mimeType'] = 'html';
2286 2285
 			if (!empty($styles)) $this->sessionData['body'] .= $styles;
2287
-			$this->sessionData['body']	.= '<blockquote type="cite">';
2286
+			$this->sessionData['body'] .= '<blockquote type="cite">';
2288 2287
 
2289
-			for($i=0; $i<count($bodyParts); $i++) {
2290
-				if($i>0) {
2288
+			for ($i = 0; $i < count($bodyParts); $i++) {
2289
+				if ($i > 0) {
2291 2290
 					$this->sessionData['body'] .= '<hr>';
2292 2291
 				}
2293
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
2292
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
2294 2293
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>";
2295 2294
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
2296 2295
 				}
2297
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2296
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2298 2297
 
2299 2298
 				$_htmlConfig = Mail::$htmLawed_config;
2300 2299
 				Mail::$htmLawed_config['comment'] = 2;
@@ -2304,37 +2303,37 @@  discard block
 block discarded – undo
2304 2303
 				#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2305 2304
 			}
2306 2305
 
2307
-			$this->sessionData['body']	.= '</blockquote><br>';
2308
-			$this->sessionData['body'] =  mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2306
+			$this->sessionData['body'] .= '</blockquote><br>';
2307
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2309 2308
 		} else {
2310 2309
 			//$this->sessionData['body']	= @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n";
2311 2310
 			// 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)
2312
-            $this->sessionData['body']  = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2311
+            $this->sessionData['body'] = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2313 2312
                 @htmlspecialchars(lang("from")).": ".$fromAddress."\r\n".
2314 2313
 				$toAddress.$ccAddress.
2315
-				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
2314
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."\r\n".
2316 2315
                 '-------------------------------------------------'."\r\n \r\n ";
2317
-			$this->sessionData['mimeType']	= 'plain';
2316
+			$this->sessionData['mimeType'] = 'plain';
2318 2317
 
2319
-			for($i=0; $i<count($bodyParts); $i++) {
2320
-				if($i>0) {
2318
+			for ($i = 0; $i < count($bodyParts); $i++) {
2319
+				if ($i > 0) {
2321 2320
 					$this->sessionData['body'] .= "<hr>";
2322 2321
 				}
2323 2322
 
2324 2323
 				// add line breaks to $bodyParts
2325
-				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']);
2324
+				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
2326 2325
 				#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2327 2326
 				$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
2328 2327
 				$this->sessionData['body'] .= "\r\n";
2329 2328
 				$hasSignature = false;
2330 2329
 				// create body new, with good line breaks and indention
2331
-				foreach(explode("\n",$newBody) as $value) {
2330
+				foreach (explode("\n", $newBody) as $value) {
2332 2331
 					// the explode is removing the character
2333 2332
 					//$value .= 'ee';
2334 2333
 
2335 2334
 					// Try to remove signatures from qouted parts to avoid multiple
2336 2335
 					// signatures problem in reply (rfc3676#section-4.3).
2337
-					if ($_mode != 'forward' && ($hasSignature || ($hasSignature = preg_match("/^--\s[\r\n]$/",$value))))
2336
+					if ($_mode != 'forward' && ($hasSignature || ($hasSignature = preg_match("/^--\s[\r\n]$/", $value))))
2338 2337
 					{
2339 2338
 						continue;
2340 2339
 					}
@@ -2342,12 +2341,12 @@  discard block
 block discarded – undo
2342 2341
 					$numberOfChars = strspn(trim($value), ">");
2343 2342
 					$appendString = str_repeat('>', $numberOfChars + 1);
2344 2343
 
2345
-					$bodyAppend = $this->mail_bo->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
2344
+					$bodyAppend = $this->mail_bo->wordwrap($value, 76 - strlen("\r\n$appendString "), "\r\n$appendString ", '>');
2346 2345
 
2347
-					if($bodyAppend[0] == '>') {
2348
-						$bodyAppend = '>'. $bodyAppend;
2346
+					if ($bodyAppend[0] == '>') {
2347
+						$bodyAppend = '>'.$bodyAppend;
2349 2348
 					} else {
2350
-						$bodyAppend = '> '. $bodyAppend;
2349
+						$bodyAppend = '> '.$bodyAppend;
2351 2350
 					}
2352 2351
 
2353 2352
 					$this->sessionData['body'] .= $bodyAppend;
@@ -2370,16 +2369,16 @@  discard block
 block discarded – undo
2370 2369
 	 */
2371 2370
 	static function _getCleanHTML($_body, $_useTidy = false)
2372 2371
 	{
2373
-		static $nonDisplayAbleCharacters = array('[\016]','[\017]',
2374
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2375
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
2372
+		static $nonDisplayAbleCharacters = array('[\016]', '[\017]',
2373
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
2374
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2376 2375
 
2377
-		if ($_useTidy && extension_loaded('tidy') )
2376
+		if ($_useTidy && extension_loaded('tidy'))
2378 2377
 		{
2379 2378
 			$tidy = new tidy();
2380
-			$cleaned = $tidy->repairString($_body, Mail::$tidy_config,'utf8');
2379
+			$cleaned = $tidy->repairString($_body, Mail::$tidy_config, 'utf8');
2381 2380
 			// Found errors. Strip it all so there's some output
2382
-			if($tidy->getStatus() == 2)
2381
+			if ($tidy->getStatus() == 2)
2383 2382
 			{
2384 2383
 				error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
2385 2384
 			}
@@ -2413,13 +2412,13 @@  discard block
 block discarded – undo
2413 2412
 	 *
2414 2413
 	 * @return array returns found inline images as attachment structure
2415 2414
 	 */
2416
-	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving=false)
2415
+	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving = false)
2417 2416
 	{
2418 2417
 		if (substr($_formData['body'], 0, 27) == '-----BEGIN PGP MESSAGE-----')
2419 2418
 		{
2420 2419
 			$_formData['mimeType'] = 'openpgp';
2421 2420
 		}
2422
-		$mail_bo	= $this->mail_bo;
2421
+		$mail_bo = $this->mail_bo;
2423 2422
 		$activeMailProfile = Mail\Account::read($this->mail_bo->profileID);
2424 2423
 
2425 2424
 		// you need to set the sender, if you work with different identities, since most smtp servers, dont allow
@@ -2428,37 +2427,37 @@  discard block
 block discarded – undo
2428 2427
 		{
2429 2428
 			error_log(__METHOD__.__LINE__.' Faking From/SenderInfo for '.$activeMailProfile['ident_email'].' with ID:'.$activeMailProfile['ident_id'].'. Identitiy to use for sending:'.array2string($_identity));
2430 2429
 		}
2431
-		$email_From =  $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2430
+		$email_From = $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2432 2431
 		// Try to fix identity email with no domain part set
2433 2432
 		$_mailObject->setFrom(Mail::fixInvalidAliasAddress(Api\Accounts::id2name($_identity['account_id'], 'account_email'), $email_From),
2434
-			Mail::generateIdentityString($_identity,false));
2433
+			Mail::generateIdentityString($_identity, false));
2435 2434
 
2436 2435
 		$_mailObject->addHeader('X-Priority', $_formData['priority']);
2437 2436
 		$_mailObject->addHeader('X-Mailer', 'EGroupware-Mail');
2438
-		if(!empty($_formData['in-reply-to'])) {
2439
-			if (stripos($_formData['in-reply-to'],'<')===false) $_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2437
+		if (!empty($_formData['in-reply-to'])) {
2438
+			if (stripos($_formData['in-reply-to'], '<') === false) $_formData['in-reply-to'] = '<'.trim($_formData['in-reply-to']).'>';
2440 2439
 			$_mailObject->addHeader('In-Reply-To', $_formData['in-reply-to']);
2441 2440
 		}
2442
-		if(!empty($_formData['references'])) {
2443
-			if (stripos($_formData['references'],'<')===false)
2441
+		if (!empty($_formData['references'])) {
2442
+			if (stripos($_formData['references'], '<') === false)
2444 2443
 			{
2445
-				$_formData['references']='<'.trim($_formData['references']).'>';
2444
+				$_formData['references'] = '<'.trim($_formData['references']).'>';
2446 2445
 			}
2447 2446
 			$_mailObject->addHeader('References', $_formData['references']);
2448 2447
 		}
2449 2448
 
2450
-		if(!empty($_formData['thread-index'])) {
2449
+		if (!empty($_formData['thread-index'])) {
2451 2450
 			$_mailObject->addHeader('Thread-Index', $_formData['thread-index']);
2452 2451
 		}
2453
-		if(!empty($_formData['list-id'])) {
2452
+		if (!empty($_formData['list-id'])) {
2454 2453
 			$_mailObject->addHeader('List-Id', $_formData['list-id']);
2455 2454
 		}
2456
-		if($_formData['disposition']=='on') {
2455
+		if ($_formData['disposition'] == 'on') {
2457 2456
 			$_mailObject->addHeader('Disposition-Notification-To', $_identity['ident_email']);
2458 2457
 		}
2459 2458
 
2460 2459
 		// Expand any mailing lists
2461
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $field)
2460
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $field)
2462 2461
 		{
2463 2462
 			if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2464 2463
 
@@ -2474,7 +2473,7 @@  discard block
 block discarded – undo
2474 2473
 		}
2475 2474
 		$disableRuler = false;
2476 2475
 		$signature = $_identity['ident_signature'];
2477
-		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend'?1:0;
2476
+		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' ? 1 : 0;
2478 2477
 		if ($sigAlreadyThere)
2479 2478
 		{
2480 2479
 			// note: if you use stationery ' s the insert signatures at the top does not apply here anymore, as the signature
@@ -2483,7 +2482,7 @@  discard block
 block discarded – undo
2483 2482
 		}
2484 2483
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
2485 2484
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
2486
-			empty($signature) || trim($this->convertHTMLToText($signature)) =='')
2485
+			empty($signature) || trim($this->convertHTMLToText($signature)) == '')
2487 2486
 		{
2488 2487
 			$disableRuler = true;
2489 2488
 		}
@@ -2509,13 +2508,13 @@  discard block
 block discarded – undo
2509 2508
 						$body .= $attachment_links;
2510 2509
 					}
2511 2510
 				}
2512
-				if(!empty($signature))
2511
+				if (!empty($signature))
2513 2512
 				{
2514 2513
 					$_mailObject->setBody($this->convertHTMLToText($body, true, true).
2515 2514
 						($disableRuler ? "\r\n" : "\r\n-- \r\n").
2516 2515
 						$this->convertHTMLToText($signature, true, true));
2517 2516
 
2518
-					$body .= ($disableRuler ?'<br>':'<hr style="border:1px dotted silver; width:90%;">').$signature;
2517
+					$body .= ($disableRuler ? '<br>' : '<hr style="border:1px dotted silver; width:90%;">').$signature;
2519 2518
 				}
2520 2519
 				else
2521 2520
 				{
@@ -2523,24 +2522,24 @@  discard block
 block discarded – undo
2523 2522
 				}
2524 2523
 				// convert URL Images to inline images - if possible
2525 2524
 				if (!$_autosaving) $inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2526
-				if (strpos($body,"<!-- HTMLSIGBEGIN -->")!==false)
2525
+				if (strpos($body, "<!-- HTMLSIGBEGIN -->") !== false)
2527 2526
 				{
2528
-					$body = str_replace(array('<!-- HTMLSIGBEGIN -->','<!-- HTMLSIGEND -->'),'',$body);
2527
+					$body = str_replace(array('<!-- HTMLSIGBEGIN -->', '<!-- HTMLSIGEND -->'), '', $body);
2529 2528
 				}
2530
-				$_mailObject->setHtmlBody($body, null, false);	// false = no automatic alternative, we called setBody()
2529
+				$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
2531 2530
 				break;
2532 2531
 			case 'openpgp':
2533 2532
 				$_mailObject->setOpenPgpBody($_formData['body']);
2534 2533
 				break;
2535 2534
 			default:
2536
-				$body = $this->convertHTMLToText($_formData['body'],false, false, true, true);
2535
+				$body = $this->convertHTMLToText($_formData['body'], false, false, true, true);
2537 2536
 
2538 2537
 				if ($attachment_links) $body .= $attachment_links;
2539 2538
 
2540 2539
 				#$_mailObject->Body = $_formData['body'];
2541
-				if(!empty($signature)) {
2542
-					$body .= ($disableRuler ?"\r\n":"\r\n-- \r\n").
2543
-						$this->convertHTMLToText($signature,true,true);
2540
+				if (!empty($signature)) {
2541
+					$body .= ($disableRuler ? "\r\n" : "\r\n-- \r\n").
2542
+						$this->convertHTMLToText($signature, true, true);
2544 2543
 				}
2545 2544
 				$_mailObject->setBody($body);
2546 2545
 		}
@@ -2549,8 +2548,8 @@  discard block
 block discarded – undo
2549 2548
 		{
2550 2549
 			$connection_opened = false;
2551 2550
 			$tnfattachments = null;
2552
-			foreach((array)$_formData['attachments'] as $attachment) {
2553
-				if(is_array($attachment))
2551
+			foreach ((array)$_formData['attachments'] as $attachment) {
2552
+				if (is_array($attachment))
2554 2553
 				{
2555 2554
 					if (!empty($attachment['uid']) && !empty($attachment['folder'])) {
2556 2555
 						/* Example:
@@ -2568,20 +2567,20 @@  discard block
 block discarded – undo
2568 2567
 							$connection_opened = true;
2569 2568
 						}
2570 2569
 						$mail_bo->reopen($attachment['folder']);
2571
-						switch(strtoupper($attachment['type'])) {
2570
+						switch (strtoupper($attachment['type'])) {
2572 2571
 							case 'MESSAGE/RFC':
2573 2572
 							case 'MESSAGE/RFC822':
2574
-								$rawBody='';
2573
+								$rawBody = '';
2575 2574
 								if (isset($attachment['partID'])) {
2576
-									$eml = $mail_bo->getAttachment($attachment['uid'],$attachment['partID'],0,false,true,$attachment['folder']);
2577
-									$rawBody=$eml['attachment'];
2575
+									$eml = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false, true, $attachment['folder']);
2576
+									$rawBody = $eml['attachment'];
2578 2577
 								} else {
2579
-									$rawBody        = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'],$attachment['folder']);
2578
+									$rawBody = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'], $attachment['folder']);
2580 2579
 								}
2581 2580
 								$_mailObject->addStringAttachment($rawBody, $attachment['name'], 'message/rfc822');
2582 2581
 								break;
2583 2582
 							default:
2584
-								$attachmentData	= $mail_bo->getAttachment($attachment['uid'], $attachment['partID'],0,false);
2583
+								$attachmentData = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false);
2585 2584
 								if ($attachmentData['type'] == 'APPLICATION/MS-TNEF')
2586 2585
 								{
2587 2586
 									if (!is_array($tnfattachments)) $tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
@@ -2589,7 +2588,7 @@  discard block
 block discarded – undo
2589 2588
 									{
2590 2589
 										if ($k['name'] == $attachment['name'])
2591 2590
 										{
2592
-											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'],$k['is_winmail']);
2591
+											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'], $k['is_winmail']);
2593 2592
 											$attachmentData['attachment'] = $tnfpart['attachment'];
2594 2593
 											break;
2595 2594
 										}
@@ -2602,7 +2601,7 @@  discard block
 block discarded – undo
2602 2601
 					// attach files not for autosaving
2603 2602
 					elseif ($_formData['filemode'] == Vfs\Sharing::ATTACH && !$_autosaving)
2604 2603
 					{
2605
-						if (isset($attachment['file']) && parse_url($attachment['file'],PHP_URL_SCHEME) == 'vfs')
2604
+						if (isset($attachment['file']) && parse_url($attachment['file'], PHP_URL_SCHEME) == 'vfs')
2606 2605
 						{
2607 2606
 							Vfs::load_wrapper('vfs');
2608 2607
 							$tmp_path = $attachment['file'];
@@ -2611,7 +2610,7 @@  discard block
 block discarded – undo
2611 2610
 						{
2612 2611
 							$tmp_path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['file']);
2613 2612
 						}
2614
-						$_mailObject->addAttachment (
2613
+						$_mailObject->addAttachment(
2615 2614
 							$tmp_path,
2616 2615
 							$attachment['name'],
2617 2616
 							$attachment['type']
@@ -2621,7 +2620,7 @@  discard block
 block discarded – undo
2621 2620
 			}
2622 2621
 			if ($connection_opened) $mail_bo->closeConnection();
2623 2622
 		}
2624
-		return is_array($inline_images)?$inline_images:array();
2623
+		return is_array($inline_images) ? $inline_images : array();
2625 2624
 	}
2626 2625
 
2627 2626
 	/**
@@ -2637,16 +2636,16 @@  discard block
 block discarded – undo
2637 2636
 	 * @param string $password =null
2638 2637
 	 * @return string might be empty if no file attachments found
2639 2638
 	 */
2640
-	protected function _getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
2639
+	protected function _getAttachmentLinks(array $attachments, $filemode, $html, $recipients = array(), $expiration = null, $password = null)
2641 2640
 	{
2642 2641
 		if ($filemode == Vfs\Sharing::ATTACH) return '';
2643 2642
 
2644 2643
 		$links = array();
2645
-		foreach($attachments as $attachment)
2644
+		foreach ($attachments as $attachment)
2646 2645
 		{
2647 2646
 			$path = $attachment['file'];
2648
-			if (empty($path)) continue;	// we only care about file attachments, not forwarded messages or parts
2649
-			if (parse_url($attachment['file'],PHP_URL_SCHEME) != 'vfs')
2647
+			if (empty($path)) continue; // we only care about file attachments, not forwarded messages or parts
2648
+			if (parse_url($attachment['file'], PHP_URL_SCHEME) != 'vfs')
2650 2649
 			{
2651 2650
 				$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($path);
2652 2651
 			}
@@ -2676,7 +2675,7 @@  discard block
 block discarded – undo
2676 2675
 		}
2677 2676
 		if (!$links)
2678 2677
 		{
2679
-			return null;	// no file attachments found
2678
+			return null; // no file attachments found
2680 2679
 		}
2681 2680
 		elseif ($html)
2682 2681
 		{
@@ -2691,7 +2690,7 @@  discard block
 block discarded – undo
2691 2690
 	 * @param array $content content sent from client-side
2692 2691
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2693 2692
 	 */
2694
-	public function ajax_saveAsDraft ($content, $action='button[saveAsDraft]')
2693
+	public function ajax_saveAsDraft($content, $action = 'button[saveAsDraft]')
2695 2694
 	{
2696 2695
 		//error_log(__METHOD__.__LINE__.array2string($content)."(, action=$action)");
2697 2696
 		$response = Api\Json\Response::get();
@@ -2705,8 +2704,8 @@  discard block
 block discarded – undo
2705 2704
 
2706 2705
 		$formData = array_merge($content, array(
2707 2706
 			'isDrafted' => 1,
2708
-			'body' => $content['mail_'.($content['mimeType']?'htmltext':'plaintext')],
2709
-			'mimeType' => $content['mimeType']?'html':'plain' // checkbox has only true|false value
2707
+			'body' => $content['mail_'.($content['mimeType'] ? 'htmltext' : 'plaintext')],
2708
+			'mimeType' => $content['mimeType'] ? 'html' : 'plain' // checkbox has only true|false value
2710 2709
 		));
2711 2710
 
2712 2711
 		//Saving draft procedure
@@ -2718,8 +2717,8 @@  discard block
 block discarded – undo
2718 2717
 			if (($messageUid = $this->saveAsDraft($formData, $folder, $action)))
2719 2718
 			{
2720 2719
 				// saving as draft, does not mean closing the message
2721
-				$messageUid = ($messageUid===true ? $status['uidnext'] : $messageUid);
2722
-				if (is_array($this->mail_bo->getMessageHeader($messageUid, '',false, false, $folder)))
2720
+				$messageUid = ($messageUid === true ? $status['uidnext'] : $messageUid);
2721
+				if (is_array($this->mail_bo->getMessageHeader($messageUid, '', false, false, $folder)))
2723 2722
 				{
2724 2723
 					$draft_id = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $messageUid);
2725 2724
 					if ($content['lastDrafted'] != $draft_id && isset($content['lastDrafted']))
@@ -2728,7 +2727,7 @@  discard block
 block discarded – undo
2728 2727
 						$duid = $dhA['msgUID'];
2729 2728
 						$dmailbox = $dhA['folder'];
2730 2729
 						// beware: do not delete the original mail as found in processedmail_id
2731
-						$pMuid='';
2730
+						$pMuid = '';
2732 2731
 						if ($content['processedmail_id'])
2733 2732
 						{
2734 2733
 							$pMhA = mail_ui::splitRowID($content['processedmail_id']);
@@ -2736,15 +2735,15 @@  discard block
 block discarded – undo
2736 2735
 						}
2737 2736
 						//error_log(__METHOD__.__LINE__."#$pMuid#$pMuid!=$duid#".array2string($content['attachments']));
2738 2737
 						// do not delete the original message if attachments are present
2739
-						if (empty($pMuid) || $pMuid!=$duid || empty($content['attachments']))
2738
+						if (empty($pMuid) || $pMuid != $duid || empty($content['attachments']))
2740 2739
 						{
2741 2740
 							try
2742 2741
 							{
2743
-								$this->mail_bo->deleteMessages($duid,$dmailbox,'remove_immediately');
2742
+								$this->mail_bo->deleteMessages($duid, $dmailbox, 'remove_immediately');
2744 2743
 							}
2745 2744
 							catch (Api\Exception $e)
2746 2745
 							{
2747
-								$msg = str_replace('"',"'",$e->getMessage());
2746
+								$msg = str_replace('"', "'", $e->getMessage());
2748 2747
 								$success = false;
2749 2748
 								error_log(__METHOD__.__LINE__.$msg);
2750 2749
 							}
@@ -2765,7 +2764,7 @@  discard block
 block discarded – undo
2765 2764
 		}
2766 2765
 		catch (Api\Exception\WrongUserinput $e)
2767 2766
 		{
2768
-			$msg = str_replace('"',"'",$e->getMessage());
2767
+			$msg = str_replace('"', "'", $e->getMessage());
2769 2768
 			error_log(__METHOD__.__LINE__.$msg);
2770 2769
 			$success = false;
2771 2770
 		}
@@ -2789,17 +2788,17 @@  discard block
 block discarded – undo
2789 2788
 	static function resolveEmailAddressList($_emailAddressList)
2790 2789
 	{
2791 2790
 		$contacts_obs = null;
2792
-		$addrFromList=array();
2793
-		foreach((array)$_emailAddressList as $ak => $address)
2791
+		$addrFromList = array();
2792
+		foreach ((array)$_emailAddressList as $ak => $address)
2794 2793
 		{
2795
-			if(is_int($address))
2794
+			if (is_int($address))
2796 2795
 			{
2797 2796
 				if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts();
2798 2797
 				// List was selected, expand to addresses
2799 2798
 				unset($_emailAddressList[$ak]);
2800
-				$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));
2799
+				$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));
2801 2800
 				// Just add email addresses, they'll be checked below
2802
-				foreach($list as $email)
2801
+				foreach ($list as $email)
2803 2802
 				{
2804 2803
 					$addrFromList[] = $email['email'] ? $email['email'] : $email['email_home'];
2805 2804
 				}
@@ -2809,7 +2808,7 @@  discard block
 block discarded – undo
2809 2808
 		{
2810 2809
 			foreach ($addrFromList as $addr)
2811 2810
 			{
2812
-				if (!empty($addr)) $_emailAddressList[]=$addr;
2811
+				if (!empty($addr)) $_emailAddressList[] = $addr;
2813 2812
 			}
2814 2813
 		}
2815 2814
 		return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList;
@@ -2823,15 +2822,15 @@  discard block
 block discarded – undo
2823 2822
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2824 2823
 	 * @return boolean return messageUID| false due to an error
2825 2824
 	 */
2826
-	function saveAsDraft($_formData, &$savingDestination='', $action='button[saveAsDraft]')
2825
+	function saveAsDraft($_formData, &$savingDestination = '', $action = 'button[saveAsDraft]')
2827 2826
 	{
2828 2827
 		//error_log(__METHOD__."(..., $savingDestination, action=$action)");
2829
-		$mail_bo	= $this->mail_bo;
2830
-		$mail		= new Api\Mailer($this->mail_bo->profileID);
2828
+		$mail_bo = $this->mail_bo;
2829
+		$mail = new Api\Mailer($this->mail_bo->profileID);
2831 2830
 
2832 2831
 		// preserve the bcc and if possible the save to folder information
2833
-		$this->sessionData['folder']    = $_formData['folder'];
2834
-		$this->sessionData['bcc']   = $_formData['bcc'];
2832
+		$this->sessionData['folder'] = $_formData['folder'];
2833
+		$this->sessionData['bcc'] = $_formData['bcc'];
2835 2834
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2836 2835
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2837 2836
 		$this->sessionData['mailaccount']  = $_formData['mailaccount'];
@@ -2840,11 +2839,11 @@  discard block
 block discarded – undo
2840 2839
 		{
2841 2840
 			$acc = Mail\Account::read($this->sessionData['mailaccount']);
2842 2841
 			//error_log(__METHOD__.__LINE__.array2string($acc));
2843
-			$identity = Mail\Account::read_identity($acc['ident_id'],true);
2842
+			$identity = Mail\Account::read_identity($acc['ident_id'], true);
2844 2843
 		}
2845 2844
 		catch (Exception $e)
2846 2845
 		{
2847
-			$identity=array();
2846
+			$identity = array();
2848 2847
 		}
2849 2848
 
2850 2849
 		$flags = '\\Seen \\Draft';
@@ -2854,7 +2853,7 @@  discard block
 block discarded – undo
2854 2853
 		// folder list as Customheader
2855 2854
 		if (!empty($this->sessionData['folder']))
2856 2855
 		{
2857
-			$folders = implode('|',array_unique($this->sessionData['folder']));
2856
+			$folders = implode('|', array_unique($this->sessionData['folder']));
2858 2857
 			$mail->addHeader('X-Mailfolder', $folders);
2859 2858
 		}
2860 2859
 		$mail->addHeader('X-Mailidentity', $this->sessionData['mailidentity']);
@@ -2874,25 +2873,25 @@  discard block
 block discarded – undo
2874 2873
 			$savingDestination = $this->sessionData['messageFolder'];
2875 2874
 			//error_log(__METHOD__.__LINE__.' SavingDestination:'.$savingDestination);
2876 2875
 		}
2877
-		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 ) $savingDestination = $mail_bo->getDraftFolder();
2876
+		if (!empty($_formData['printit']) && $_formData['printit'] == 0) $savingDestination = $mail_bo->getDraftFolder();
2878 2877
 
2879 2878
 		// normaly Bcc is only added to recipients, but not as header visible to all recipients
2880 2879
 		$mail->forceBccHeader();
2881 2880
 
2882 2881
 		$mail_bo->openConnection();
2883
-		if ($mail_bo->folderExists($savingDestination,true)) {
2882
+		if ($mail_bo->folderExists($savingDestination, true)) {
2884 2883
 			try
2885 2884
 			{
2886 2885
 				$messageUid = $mail_bo->appendMessage($savingDestination, $mail->getRaw(), null, $flags);
2887 2886
 			}
2888 2887
 			catch (Api\Exception\WrongUserinput $e)
2889 2888
 			{
2890
-				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",__METHOD__,$savingDestination,$e->getMessage()));
2889
+				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", __METHOD__, $savingDestination, $e->getMessage()));
2891 2890
 				return false;
2892 2891
 			}
2893 2892
 
2894 2893
 		} else {
2895
-			error_log(__METHOD__.__LINE__."->".lang("folder")." ". $savingDestination." ".lang("does not exist on IMAP Server."));
2894
+			error_log(__METHOD__.__LINE__."->".lang("folder")." ".$savingDestination." ".lang("does not exist on IMAP Server."));
2896 2895
 			return false;
2897 2896
 		}
2898 2897
 		$mail_bo->closeConnection();
@@ -2901,28 +2900,28 @@  discard block
 block discarded – undo
2901 2900
 
2902 2901
 	function send($_formData)
2903 2902
 	{
2904
-		$mail_bo	= $this->mail_bo;
2905
-		$mail 		= new Api\Mailer($mail_bo->profileID);
2906
-		$messageIsDraft	=  false;
2903
+		$mail_bo = $this->mail_bo;
2904
+		$mail = new Api\Mailer($mail_bo->profileID);
2905
+		$messageIsDraft = false;
2907 2906
 
2908
-		$this->sessionData['mailaccount']	= $_formData['mailaccount'];
2907
+		$this->sessionData['mailaccount'] = $_formData['mailaccount'];
2909 2908
 		$this->sessionData['to']	= self::resolveEmailAddressList($_formData['to']);
2910 2909
 		$this->sessionData['cc']	= self::resolveEmailAddressList($_formData['cc']);
2911
-		$this->sessionData['bcc']	= self::resolveEmailAddressList($_formData['bcc']);
2912
-		$this->sessionData['folder']	= $_formData['folder'];
2910
+		$this->sessionData['bcc'] = self::resolveEmailAddressList($_formData['bcc']);
2911
+		$this->sessionData['folder'] = $_formData['folder'];
2913 2912
 		$this->sessionData['replyto']	= $_formData['replyto'];
2914 2913
 		$this->sessionData['subject']	= trim($_formData['subject']);
2915
-		$this->sessionData['body']	= $_formData['body'];
2916
-		$this->sessionData['priority']	= $_formData['priority'];
2914
+		$this->sessionData['body'] = $_formData['body'];
2915
+		$this->sessionData['priority'] = $_formData['priority'];
2917 2916
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2918 2917
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2919 2918
 		$this->sessionData['disposition'] = $_formData['disposition'];
2920
-		$this->sessionData['mimeType']	= $_formData['mimeType'];
2919
+		$this->sessionData['mimeType'] = $_formData['mimeType'];
2921 2920
 		$this->sessionData['to_infolog'] = $_formData['to_infolog'];
2922 2921
 		$this->sessionData['to_tracker'] = $_formData['to_tracker'];
2923
-		$this->sessionData['attachments']  = $_formData['attachments'];
2924
-		$this->sessionData['smime_sign']  = $_formData['smime_sign'];
2925
-		$this->sessionData['smime_encrypt']  = $_formData['smime_encrypt'];
2922
+		$this->sessionData['attachments'] = $_formData['attachments'];
2923
+		$this->sessionData['smime_sign'] = $_formData['smime_sign'];
2924
+		$this->sessionData['smime_encrypt'] = $_formData['smime_encrypt'];
2926 2925
 
2927 2926
 		if (isset($_formData['lastDrafted']) && !empty($_formData['lastDrafted']))
2928 2927
 		{
@@ -2931,11 +2930,11 @@  discard block
 block discarded – undo
2931 2930
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_formData['mode'].' PID:'.$_formData['processedmail_id']);
2932 2931
 		if (isset($_formData['mode']) && !empty($_formData['mode']))
2933 2932
 		{
2934
-			if ($_formData['mode']=='forward' && !empty($_formData['processedmail_id']))
2933
+			if ($_formData['mode'] == 'forward' && !empty($_formData['processedmail_id']))
2935 2934
 			{
2936
-				$this->sessionData['forwardFlag']='forwarded';
2937
-				$_formData['processedmail_id'] = explode(',',$_formData['processedmail_id']);
2938
-				$this->sessionData['uid']=array();
2935
+				$this->sessionData['forwardFlag'] = 'forwarded';
2936
+				$_formData['processedmail_id'] = explode(',', $_formData['processedmail_id']);
2937
+				$this->sessionData['uid'] = array();
2939 2938
 				foreach ($_formData['processedmail_id'] as $k =>$rowid)
2940 2939
 				{
2941 2940
 					$fhA = mail_ui::splitRowID($rowid);
@@ -2944,13 +2943,13 @@  discard block
 block discarded – undo
2944 2943
 					if (!empty($fhA['folder'])) $this->sessionData['sourceFolder'] = $fhA['folder'];
2945 2944
 				}
2946 2945
 			}
2947
-			if ($_formData['mode']=='reply' && !empty($_formData['processedmail_id']))
2946
+			if ($_formData['mode'] == 'reply' && !empty($_formData['processedmail_id']))
2948 2947
 			{
2949 2948
 				$rhA = mail_ui::splitRowID($_formData['processedmail_id']);
2950 2949
 				$this->sessionData['uid'] = $rhA['msgUID'];
2951 2950
 				$this->sessionData['messageFolder'] = $rhA['folder'];
2952 2951
 			}
2953
-			if ($_formData['mode']=='composefromdraft' && !empty($_formData['processedmail_id']))
2952
+			if ($_formData['mode'] == 'composefromdraft' && !empty($_formData['processedmail_id']))
2954 2953
 			{
2955 2954
 				$dhA = mail_ui::splitRowID($_formData['processedmail_id']);
2956 2955
 				$this->sessionData['uid'] = $dhA['msgUID'];
@@ -2959,26 +2958,26 @@  discard block
 block discarded – undo
2959 2958
 		}
2960 2959
 		// if the body is empty, maybe someone pasted something with scripts, into the message body
2961 2960
 		// this should not happen anymore, unless you call send directly, since the check was introduced with the action command
2962
-		if(empty($this->sessionData['body']))
2961
+		if (empty($this->sessionData['body']))
2963 2962
 		{
2964 2963
 			// this is to be found with the egw_unset_vars array for the _POST['body'] array
2965
-			$name='_POST';
2966
-			$key='body';
2964
+			$name = '_POST';
2965
+			$key = 'body';
2967 2966
 			#error_log($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2968 2967
 			if (isset($GLOBALS['egw_unset_vars'][$name.'['.$key.']']))
2969 2968
 			{
2970
-				$this->sessionData['body'] = self::_getCleanHTML( $GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2971
-				$_formData['body']=$this->sessionData['body'];
2969
+				$this->sessionData['body'] = self::_getCleanHTML($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2970
+				$_formData['body'] = $this->sessionData['body'];
2972 2971
 			}
2973 2972
 			#error_log($this->sessionData['body']);
2974 2973
 		}
2975
-		if(empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2974
+		if (empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2976 2975
 		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder'])) {
2977 2976
 		   	$messageIsDraft = true;
2978 2977
 		}
2979 2978
 		try
2980 2979
 		{
2981
-			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'],true);
2980
+			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'], true);
2982 2981
 		}
2983 2982
 		catch (Exception $e)
2984 2983
 		{
@@ -2989,7 +2988,7 @@  discard block
 block discarded – undo
2989 2988
 		// create the messages and store inline images
2990 2989
 		$inline_images = $this->createMessage($mail, $_formData, $identity);
2991 2990
 		// remember the identity
2992
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2991
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From; //$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2993 2992
 		#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
2994 2993
 		#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";
2995 2994
 		#exit;
@@ -3000,12 +2999,12 @@  discard block
 block discarded – undo
3000 2999
 		$folderOnMailAccount = array();
3001 3000
 		foreach ($folderToCheck as $k => $f)
3002 3001
 		{
3003
-			$fval=$f;
3004
-			$icServerID = $_formData['serverID'];//folders always assumed with serverID
3005
-			if (stripos($f,'::')!==false) list($icServerID,$fval) = explode('::',$f,2);
3006
-			if ($_formData['serverID']!=$_formData['mailaccount'])
3002
+			$fval = $f;
3003
+			$icServerID = $_formData['serverID']; //folders always assumed with serverID
3004
+			if (stripos($f, '::') !== false) list($icServerID, $fval) = explode('::', $f, 2);
3005
+			if ($_formData['serverID'] != $_formData['mailaccount'])
3007 3006
 			{
3008
-				if ($icServerID == $_formData['serverID'] )
3007
+				if ($icServerID == $_formData['serverID'])
3009 3008
 				{
3010 3009
 					$folder[$fval] = $fval;
3011 3010
 					$folderOnServerID[] = $fval;
@@ -3018,7 +3017,7 @@  discard block
 block discarded – undo
3018 3017
 			}
3019 3018
 			else
3020 3019
 			{
3021
-				if ($icServerID == $_formData['serverID'] )
3020
+				if ($icServerID == $_formData['serverID'])
3022 3021
 				{
3023 3022
 					$folder[$fval] = $fval;
3024 3023
 					$folderOnServerID[] = $fval;
@@ -3035,7 +3034,7 @@  discard block
 block discarded – undo
3035 3034
 		// we use the sentFolder settings of the choosen mailaccount
3036 3035
 		// sentFolder is account specific
3037 3036
 		$changeProfileOnSentFolderNeeded = false;
3038
-		if ($_formData['serverID']!=$_formData['mailaccount'])
3037
+		if ($_formData['serverID'] != $_formData['mailaccount'])
3039 3038
 		{
3040 3039
 			$this->changeProfile($_formData['mailaccount']);
3041 3040
 			//error_log(__METHOD__.__LINE__.'#'.$this->mail_bo->profileID.'<->'.$mail_bo->profileID.'#');
@@ -3043,30 +3042,30 @@  discard block
 block discarded – undo
3043 3042
 			// sentFolder is account specific
3044 3043
 			$sentFolder = $this->mail_bo->getSentFolder();
3045 3044
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
3046
-			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
3045
+			if ($sentFolder && $sentFolder != 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
3047 3046
 		}
3048 3047
 		else
3049 3048
 		{
3050 3049
 			$sentFolder = $mail_bo->getSentFolder();
3051 3050
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
3052
-			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
3051
+			if ($sentFolder && $sentFolder != 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
3053 3052
 		}
3054 3053
 		//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
3055 3054
 
3056 3055
 		// we switch $this->mail_bo back to the account we used to work on
3057
-		if ($_formData['serverID']!=$_formData['mailaccount'])
3056
+		if ($_formData['serverID'] != $_formData['mailaccount'])
3058 3057
 		{
3059 3058
 			$this->changeProfile($_formData['serverID']);
3060 3059
 		}
3061 3060
 
3062 3061
 
3063
-		if(isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
3062
+		if (isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
3064 3063
 			$this->mailPreferences['sendOptions'] != 'send_only' &&
3065 3064
 			$messageIsDraft == false)
3066 3065
 		{
3067 3066
 			if ($sentFolder)
3068 3067
 			{
3069
-				if ($_formData['serverID']!=$_formData['mailaccount'])
3068
+				if ($_formData['serverID'] != $_formData['mailaccount'])
3070 3069
 				{
3071 3070
 					$folderOnMailAccount[] = $sentFolder;
3072 3071
 				}
@@ -3083,14 +3082,14 @@  discard block
 block discarded – undo
3083 3082
 		}
3084 3083
 		else
3085 3084
 		{
3086
-			if (((!isset($sentFolder)||$sentFolder==false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
3085
+			if (((!isset($sentFolder) || $sentFolder == false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
3087 3086
 				($this->mailPreferences['sendOptions'] != 'send_only' &&
3088 3087
 				$sentFolder != 'none')) $this->errorInfo = lang("No Send Folder set in preferences");
3089 3088
 		}
3090 3089
 		// draftFolder is on Server we start from
3091
-		if($messageIsDraft == true) {
3090
+		if ($messageIsDraft == true) {
3092 3091
 			$draftFolder = $mail_bo->getDraftFolder();
3093
-			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true)) {
3092
+			if (!empty($draftFolder) && $mail_bo->folderExists($draftFolder, true)) {
3094 3093
 				$this->sessionData['folder'] = array($draftFolder);
3095 3094
 				$folderOnServerID[] = $draftFolder;
3096 3095
 				$folder[$draftFolder] = $draftFolder;
@@ -3099,18 +3098,18 @@  discard block
 block discarded – undo
3099 3098
 		if ($folderOnServerID) $folderOnServerID = array_unique($folderOnServerID);
3100 3099
 		if ($folderOnMailAccount) $folderOnMailAccount = array_unique($folderOnMailAccount);
3101 3100
 		if (($this->mailPreferences['sendOptions'] != 'send_only' && $sentFolder != 'none') &&
3102
-			!( count($folder) > 0) &&
3103
-			!($_formData['to_infolog']=='on' || $_formData['to_tracker']=='on'))
3101
+			!(count($folder) > 0) &&
3102
+			!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on'))
3104 3103
 		{
3105
-			$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:'');
3104
+			$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 : '');
3106 3105
 			#error_log($this->errorInfo);
3107 3106
 			return false;
3108 3107
 		}
3109 3108
 		// SMIME SIGN/ENCRYPTION
3110
-		if ($_formData['smime_sign'] == 'on' || $_formData['smime_encrypt'] == 'on' )
3109
+		if ($_formData['smime_sign'] == 'on' || $_formData['smime_encrypt'] == 'on')
3111 3110
 		{
3112
-			$recipients = array_merge($_formData['to'], (array) $_formData['cc'], (array) $_formData['bcc']);
3113
-			try	{
3111
+			$recipients = array_merge($_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc']);
3112
+			try {
3114 3113
 				if ($_formData['smime_sign'] == 'on')
3115 3114
 				{
3116 3115
 					if ($_formData['smime_passphrase'] != '') {
@@ -3123,7 +3122,7 @@  discard block
 block discarded – undo
3123 3122
 					}
3124 3123
 					$smime_success = $this->_encrypt(
3125 3124
 						$mail,
3126
-						$_formData['smime_encrypt'] == 'on'? Mail\Smime::TYPE_SIGN_ENCRYPT: Mail\Smime::TYPE_SIGN,
3125
+						$_formData['smime_encrypt'] == 'on' ? Mail\Smime::TYPE_SIGN_ENCRYPT : Mail\Smime::TYPE_SIGN,
3127 3126
 						Mail::stripRFC822Addresses($recipients),
3128 3127
 						$identity['ident_email'],
3129 3128
 						$_formData['smime_passphrase']
@@ -3131,16 +3130,15 @@  discard block
 block discarded – undo
3131 3130
 					if (!$smime_success)
3132 3131
 					{
3133 3132
 						$response = Api\Json\Response::get();
3134
-						$this->errorInfo = $_formData['smime_passphrase'] == ''?
3135
-								lang('You need to enter your S/MIME passphrase to send this message.'):
3136
-								lang('The entered passphrase is not correct! Please try again.');
3133
+						$this->errorInfo = $_formData['smime_passphrase'] == '' ?
3134
+								lang('You need to enter your S/MIME passphrase to send this message.') : lang('The entered passphrase is not correct! Please try again.');
3137 3135
 						$response->call('app.mail.smimePassDialog', $this->errorInfo);
3138 3136
 						return false;
3139 3137
 					}
3140 3138
 				}
3141 3139
 				elseif ($_formData['smime_sign'] == 'off' && $_formData['smime_encrypt'] == 'on')
3142 3140
 				{
3143
-					$smime_success =  $this->_encrypt(
3141
+					$smime_success = $this->_encrypt(
3144 3142
 						$mail,
3145 3143
 						Mail\Smime::TYPE_ENCRYPT,
3146 3144
 						Mail::stripRFC822Addresses($recipients),
@@ -3160,23 +3158,23 @@  discard block
 block discarded – undo
3160 3158
 		@set_time_limit(120);
3161 3159
 		//$mail->SMTPDebug = 10;
3162 3160
 		//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']));
3163
-		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
3161
+		if (count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
3164 3162
 			try {
3165 3163
 				// do no close the session before sending, if we have to store the send text for infolog or other integration in the session
3166
-				if (!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' ))
3164
+				if (!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on'))
3167 3165
 				{
3168 3166
 					$GLOBALS['egw']->session->commit_session();
3169 3167
 				}
3170 3168
 				$mail->send();
3171 3169
 			}
3172
-			catch(Exception $e) {
3170
+			catch (Exception $e) {
3173 3171
 				_egw_log_exception($e);
3174 3172
 				//if( $e->details ) error_log(__METHOD__.__LINE__.array2string($e->details));
3175
-				$this->errorInfo = $e->getMessage().($e->details?'<br/>'.$e->details:'');
3173
+				$this->errorInfo = $e->getMessage().($e->details ? '<br/>'.$e->details : '');
3176 3174
 				return false;
3177 3175
 			}
3178 3176
 		} else {
3179
-			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder'])) {
3177
+			if (count(array($this->sessionData['folder'])) > 0 && !empty($this->sessionData['folder'])) {
3180 3178
 				//error_log(__METHOD__.__LINE__."Folders:".print_r($this->sessionData['folder'],true));
3181 3179
 			} else {
3182 3180
 				$this->errorInfo = lang("Error: ").lang("No Address TO/CC/BCC supplied, and no folder to save message to provided.");
@@ -3204,15 +3202,15 @@  discard block
 block discarded – undo
3204 3202
 		// copying mail to folder
3205 3203
 		if (count($folder) > 0)
3206 3204
 		{
3207
-			foreach($folderOnServerID as $folderName) {
3205
+			foreach ($folderOnServerID as $folderName) {
3208 3206
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3209 3207
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3210 3208
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3211 3209
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3212
-				if ($mail_bo->folderExists($folderName,true)) {
3213
-					if($mail_bo->isSentFolder($folderName)) {
3210
+				if ($mail_bo->folderExists($folderName, true)) {
3211
+					if ($mail_bo->isSentFolder($folderName)) {
3214 3212
 						$flags = '\\Seen';
3215
-					} elseif($mail_bo->isDraftFolder($folderName)) {
3213
+					} elseif ($mail_bo->isDraftFolder($folderName)) {
3216 3214
 						$flags = '\\Draft';
3217 3215
 					} else {
3218 3216
 						$flags = '\\Seen';
@@ -3228,25 +3226,25 @@  discard block
 block discarded – undo
3228 3226
 					}
3229 3227
 					catch (Api\Exception\WrongUserinput $e)
3230 3228
 					{
3231
-						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()));
3229
+						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()));
3232 3230
 					}
3233 3231
 				}
3234 3232
 				else
3235 3233
 				{
3236
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3234
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3237 3235
 				}
3238 3236
 			}
3239 3237
 			// if we choose to send from a differing profile
3240 3238
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['mailaccount']);
3241
-			foreach($folderOnMailAccount as $folderName) {
3239
+			foreach ($folderOnMailAccount as $folderName) {
3242 3240
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3243 3241
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3244 3242
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3245 3243
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3246
-				if ($this->mail_bo->folderExists($folderName,true)) {
3247
-					if($this->mail_bo->isSentFolder($folderName)) {
3244
+				if ($this->mail_bo->folderExists($folderName, true)) {
3245
+					if ($this->mail_bo->isSentFolder($folderName)) {
3248 3246
 						$flags = '\\Seen';
3249
-					} elseif($this->mail_bo->isDraftFolder($folderName)) {
3247
+					} elseif ($this->mail_bo->isDraftFolder($folderName)) {
3250 3248
 						$flags = '\\Draft';
3251 3249
 					} else {
3252 3250
 						$flags = '\\Seen';
@@ -3262,12 +3260,12 @@  discard block
 block discarded – undo
3262 3260
 					}
3263 3261
 					catch (Api\Exception\WrongUserinput $e)
3264 3262
 					{
3265
-						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()));
3263
+						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()));
3266 3264
 					}
3267 3265
 				}
3268 3266
 				else
3269 3267
 				{
3270
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3268
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3271 3269
 				}
3272 3270
 			}
3273 3271
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['serverID']);
@@ -3278,27 +3276,27 @@  discard block
 block discarded – undo
3278 3276
 		$lastDrafted = false;
3279 3277
 		if (isset($this->sessionData['lastDrafted']))
3280 3278
 		{
3281
-			$lastDrafted=array();
3279
+			$lastDrafted = array();
3282 3280
 			$dhA = mail_ui::splitRowID($this->sessionData['lastDrafted']);
3283 3281
 			$lastDrafted['uid'] = $dhA['msgUID'];
3284 3282
 			$lastDrafted['folder'] = $dhA['folder'];
3285
-			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
3283
+			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
3286 3284
 			// manually drafted, do not delete
3287 3285
 			// will be handled later on IF mode was $_formData['mode']=='composefromdraft'
3288
-			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
3286
+			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted = false;
3289 3287
 			//error_log(__METHOD__.__LINE__.array2string($lastDrafted));
3290 3288
 		}
3291 3289
 		if ($lastDrafted && is_array($lastDrafted) && $mail_bo->isDraftFolder($lastDrafted['folder']))
3292 3290
 		{
3293 3291
 			try
3294 3292
 			{
3295
-				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode']=='composefromdraft' &&
3296
-					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )&&$this->sessionData['attachments']))
3293
+				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode'] == 'composefromdraft' &&
3294
+					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3297 3295
 				{
3298 3296
 					//error_log(__METHOD__.__LINE__."#".$lastDrafted['uid'].'#'.$lastDrafted['folder'].array2string($_formData));
3299 3297
 					//error_log(__METHOD__.__LINE__."#".array2string($_formData));
3300 3298
 					//error_log(__METHOD__.__LINE__."#".array2string($this->sessionData));
3301
-					$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
3299
+					$mail_bo->deleteMessages($lastDrafted['uid'], $lastDrafted['folder'], 'remove_immediately');
3302 3300
 				}
3303 3301
 			}
3304 3302
 			catch (Api\Exception $e)
@@ -3310,22 +3308,22 @@  discard block
 block discarded – undo
3310 3308
 		unset($this->sessionData['lastDrafted']);
3311 3309
 
3312 3310
 		//error_log("handling draft messages, flagging and such");
3313
-		if((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3311
+		if ((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3314 3312
 			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3315 3313
 			// mark message as answered
3316 3314
 			$mail_bo->openConnection();
3317
-			$mail_bo->reopen(($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3315
+			$mail_bo->reopen(($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3318 3316
 			// if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send
3319 3317
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
3320 3318
 			if ($mail_bo->isDraftFolder($this->sessionData['messageFolder']) && !$mail_bo->isTemplateFolder($this->sessionData['messageFolder']))
3321 3319
 			{
3322 3320
 				try // message may be deleted already, as it maybe done by autosave
3323 3321
 				{
3324
-					if ($_formData['mode']=='composefromdraft' &&
3322
+					if ($_formData['mode'] == 'composefromdraft' &&
3325 3323
 						!(($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3326 3324
 					{
3327 3325
 						//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
3328
-						$mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder'], 'remove_immediately');
3326
+						$mail_bo->deleteMessages(array($this->sessionData['uid']), $this->sessionData['messageFolder'], 'remove_immediately');
3329 3327
 					}
3330 3328
 				}
3331 3329
 				catch (Api\Exception $e)
@@ -3334,14 +3332,14 @@  discard block
 block discarded – undo
3334 3332
 					unset($e);
3335 3333
 				}
3336 3334
 			} else {
3337
-				$mail_bo->flagMessages("answered", $this->sessionData['uid'],($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3335
+				$mail_bo->flagMessages("answered", $this->sessionData['uid'], ($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3338 3336
 				//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)).':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3339
-				if (array_key_exists('forwardFlag',$this->sessionData) && $this->sessionData['forwardFlag']=='forwarded')
3337
+				if (array_key_exists('forwardFlag', $this->sessionData) && $this->sessionData['forwardFlag'] == 'forwarded')
3340 3338
 				{
3341 3339
 					try
3342 3340
 					{
3343 3341
 						//error_log(__METHOD__.__LINE__.':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3344
-						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'],$this->sessionData['sourceFolder']);
3342
+						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'], $this->sessionData['sourceFolder']);
3345 3343
 					}
3346 3344
 					catch (Api\Exception $e)
3347 3345
 					{
@@ -3369,49 +3367,49 @@  discard block
 block discarded – undo
3369 3367
 		if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc'];
3370 3368
 		if (!empty($mailaddresses)) $mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3371 3369
 
3372
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )
3370
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on')
3373 3371
 		{
3374 3372
 			$this->sessionData['attachments'] = array_merge((array)$this->sessionData['attachments'], (array)$inline_images);
3375 3373
 
3376
-			foreach(array('to_infolog','to_tracker','to_calendar') as $app_key)
3374
+			foreach (array('to_infolog', 'to_tracker', 'to_calendar') as $app_key)
3377 3375
 			{
3378 3376
 				$entryid = $_formData['to_integrate_ids'][0][$app_key];
3379 3377
 				if ($_formData[$app_key] == 'on')
3380 3378
 				{
3381
-					$app_name = substr($app_key,3);
3379
+					$app_name = substr($app_key, 3);
3382 3380
 					// Get registered hook data of the app called for integration
3383
-					$hook = Api\Hooks::single(array('location'=> 'mail_import'),$app_name);
3381
+					$hook = Api\Hooks::single(array('location'=> 'mail_import'), $app_name);
3384 3382
 
3385 3383
 					// store mail / eml in temp. file to not have to download it from mail-server again
3386
-					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'mail_integrate');
3384
+					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'mail_integrate');
3387 3385
 					$eml_fp = fopen($eml, 'w');
3388 3386
 					stream_copy_to_stream($mail->getRaw(), $eml_fp);
3389 3387
 					fclose($eml_fp);
3390 3388
 					$target = array(
3391 3389
 						'menuaction' => $hook['menuaction'],
3392
-						'egw_data' => Link::set_data(null,'mail_integration::integrate',array(
3390
+						'egw_data' => Link::set_data(null, 'mail_integration::integrate', array(
3393 3391
 							$mailaddresses,
3394 3392
 							$this->sessionData['subject'],
3395 3393
 							$this->convertHTMLToText($this->sessionData['body']),
3396 3394
 							$this->sessionData['attachments'],
3397 3395
 							false, // date
3398 3396
 							$eml,
3399
-							$_formData['serverID']),true),
3397
+							$_formData['serverID']), true),
3400 3398
 						'app' => $app_name
3401 3399
 					);
3402 3400
 					if ($entryid) $target['entry_id'] = $entryid;
3403 3401
 					// Open the app called for integration in a popup
3404 3402
 					// and store the mail raw data as egw_data, in order to
3405 3403
 					// be stored from registered app method later
3406
-					Framework::popup(Egw::link('/index.php', $target),'_blank',$hook['popup']);
3404
+					Framework::popup(Egw::link('/index.php', $target), '_blank', $hook['popup']);
3407 3405
 				}
3408 3406
 			}
3409 3407
 		}
3410 3408
 		// only clean up temp-files, if we dont need them for mail_integration::integrate
3411
-		elseif(is_array($this->sessionData['attachments']))
3409
+		elseif (is_array($this->sessionData['attachments']))
3412 3410
 		{
3413
-			foreach($this->sessionData['attachments'] as $value) {
3414
-				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3411
+			foreach ($this->sessionData['attachments'] as $value) {
3412
+				if (!empty($value['file']) && parse_url($value['file'], PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3415 3413
 					unlink($GLOBALS['egw_info']['server']['temp_dir'].'/'.$value['file']);
3416 3414
 				}
3417 3415
 			}
@@ -3428,7 +3426,7 @@  discard block
 block discarded – undo
3428 3426
 	 * @param array $content
3429 3427
 	 * @return array - the input, enriched with some not set attributes
3430 3428
 	 */
3431
-	function setDefaults($content=array())
3429
+	function setDefaults($content = array())
3432 3430
 	{
3433 3431
 		// if there's not already an identity selected for current account
3434 3432
 		if (empty($content['mailidentity']))
@@ -3437,7 +3435,7 @@  discard block
 block discarded – undo
3437 3435
 			if (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed']))
3438 3436
 			{
3439 3437
 				$sigPref = $GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed'];
3440
-				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID]>0)
3438
+				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID] > 0)
3441 3439
 				{
3442 3440
 					$content['mailidentity'] = $sigPref[$this->mail_bo->profileID];
3443 3441
 				}
@@ -3446,7 +3444,7 @@  discard block
 block discarded – undo
3446 3444
 			if (empty($content['mailidentity']))
3447 3445
 			{
3448 3446
 				$default_identity = null;
3449
-				foreach(Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3447
+				foreach (Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3450 3448
 				{
3451 3449
 					if (!isset($default_identity)) $default_identity = $identity['ident_id'];
3452 3450
 					if (!empty($identity['ident_signature']))
@@ -3461,7 +3459,7 @@  discard block
 block discarded – undo
3461 3459
 		if (!isset($content['mimeType']) || empty($content['mimeType']))
3462 3460
 		{
3463 3461
 			$content['mimeType'] = 'html';
3464
-			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text") $content['mimeType']  = 'plain';
3462
+			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions'] == "text") $content['mimeType'] = 'plain';
3465 3463
 		}
3466 3464
 		return $content;
3467 3465
 
@@ -3484,7 +3482,7 @@  discard block
 block discarded – undo
3484 3482
 	 * @param boolean $_noPrefixId = false, if set to true folders name does not get prefixed by account id
3485 3483
 	 * @return type
3486 3484
 	 */
3487
-	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false) {
3485
+	function ajax_searchFolder($_searchStringLength = 2, $_returnList = false, $_mailaccountToSearch = null, $_noPrefixId = false) {
3488 3486
 		//error_log(__METHOD__.__LINE__.':'.array2string($_REQUEST));
3489 3487
 		static $useCacheIfPossible = null;
3490 3488
 		if (is_null($useCacheIfPossible)) $useCacheIfPossible = true;
@@ -3497,36 +3495,36 @@  discard block
 block discarded – undo
3497 3495
 		{
3498 3496
 			$this->changeProfile($_mailaccountToSearch);
3499 3497
 		}
3500
-		if (strlen($_searchString)>=$_searchStringLength && isset($this->mail_bo->icServer))
3498
+		if (strlen($_searchString) >= $_searchStringLength && isset($this->mail_bo->icServer))
3501 3499
 		{
3502 3500
 			//error_log(__METHOD__.__LINE__.':'.$this->mail_bo->icServer->ImapServerId);
3503 3501
 			$this->mail_bo->openConnection($this->mail_bo->icServer->ImapServerId);
3504 3502
 			//error_log(__METHOD__.__LINE__.array2string($_searchString).'<->'.$searchString);
3505
-			$folderObjects = $this->mail_bo->getFolderObjects(true,false,true,$useCacheIfPossible);
3506
-			if (count($folderObjects)<=1) {
3503
+			$folderObjects = $this->mail_bo->getFolderObjects(true, false, true, $useCacheIfPossible);
3504
+			if (count($folderObjects) <= 1) {
3507 3505
 				$useCacheIfPossible = false;
3508 3506
 			}
3509 3507
 			else
3510 3508
 			{
3511 3509
 				$useCacheIfPossible = true;
3512 3510
 			}
3513
-			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset,'UTF7-IMAP');
3511
+			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset, 'UTF7-IMAP');
3514 3512
 			foreach ($folderObjects as $k =>$fA)
3515 3513
 			{
3516 3514
 				//error_log(__METHOD__.__LINE__.$_searchString.'/'.$searchString.' in '.$k.'->'.$fA->displayName);
3517
-				$f=false;
3518
-				$key = $_noPrefixId?$k:$_mailaccountToSearch.'::'.$k;
3519
-				if ($_searchStringLength<=0)
3515
+				$f = false;
3516
+				$key = $_noPrefixId ? $k : $_mailaccountToSearch.'::'.$k;
3517
+				if ($_searchStringLength <= 0)
3520 3518
 				{
3521
-					$f=true;
3519
+					$f = true;
3522 3520
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3523 3521
 				}
3524
-				if ($f==false && stripos($fA->displayName,$_searchString)!==false)
3522
+				if ($f == false && stripos($fA->displayName, $_searchString) !== false)
3525 3523
 				{
3526
-					$f=true;
3524
+					$f = true;
3527 3525
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3528 3526
 				}
3529
-				if ($f==false && stripos($k,$searchString)!==false)
3527
+				if ($f == false && stripos($k, $searchString) !== false)
3530 3528
 				{
3531 3529
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3532 3530
 				}
@@ -3554,7 +3552,7 @@  discard block
 block discarded – undo
3554 3552
 		exit();
3555 3553
 	}
3556 3554
 
3557
-	public static function ajax_searchAddress($_searchStringLength=2) {
3555
+	public static function ajax_searchAddress($_searchStringLength = 2) {
3558 3556
 		//error_log(__METHOD__. "request from seachAddress " . $_REQUEST['query']);
3559 3557
 		$_searchString = trim($_REQUEST['query']);
3560 3558
 		$include_lists = (boolean)$_REQUEST['include_lists'];
@@ -3563,12 +3561,12 @@  discard block
 block discarded – undo
3563 3561
 		$results = array();
3564 3562
 
3565 3563
 		// Add up to 10 matching mailing lists, and 10 groups
3566
-		if($include_lists)
3564
+		if ($include_lists)
3567 3565
 		{
3568 3566
 			$results += static::get_lists($_searchString, $contacts_obj);
3569 3567
 		}
3570 3568
 
3571
-		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
3569
+		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString) >= $_searchStringLength)
3572 3570
 		{
3573 3571
 			//error_log(__METHOD__.__LINE__.array2string($_searchString));
3574 3572
 			$showAccounts = $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== '1';
@@ -3577,66 +3575,66 @@  discard block
 block discarded – undo
3577 3575
 			{
3578 3576
 				if (mb_strlen($v) < 3) unset($search[$k]);
3579 3577
 			}
3580
-			$search_str = implode(' +', $search);	// tell contacts/so_sql to AND search patterns
3578
+			$search_str = implode(' +', $search); // tell contacts/so_sql to AND search patterns
3581 3579
 			//error_log(__METHOD__.__LINE__.$_searchString);
3582 3580
 			$filter = $showAccounts ? array() : array('account_id' => null);
3583
-			$filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home', 'contact_id');
3584
-			$cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home', 'contact_id');
3585
-			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter);
3581
+			$filter['cols_to_search'] = array('n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home', 'contact_id');
3582
+			$cols = array('n_fn', 'n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home', 'contact_id');
3583
+			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3586 3584
 			$cfs_type_email = Api\Storage\Customfields::get_email_cfs('addressbook');
3587 3585
 			// additionally search the accounts, if the contact storage is not the account storage
3588 3586
 			if ($showAccounts && $contacts_obj->so_accounts)
3589 3587
 			{
3590 3588
 				$filter['owner'] = 0;
3591
-				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false,'OR', array(0,100), $filter);
3589
+				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3592 3590
 
3593 3591
 				if ($contacts && $accounts)
3594 3592
 				{
3595
-					$contacts = array_merge($contacts,$accounts);
3596
-					usort($contacts,function($a, $b)
3593
+					$contacts = array_merge($contacts, $accounts);
3594
+					usort($contacts, function($a, $b)
3597 3595
 					{
3598 3596
 						return strcasecmp($a['n_fn'], $b['n_fn']);
3599 3597
 					});
3600 3598
 				}
3601
-				elseif($accounts)
3599
+				elseif ($accounts)
3602 3600
 				{
3603
-					$contacts =& $accounts;
3601
+					$contacts = & $accounts;
3604 3602
 				}
3605 3603
 				unset($accounts);
3606 3604
 			}
3607 3605
 		}
3608 3606
 
3609
-		if(is_array($contacts)) {
3610
-			foreach($contacts as $contact) {
3607
+		if (is_array($contacts)) {
3608
+			foreach ($contacts as $contact) {
3611 3609
 				$cf_emails = (array)array_values(array_values($contacts_obj->read_customfields($contact['id'], $cfs_type_email))[0]);
3612
-				foreach(array_merge(array($contact['email'],$contact['email_home']), $cf_emails) as $email) {
3610
+				foreach (array_merge(array($contact['email'], $contact['email_home']), $cf_emails) as $email) {
3613 3611
 					// avoid wrong addresses, if an rfc822 encoded address is in addressbook
3614 3612
 					//$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
3615 3613
 					$rfcAddr = Mail::parseAddressList($email);
3616
-					$_rfcAddr=$rfcAddr->first();
3614
+					$_rfcAddr = $rfcAddr->first();
3617 3615
 					if (!$_rfcAddr->valid)
3618 3616
 					{
3619 3617
 						continue; // skip address if we encounter an error here
3620 3618
 					}
3621 3619
 					$email = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
3622 3620
 
3623
-					if (method_exists($contacts_obj,'search'))
3621
+					if (method_exists($contacts_obj, 'search'))
3624 3622
 					{
3625
-						$contact['n_fn']='';
3623
+						$contact['n_fn'] = '';
3626 3624
 						if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
3627
-						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3628
-						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3629
-						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3630
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3625
+						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_given'];
3626
+						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_family'];
3627
+						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').'('.$contact['org_name'].')';
3628
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3631 3629
 					}
3632 3630
 					else
3633 3631
 					{
3634
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3632
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3635 3633
 					}
3636 3634
 					$args = explode('@', trim($email));
3637 3635
 					$args[] = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']);
3638 3636
 					$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
3639
-					if(!empty($email) && in_array($completeMailString ,$results) === false) {
3637
+					if (!empty($email) && in_array($completeMailString, $results) === false) {
3640 3638
 						$results[] = array(
3641 3639
 							'id'=>$completeMailString,
3642 3640
 							'label' => $completeMailString,
@@ -3652,10 +3650,10 @@  discard block
 block discarded – undo
3652 3650
 		// Add groups
3653 3651
 		$group_options = array('account_type' => 'groups');
3654 3652
 		$groups = $GLOBALS['egw']->accounts->link_query($_searchString, $group_options);
3655
-		foreach($groups as $g_id => $name)
3653
+		foreach ($groups as $g_id => $name)
3656 3654
 		{
3657 3655
 			$group = $GLOBALS['egw']->accounts->read($g_id);
3658
-			if(!$group['account_email']) continue;
3656
+			if (!$group['account_email']) continue;
3659 3657
 			$args = explode('@', trim($group['account_email']));
3660 3658
 			$args[] = $name;
3661 3659
 			$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
@@ -3696,14 +3694,14 @@  discard block
 block discarded – undo
3696 3694
 			}
3697 3695
 		);
3698 3696
 
3699
-		foreach($lists as $key => $list_name)
3697
+		foreach ($lists as $key => $list_name)
3700 3698
 		{
3701 3699
 			$type = $key > 0 ? 'manual' : 'group';
3702 3700
 			$list = array(
3703 3701
 				'id'	=> $key,
3704 3702
 				'name'	=> $list_name,
3705 3703
 				'label'	=> $list_name,
3706
-				'class' => 'mailinglist ' . "{$type}_list",
3704
+				'class' => 'mailinglist '."{$type}_list",
3707 3705
 				'title' => lang('Mailinglist'),
3708 3706
 				'data'	=> $key
3709 3707
 			);
@@ -3711,9 +3709,9 @@  discard block
 block discarded – undo
3711 3709
 		}
3712 3710
 		$trim = function($list) {
3713 3711
 			$limit = 10;
3714
-			if(count($list) <= $limit) return $list;
3715
-			$list[$limit-1]['class'].= ' more_results';
3716
-			$list[$limit-1]['title'] .= '  (' . lang('%1 more', count($list) - $limit) . ')';
3712
+			if (count($list) <= $limit) return $list;
3713
+			$list[$limit - 1]['class'] .= ' more_results';
3714
+			$list[$limit - 1]['title'] .= '  ('.lang('%1 more', count($list) - $limit).')';
3717 3715
 			return array_slice($list, 0, $limit);
3718 3716
 		};
3719 3717
 		return array_merge($trim($group_lists), $trim($manual_lists));
@@ -3727,7 +3725,7 @@  discard block
 block discarded – undo
3727 3725
 	public function ajax_merge($contact_id)
3728 3726
 	{
3729 3727
 		$response = Api\Json\Response::get();
3730
-		if(class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3728
+		if (class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3731 3729
 		{
3732 3730
 			$document_merge = new $_REQUEST['merge']();
3733 3731
 		}
@@ -3737,7 +3735,7 @@  discard block
 block discarded – undo
3737 3735
 		}
3738 3736
 		$this->mail_bo->openConnection();
3739 3737
 
3740
-		if(($error = $document_merge->check_document($_REQUEST['document'],'')))
3738
+		if (($error = $document_merge->check_document($_REQUEST['document'], '')))
3741 3739
 		{
3742 3740
 			$response->error($error);
3743 3741
 			return;
@@ -3748,23 +3746,23 @@  discard block
 block discarded – undo
3748 3746
 		try
3749 3747
 		{
3750 3748
 			$results = $this->mail_bo->importMessageToMergeAndSend(
3751
-				$document_merge, Vfs::PREFIX . $_REQUEST['document'],
3749
+				$document_merge, Vfs::PREFIX.$_REQUEST['document'],
3752 3750
 				// Send an extra non-numeric ID to force actual send of document
3753 3751
 				// instead of save as draft
3754 3752
 				array((int)$contact_id, ''),
3755
-				$folder,$merged_mail_id
3753
+				$folder, $merged_mail_id
3756 3754
 			);
3757 3755
 
3758 3756
 			// Also save as infolog
3759
-			if($merged_mail_id && $_REQUEST['to_app'] && isset($GLOBALS['egw_info']['user']['apps'][$_REQUEST['to_app']]))
3757
+			if ($merged_mail_id && $_REQUEST['to_app'] && isset($GLOBALS['egw_info']['user']['apps'][$_REQUEST['to_app']]))
3760 3758
 			{
3761 3759
 				$rowid = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $merged_mail_id, true);
3762 3760
 				$data = mail_integration::get_integrate_data($rowid);
3763
-				if($data && $_REQUEST['to_app'] == 'infolog')
3761
+				if ($data && $_REQUEST['to_app'] == 'infolog')
3764 3762
 				{
3765 3763
 					$bo = new infolog_bo();
3766
-					$entry = $bo->import_mail($data['addresses'],$data['subject'],$data['message'],$data['attachments'],$data['date']);
3767
-					if($_REQUEST['info_type'] && isset($bo->enums['type'][$_REQUEST['info_type']]))
3764
+					$entry = $bo->import_mail($data['addresses'], $data['subject'], $data['message'], $data['attachments'], $data['date']);
3765
+					if ($_REQUEST['info_type'] && isset($bo->enums['type'][$_REQUEST['info_type']]))
3768 3766
 					{
3769 3767
 						$entry['info_type'] = $_REQUEST['info_type'];
3770 3768
 					}
@@ -3783,13 +3781,13 @@  discard block
 block discarded – undo
3783 3781
 			);
3784 3782
 		}
3785 3783
 
3786
-		if($results['success'])
3784
+		if ($results['success'])
3787 3785
 		{
3788
-			$response->data(implode(',',$results['success']));
3786
+			$response->data(implode(',', $results['success']));
3789 3787
 		}
3790
-		if($results['failed'])
3788
+		if ($results['failed'])
3791 3789
 		{
3792
-			$response->error(implode(',',$results['failed']));
3790
+			$response->error(implode(',', $results['failed']));
3793 3791
 		}
3794 3792
 	}
3795 3793
 
@@ -3805,7 +3803,7 @@  discard block
 block discarded – undo
3805 3803
 	 * @return boolean returns true if successful and false if passphrase required
3806 3804
 	 * @throws Api\Exception\WrongUserinput if no certificate found
3807 3805
 	 */
3808
-	protected function _encrypt($mail, $type, $recipients, $sender, $passphrase='')
3806
+	protected function _encrypt($mail, $type, $recipients, $sender, $passphrase = '')
3809 3807
 	{
3810 3808
 		$AB = new addressbook_bo();
3811 3809
 		 // passphrase of sender private key
@@ -3814,7 +3812,7 @@  discard block
 block discarded – undo
3814 3812
 		try
3815 3813
 		{
3816 3814
 			$sender_cert = $AB->get_smime_keys($sender);
3817
-			if (!$sender_cert)	throw new Exception("S/MIME Encryption failed because no certificate has been found for sender address: " . $sender);
3815
+			if (!$sender_cert)	throw new Exception("S/MIME Encryption failed because no certificate has been found for sender address: ".$sender);
3818 3816
 			$params['senderPubKey'] = $sender_cert[$sender];
3819 3817
 
3820 3818
 			if (isset($sender) && ($type == Mail\Smime::TYPE_SIGN || $type == Mail\Smime::TYPE_SIGN_ENCRYPT))
@@ -3829,14 +3827,14 @@  discard block
 block discarded – undo
3829 3827
 				$params['recipientsCerts'] = $AB->get_smime_keys($recipients);
3830 3828
 				foreach ($recipients as &$recipient)
3831 3829
 				{
3832
-					if (!$params['recipientsCerts'][$recipient]) $missingCerts []= $recipient;
3830
+					if (!$params['recipientsCerts'][$recipient]) $missingCerts [] = $recipient;
3833 3831
 				}
3834
-				if (is_array($missingCerts)) throw new Exception ('S/MIME Encryption failed because no certificate has been found for following addresses: '. implode ('|', $missingCerts));
3832
+				if (is_array($missingCerts)) throw new Exception('S/MIME Encryption failed because no certificate has been found for following addresses: '.implode('|', $missingCerts));
3835 3833
 			}
3836 3834
 
3837 3835
 			return $mail->smimeEncrypt($type, $params);
3838 3836
 		}
3839
-		catch(Api\Exception\WrongUserinput $e)
3837
+		catch (Api\Exception\WrongUserinput $e)
3840 3838
 		{
3841 3839
 			throw new $e;
3842 3840
 		}
@@ -3852,7 +3850,7 @@  discard block
 block discarded – undo
3852 3850
 	 *
3853 3851
 	 * @throws Exception throws exception on cross account attempt
3854 3852
 	 */
3855
-	function _get_uids_as_attachments ($_ids, $_serverID)
3853
+	function _get_uids_as_attachments($_ids, $_serverID)
3856 3854
 	{
3857 3855
 		$ids = is_array($_ids) ? $_ids : explode(',', $_ids);
3858 3856
 		if (is_array($ids) && $_serverID)
@@ -3866,12 +3864,12 @@  discard block
 block discarded – undo
3866 3864
 		foreach ($ids as &$id)
3867 3865
 		{
3868 3866
 			$parts = mail_ui::splitRowID($id);
3869
-			$mail_bo    = $this->mail_bo;
3867
+			$mail_bo = $this->mail_bo;
3870 3868
 			$mail_bo->openConnection();
3871 3869
 			$mail_bo->reopen($parts['folder']);
3872
-			$headers	= $mail_bo->getMessageEnvelope($parts['msgUID'], null,false,$parts['folder']);
3870
+			$headers = $mail_bo->getMessageEnvelope($parts['msgUID'], null, false, $parts['folder']);
3873 3871
 			$this->addMessageAttachment($parts['msgUID'], null, $parts['folder'],
3874
-					$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
3872
+					$mail_bo->decode_header(($headers['SUBJECT'] ? $headers['SUBJECT'] : lang('no subject'))).'.eml',
3875 3873
 					'MESSAGE/RFC822', $headers['SIZE'] ? $headers['SIZE'] : lang('unknown'));
3876 3874
 			$mail_bo->closeConnection();
3877 3875
 		}
Please login to merge, or discard this patch.