Completed
Push — 16.1 ( 622b92...c1c7ba )
by Ralf
35:24 queued 19:51
created
mail/inc/class.mail_compose.inc.php 2 patches
Spacing   +604 added lines, -605 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class mail_compose
26 26
 {
27
-	var $public_functions = array
28
-	(
27
+	var $public_functions = array(
29 28
 		'compose'		=> True,
30 29
 		'getAttachment'		=> True,
31 30
 	);
@@ -34,8 +33,8 @@  discard block
 block discarded – undo
34 33
 	 * class vars for destination, priorities, mimeTypes
35 34
 	 */
36 35
 	static $destinations = array(
37
-		'to' 		=> 'to',  // lang('to')
38
-		'cc'		=> 'cc',  // lang('cc')
36
+		'to' 		=> 'to', // lang('to')
37
+		'cc'		=> 'cc', // lang('cc')
39 38
 		'bcc'		=> 'bcc', // lang('bcc')
40 39
 		'replyto'	=> 'replyto', // lang('replyto')
41 40
 		'folder'	=> 'folder'  // lang('folder')
@@ -63,20 +62,20 @@  discard block
 block discarded – undo
63 62
 	 * @var array
64 63
 	 */
65 64
 	var $mailPreferences;
66
-	var $attachments;	// Array of attachments
65
+	var $attachments; // Array of attachments
67 66
 	var $displayCharset;
68 67
 	var $composeID;
69 68
 	var $sessionData;
70 69
 
71 70
 	function __construct()
72 71
 	{
73
-		$this->displayCharset   = Api\Translation::charset();
72
+		$this->displayCharset = Api\Translation::charset();
74 73
 
75 74
 		$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'];
76
-		$this->mail_bo	= Mail::getInstance(true,$profileID);
75
+		$this->mail_bo = Mail::getInstance(true, $profileID);
77 76
 		$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->mail_bo->profileID;
78 77
 
79
-		$this->mailPreferences	=& $this->mail_bo->mailPreferences;
78
+		$this->mailPreferences = & $this->mail_bo->mailPreferences;
80 79
 		//force the default for the forwarding -> asmail
81 80
 		if (!is_array($this->mailPreferences) || empty($this->mailPreferences['message_forwarding']))
82 81
 		{
@@ -84,7 +83,7 @@  discard block
 block discarded – undo
84 83
 		}
85 84
 		if (is_null(Mail::$mailConfig)) Mail::$mailConfig = Api\Config::read('mail');
86 85
 
87
-		$this->mailPreferences  =& $this->mail_bo->mailPreferences;
86
+		$this->mailPreferences = & $this->mail_bo->mailPreferences;
88 87
 	}
89 88
 
90 89
 	/**
@@ -94,15 +93,15 @@  discard block
 block discarded – undo
94 93
 	 */
95 94
 	function changeProfile($_icServerID)
96 95
 	{
97
-		if ($this->mail_bo->profileID!=$_icServerID)
96
+		if ($this->mail_bo->profileID != $_icServerID)
98 97
 		{
99 98
 			if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.$this->mail_bo->profileID.'<->'.$_icServerID);
100
-			$this->mail_bo = Mail::getInstance(false,$_icServerID);
99
+			$this->mail_bo = Mail::getInstance(false, $_icServerID);
101 100
 			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$this->mail_bo->profileID.':'.function_backtrace());
102 101
 			// no icServer Object: something failed big time
103 102
 			if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
104 103
 			$this->mail_bo->openConnection($this->mail_bo->profileID);
105
-			$this->mailPreferences  =& $this->mail_bo->mailPreferences;
104
+			$this->mailPreferences = & $this->mail_bo->mailPreferences;
106 105
 		}
107 106
 	}
108 107
 
@@ -180,7 +179,7 @@  discard block
 block discarded – undo
180 179
 				'checkbox' => true,
181 180
 				'hint' => 'check to save as trackerentry on send',
182 181
 				'onExecute' => 'javaScript:app.mail.compose_setToggle',
183
-				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'),'tracker'),
182
+				'mail_import' => Api\Hooks::single(array('location' => 'mail_import'), 'tracker'),
184 183
 			),
185 184
 			'to_calendar' => array(
186 185
 				'caption' => 'Calendar',
@@ -205,7 +204,7 @@  discard block
 block discarded – undo
205 204
 				'children' => array(),
206 205
 				'hint' => 'Select the message priority tag',
207 206
 			),
208
-			'save2vfs' => array (
207
+			'save2vfs' => array(
209 208
 				'caption' => 'Save to filemanager',
210 209
 				'icon' => 'filesave',
211 210
 				'group' => ++$group,
@@ -242,7 +241,7 @@  discard block
 block discarded – undo
242 241
 		{
243 242
 			foreach (array_keys($actions) as $key)
244 243
 			{
245
-				if (!in_array($key, array('send','button[saveAsDraft]','uploadForCompose' ))) {
244
+				if (!in_array($key, array('send', 'button[saveAsDraft]', 'uploadForCompose'))) {
246 245
 					$actions[$key]['toolbarDefault'] = false;
247 246
 				}
248 247
 			}
@@ -266,7 +265,7 @@  discard block
 block discarded – undo
266 265
 	 * @var boolean $suppressSigOnTop =false
267 266
 	 * @var boolean $isReply =false
268 267
 	 */
269
-	function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false)
268
+	function compose(array $_content = null, $msg = null, $_focusElement = 'to', $suppressSigOnTop = false, $isReply = false)
270 269
 	{
271 270
 		if ($msg) Framework::message($msg);
272 271
 
@@ -287,14 +286,14 @@  discard block
 block discarded – undo
287 286
 		//lang('compose'),lang('from') // needed to be found by translationtools
288 287
 		//error_log(__METHOD__.__LINE__.array2string($_REQUEST).function_backtrace());
289 288
 		//error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace());
290
-		$_contentHasSigID = $_content?array_key_exists('mailidentity',(array)$_content):false;
291
-		$_contentHasMimeType = $_content? array_key_exists('mimeType',(array)$_content):false;
289
+		$_contentHasSigID = $_content ? array_key_exists('mailidentity', (array)$_content) : false;
290
+		$_contentHasMimeType = $_content ? array_key_exists('mimeType', (array)$_content) : false;
292 291
 		if (isset($_GET['reply_id'])) $replyID = $_GET['reply_id'];
293 292
 		if (!$replyID && isset($_GET['id'])) $replyID = $_GET['id'];
294 293
 
295 294
 		// Process different places we can use as a start for composing an email
296 295
 		$actionToProcess = 'compose';
297
-		if($_GET['from'] && $replyID)
296
+		if ($_GET['from'] && $replyID)
298 297
 		{
299 298
 			$_content = array_merge((array)$_content, $this->getComposeFrom(
300 299
 				// Parameters needed for fetching appropriate data
@@ -312,10 +311,10 @@  discard block
 block discarded – undo
312 311
 		}
313 312
 
314 313
 		$composeCache = array();
315
-		if (isset($_content['composeID'])&&!empty($_content['composeID']))
314
+		if (isset($_content['composeID']) && !empty($_content['composeID']))
316 315
 		{
317 316
 			$isFirstLoad = false;
318
-			$composeCache = Api\Cache::getCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$_content['composeID'],$callback=null,$callback_params=array(),$expiration=60*60*2);
317
+			$composeCache = Api\Cache::getCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$_content['composeID'], $callback = null, $callback_params = array(), $expiration = 60 * 60 * 2);
319 318
 			$this->composeID = $_content['composeID'];
320 319
 			//error_log(__METHOD__.__LINE__.array2string($composeCache));
321 320
 		}
@@ -325,7 +324,7 @@  discard block
 block discarded – undo
325 324
 			// respect that composeasnew may not want that, as we assume there
326 325
 			// is some style already set and our initalStyle always adds a span with &nbsp;
327 326
 			// and we want to avoid that
328
-			$isFirstLoad = !($actionToProcess=='composeasnew');//true;
327
+			$isFirstLoad = !($actionToProcess == 'composeasnew'); //true;
329 328
 			$this->composeID = $_content['composeID'] = $this->generateComposeID();
330 329
 			if (!is_array($_content))
331 330
 			{
@@ -360,7 +359,7 @@  discard block
 block discarded – undo
360 359
 				if (!isset($upload['file'])) $upload['file'] = $upload['tmp_name'];
361 360
 				try
362 361
 				{
363
-					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload,$this->composeID,false);
362
+					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload, $this->composeID, false);
364 363
 				}
365 364
 				catch (Api\Exception\WrongUserinput $e)
366 365
 				{
@@ -386,12 +385,12 @@  discard block
 block discarded – undo
386 385
 			unset($_content['attachments']['delete']);
387 386
 			$attachments = $_content['attachments'];
388 387
 			unset($_content['attachments']);
389
-			foreach($attachments as $i => $att)
388
+			foreach ($attachments as $i => $att)
390 389
 			{
391
-				$remove=false;
392
-				foreach(array_keys($toDelete) as $k)
390
+				$remove = false;
391
+				foreach (array_keys($toDelete) as $k)
393 392
 				{
394
-					if ($att['tmp_name']==$k) $remove=true;
393
+					if ($att['tmp_name'] == $k) $remove = true;
395 394
 				}
396 395
 				if (!$remove) $_content['attachments'][] = $att;
397 396
 			}
@@ -399,7 +398,7 @@  discard block
 block discarded – undo
399 398
 		// someone clicked something like send, or saveAsDraft
400 399
 		// make sure, we are connected to the correct server for sending and storing the send message
401 400
 		$activeProfile = $composeProfile = $this->mail_bo->profileID; // active profile may not be the profile uised in/for compose
402
-		$activeFolderCache = Api\Cache::getCache(Api\Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),$callback=null,$callback_params=array(),$expiration=60*60*10);
401
+		$activeFolderCache = Api\Cache::getCache(Api\Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 10);
403 402
 		if (!empty($activeFolderCache[$this->mail_bo->profileID]))
404 403
 		{
405 404
 			//error_log(__METHOD__.__LINE__.' CurrentFolder:'.$activeFolderCache[$this->mail_bo->profileID]);
@@ -407,7 +406,7 @@  discard block
 block discarded – undo
407 406
 		}
408 407
 		//error_log(__METHOD__.__LINE__.array2string($_content));
409 408
 		if (!empty($_content['serverID']) && $_content['serverID'] != $this->mail_bo->profileID &&
410
-			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft']||$_content['button']['saveAsDraftAndPrint'])
409
+			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft'] || $_content['button']['saveAsDraftAndPrint'])
411 410
 		)
412 411
 		{
413 412
 			$this->changeProfile($_content['serverID']);
@@ -421,19 +420,19 @@  discard block
 block discarded – undo
421 420
 		{
422 421
 			$buttonClicked = $suppressSigOnTop = true;
423 422
 			$sendOK = true;
424
-			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html'?'html':'plain').'text']);
423
+			$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
425 424
 			/*
426 425
 			perform some simple checks, before trying to send on:
427 426
 			$_content['to'];$_content['cc'];$_content['bcc'];
428 427
 			trim($_content['subject']);
429 428
 			trim(strip_tags(str_replace('&nbsp;','',$_content['body'])));
430 429
 			*/
431
-			if (strlen(trim(strip_tags(str_replace('&nbsp;','',$_content['body']))))==0 && count($_content['attachments'])==0)
430
+			if (strlen(trim(strip_tags(str_replace('&nbsp;', '', $_content['body'])))) == 0 && count($_content['attachments']) == 0)
432 431
 			{
433 432
 				$sendOK = false;
434 433
 				$_content['msg'] = $message = lang("no message body supplied");
435 434
 			}
436
-			if ($sendOK && strlen(trim($_content['subject']))==0)
435
+			if ($sendOK && strlen(trim($_content['subject'])) == 0)
437 436
 			{
438 437
 				$sendOK = false;
439 438
 				$_content['msg'] = $message = lang("no subject supplied");
@@ -448,15 +447,15 @@  discard block
 block discarded – undo
448 447
 				try
449 448
 				{
450 449
 					$success = $this->send($_content);
451
-					if ($success==false)
450
+					if ($success == false)
452 451
 					{
453
-						$sendOK=false;
452
+						$sendOK = false;
454 453
 						$message = $this->errorInfo;
455 454
 					}
456 455
 					if (!empty($_content['mailidentity']) && $_content['mailidentity'] != $sigPref[$this->mail_bo->profileID])
457 456
 					{
458
-						$sigPref[$this->mail_bo->profileID]=$_content['mailidentity'];
459
-						$GLOBALS['egw']->preferences->add('mail','LastSignatureIDUsed',$sigPref,'user');
457
+						$sigPref[$this->mail_bo->profileID] = $_content['mailidentity'];
458
+						$GLOBALS['egw']->preferences->add('mail', 'LastSignatureIDUsed', $sigPref, 'user');
460 459
 						// save prefs
461 460
 						$GLOBALS['egw']->preferences->save_repository(true);
462 461
 					}
@@ -480,23 +479,23 @@  discard block
 block discarded – undo
480 479
 				if (isset($_content['mode']) && !empty($_content['mode']))
481 480
 				{
482 481
 					$mode = $_content['mode'];
483
-					if ($_content['mode']=='forward' && !empty($_content['processedmail_id']))
482
+					if ($_content['mode'] == 'forward' && !empty($_content['processedmail_id']))
484 483
 					{
485
-						$_content['processedmail_id'] = explode(',',$_content['processedmail_id']);
484
+						$_content['processedmail_id'] = explode(',', $_content['processedmail_id']);
486 485
 						foreach ($_content['processedmail_id'] as $k =>$rowid)
487 486
 						{
488 487
 							$fhA = mail_ui::splitRowID($rowid);
489 488
 							//$this->sessionData['uid'][] = $fhA['msgUID'];
490 489
 							//$this->sessionData['forwardedUID'][] = $fhA['msgUID'];
491
-							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp=false);
490
+							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp = false);
492 491
 							if (!empty($fhA['folder'])) $workingFolder = $fhA['folder'];
493 492
 						}
494 493
 					}
495
-					if ($_content['mode']=='reply' && !empty($_content['processedmail_id']))
494
+					if ($_content['mode'] == 'reply' && !empty($_content['processedmail_id']))
496 495
 					{
497 496
 						$rhA = mail_ui::splitRowID($_content['processedmail_id']);
498 497
 						//$this->sessionData['uid'] = $rhA['msgUID'];
499
-						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
498
+						$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
500 499
 						$workingFolder = $rhA['folder'];
501 500
 					}
502 501
 				}
@@ -504,30 +503,30 @@  discard block
 block discarded – undo
504 503
 				if (empty($idsForRefresh) && !empty($_content['processedmail_id']))
505 504
 				{
506 505
 					$rhA = mail_ui::splitRowID($_content['processedmail_id']);
507
-					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp=false);
506
+					$idsForRefresh[] = mail_ui::generateRowID($rhA['profileID'], $rhA['folder'], $rhA['msgUID'], $_prependApp = false);
508 507
 				}
509 508
 				$response = Api\Json\Response::get();
510 509
 				if ($activeProfile != $composeProfile)
511 510
 				{
512 511
 					// we need a message only, when account ids (composeProfile vs. activeProfile) differ
513
-					$response->call('opener.egw_message',lang('Message send successfully.'));
512
+					$response->call('opener.egw_message', lang('Message send successfully.'));
514 513
 				}
515
-				elseif ($activeProfile == $composeProfile && ($workingFolder==$activeFolder && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder)))
514
+				elseif ($activeProfile == $composeProfile && ($workingFolder == $activeFolder && $mode != 'compose') || ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder)))
516 515
 				{
517
-					if ($this->mail_bo->isSentFolder($workingFolder)||$this->mail_bo->isDraftFolder($workingFolder))
516
+					if ($this->mail_bo->isSentFolder($workingFolder) || $this->mail_bo->isDraftFolder($workingFolder))
518 517
 					{
519 518
 						// we may need a refresh when on sent folder or in drafts, as drafted messages will/should be deleted after succeeded send action
520
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail');
519
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail');
521 520
 					}
522 521
 					else
523 522
 					{
524 523
 						//error_log(__METHOD__.__LINE__.array2string($idsForRefresh));
525
-						$response->call('opener.egw_refresh',lang('Message send successfully.'),'mail',$idsForRefresh,'update');
524
+						$response->call('opener.egw_refresh', lang('Message send successfully.'), 'mail', $idsForRefresh, 'update');
526 525
 					}
527 526
 				}
528 527
 				else
529 528
 				{
530
-					$response->call('opener.egw_message',lang('Message send successfully.'));
529
+					$response->call('opener.egw_message', lang('Message send successfully.'));
531 530
 				}
532 531
 				//egw_framework::refresh_opener(lang('Message send successfully.'),'mail');
533 532
 				Framework::window_close();
@@ -535,60 +534,60 @@  discard block
 block discarded – undo
535 534
 			if ($sendOK == false)
536 535
 			{
537 536
 				$response = Api\Json\Response::get();
538
-				Framework::message(lang('Message send failed: %1',$message),'error');// maybe error is more appropriate
537
+				Framework::message(lang('Message send failed: %1', $message), 'error'); // maybe error is more appropriate
539 538
 				$response->call('app.mail.clearIntevals');
540 539
 			}
541 540
 		}
542 541
 
543 542
 		if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile);
544 543
 		$insertSigOnTop = false;
545
-		$content = (is_array($_content)?$_content:array());
544
+		$content = (is_array($_content) ? $_content : array());
546 545
 		if ($_contentHasMimeType)
547 546
 		{
548 547
 			// mimeType is now a checkbox; convert it here to match expectations
549 548
 			// ToDo: match Code to meet checkbox value
550
-			if ($content['mimeType']==1)
549
+			if ($content['mimeType'] == 1)
551 550
 			{
552
-				$_content['mimeType'] = $content['mimeType']='html';
551
+				$_content['mimeType'] = $content['mimeType'] = 'html';
553 552
 			}
554 553
 			else
555 554
 			{
556
-				$_content['mimeType'] = $content['mimeType']='plain';
555
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
557 556
 			}
558 557
 
559 558
 		}
560 559
 		// user might have switched desired mimetype, so we should convert
561
-		if ($content['is_html'] && $content['mimeType']=='plain')
560
+		if ($content['is_html'] && $content['mimeType'] == 'plain')
562 561
 		{
563 562
 			//error_log(__METHOD__.__LINE__.$content['mail_htmltext']);
564 563
 			$suppressSigOnTop = true;
565
-			if (stripos($content['mail_htmltext'],'<pre>')!==false)
564
+			if (stripos($content['mail_htmltext'], '<pre>') !== false)
566 565
 			{
567 566
 				$contentArr = Api\Mail\Html::splithtmlByPRE($content['mail_htmltext']);
568 567
 				if (is_array($contentArr))
569 568
 				{
570 569
 					foreach ($contentArr as $k =>&$elem)
571 570
 					{
572
-						if (stripos($elem,'<pre>')!==false) $elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
571
+						if (stripos($elem, '<pre>') !== false) $elem = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $elem);
573 572
 					}
574
-					$content['mail_htmltext'] = implode('',$contentArr);
573
+					$content['mail_htmltext'] = implode('', $contentArr);
575 574
 				}
576 575
 			}
577 576
 			$content['mail_htmltext'] = $this->_getCleanHTML($content['mail_htmltext']);
578
-			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'],$charset=false,false,true);
577
+			$content['mail_htmltext'] = Api\Mail\Html::convertHTMLToText($content['mail_htmltext'], $charset = false, false, true);
579 578
 
580 579
 			$content['body'] = $content['mail_htmltext'];
581 580
 			unset($content['mail_htmltext']);
582 581
 			$content['is_html'] = false;
583 582
 			$content['is_plain'] = true;
584 583
 		}
585
-		if ($content['is_plain'] && $content['mimeType']=='html')
584
+		if ($content['is_plain'] && $content['mimeType'] == 'html')
586 585
 		{
587 586
 			// the possible font span should only be applied on first load or on switch plain->html
588 587
 			$isFirstLoad = "switchedplaintohtml";
589 588
 			//error_log(__METHOD__.__LINE__.$content['mail_plaintext']);
590 589
 			$suppressSigOnTop = true;
591
-			$content['mail_plaintext'] = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$content['mail_plaintext']);
590
+			$content['mail_plaintext'] = str_replace(array("\r\n", "\n", "\r"), array("<br>", "<br>", "<br>"), $content['mail_plaintext']);
592 591
 			//$this->replaceEmailAdresses($content['mail_plaintext']);
593 592
 			$content['body'] = $content['mail_plaintext'];
594 593
 			unset($content['mail_plaintext']);
@@ -596,7 +595,7 @@  discard block
 block discarded – undo
596 595
 			$content['is_plain'] = false;
597 596
 		}
598 597
 
599
-		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text']);
598
+		$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text']);
600 599
 		unset($_content['body']);
601 600
 		unset($_content['mail_htmltext']);
602 601
 		unset($_content['mail_plaintext']);
@@ -608,7 +607,7 @@  discard block
 block discarded – undo
608 607
 
609 608
 		// form was submitted either by clicking a button or by changing one of the triggering selectboxes
610 609
 		// identity and signatureid; this might trigger that the signature in mail body may have to be altered
611
-		if ( !empty($content['body']) &&
610
+		if (!empty($content['body']) &&
612 611
 			(!empty($composeCache['mailaccount']) && !empty($_content['mailaccount']) && $_content['mailaccount'] != $composeCache['mailaccount']) ||
613 612
 			(!empty($composeCache['mailidentity']) && !empty($_content['mailidentity']) && $_content['mailidentity'] != $composeCache['mailidentity'])
614 613
 		)
@@ -619,7 +618,7 @@  discard block
 block discarded – undo
619 618
 			{
620 619
 				$acc = Mail\Account::read($_content['mailaccount']);
621 620
 				//error_log(__METHOD__.__LINE__.array2string($acc));
622
-				$Identities = Mail\Account::read_identity($acc['ident_id'],true);
621
+				$Identities = Mail\Account::read_identity($acc['ident_id'], true);
623 622
 				//error_log(__METHOD__.__LINE__.array2string($Identities));
624 623
 				if ($Identities['ident_id'])
625 624
 				{
@@ -632,41 +631,41 @@  discard block
 block discarded – undo
632 631
 				}
633 632
 			}
634 633
 			$_oldSig = $composeCache['mailidentity'];
635
-			$_signatureid = ($newSig?$newSig:$_content['mailidentity']);
634
+			$_signatureid = ($newSig ? $newSig : $_content['mailidentity']);
636 635
 
637 636
 			if ($_oldSig != $_signatureid)
638 637
 			{
639
-				if($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
638
+				if ($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
640 639
 				// prepare signatures, the selected sig may be used on top of the body
641 640
 				try
642 641
 				{
643
-					$oldSignature = Mail\Account::read_identity($_oldSig,true);
642
+					$oldSignature = Mail\Account::read_identity($_oldSig, true);
644 643
 					//error_log(__METHOD__.__LINE__.'Old:'.array2string($oldSignature).'#');
645 644
 					$oldSigText = $oldSignature['ident_signature'];
646 645
 				}
647 646
 				catch (Exception $e)
648 647
 				{
649
-					$oldSignature=array();
648
+					$oldSignature = array();
650 649
 					$oldSigText = null;
651 650
 				}
652 651
 				try
653 652
 				{
654
-					$signature = Mail\Account::read_identity($_signatureid,true);
653
+					$signature = Mail\Account::read_identity($_signatureid, true);
655 654
 					//error_log(__METHOD__.__LINE__.'New:'.array2string($signature).'#');
656 655
 					$sigText = $signature['ident_signature'];
657 656
 				}
658 657
 				catch (Exception $e)
659 658
 				{
660
-					$signature=array();
659
+					$signature = array();
661 660
 					$sigText = null;
662 661
 				}
663 662
 				//error_log(__METHOD__.'Old:'.$oldSigText.'#');
664 663
 				//error_log(__METHOD__.'New:'.$sigText.'#');
665 664
 				if ($_currentMode == 'plain')
666 665
 				{
667
-					$oldSigText = $this->convertHTMLToText($oldSigText,true,true);
668
-					$sigText = $this->convertHTMLToText($sigText,true,true);
669
-					if($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
666
+					$oldSigText = $this->convertHTMLToText($oldSigText, true, true);
667
+					$sigText = $this->convertHTMLToText($sigText, true, true);
668
+					if ($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
670 669
 				}
671 670
 
672 671
 				//$oldSigText = Mail::merge($oldSigText,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
@@ -680,9 +679,9 @@  discard block
 block discarded – undo
680 679
 				//error_log(__METHOD__.'Old(clean):'.$oldSigTextCleaned.'#');
681 680
 				if ($_currentMode == 'html')
682 681
 				{
683
-					$content['body'] = str_replace("\n",'\n',$content['body']);	// dont know why, but \n screws up preg_replace
682
+					$content['body'] = str_replace("\n", '\n', $content['body']); // dont know why, but \n screws up preg_replace
684 683
 					$styles = Mail::getStyles(array(array('body'=>$content['body'])));
685
-					if (stripos($content['body'],'style')!==false) Api\Mail\Html::replaceTagsCompletley($content['body'],'style',$endtag='',true); // clean out empty or pagewide style definitions / left over tags
684
+					if (stripos($content['body'], 'style') !== false) Api\Mail\Html::replaceTagsCompletley($content['body'], 'style', $endtag = '', true); // clean out empty or pagewide style definitions / left over tags
686 685
 				}
687 686
 				$content['body'] = str_replace(array("\r", "\t", "<br />\n", ": "), array("", "", "<br />", ":"),
688 687
 					$_currentMode == 'html' ? Api\Html::purify($content['body'], Mail::$htmLawed_config, array(), true) : $content['body']);
@@ -690,9 +689,9 @@  discard block
 block discarded – undo
690 689
 				if ($_currentMode == 'html')
691 690
 				{
692 691
 					$replaced = null;
693
-					$content['body'] = preg_replace($reg='|'.preg_quote('<!-- HTMLSIGBEGIN -->','|').'.*'.preg_quote('<!-- HTMLSIGEND -->','|').'|u',
694
-						$rep='<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in=$content['body'], -1, $replaced);
695
-					$content['body'] = str_replace(array('\n',"\xe2\x80\x93","\xe2\x80\x94","\xe2\x82\xac"),array("\n",'&ndash;','&mdash;','&euro;'),$content['body']);
692
+					$content['body'] = preg_replace($reg = '|'.preg_quote('<!-- HTMLSIGBEGIN -->', '|').'.*'.preg_quote('<!-- HTMLSIGEND -->', '|').'|u',
693
+						$rep = '<!-- HTMLSIGBEGIN -->'.$sigText.'<!-- HTMLSIGEND -->', $in = $content['body'], -1, $replaced);
694
+					$content['body'] = str_replace(array('\n', "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x82\xac"), array("\n", '&ndash;', '&mdash;', '&euro;'), $content['body']);
696 695
 					//error_log(__METHOD__."() preg_replace('$reg', '$rep', '$in', -1)='".$content['body']."', replaced=$replaced");
697 696
 					unset($rep, $in);
698 697
 					if ($replaced)
@@ -703,32 +702,32 @@  discard block
 block discarded – undo
703 702
 					else
704 703
 					{
705 704
 						// try the old way
706
-						$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
705
+						$found = (strlen(trim($oldSigTextCleaned)) > 0 ? strpos($content['body'], trim($oldSigTextCleaned)) : false);
707 706
 					}
708 707
 				}
709 708
 				else
710 709
 				{
711
-					$found = (strlen(trim($oldSigTextCleaned))>0?strpos($content['body'],trim($oldSigTextCleaned)):false);
710
+					$found = (strlen(trim($oldSigTextCleaned)) > 0 ? strpos($content['body'], trim($oldSigTextCleaned)) : false);
712 711
 				}
713 712
 
714
-				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
713
+				if ($found !== false && $_oldSig != -2 && !(empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
715 714
 				{
716 715
 					//error_log(__METHOD__.'Old Content:'.$content['body'].'#');
717
-					$_oldSigText = preg_quote($oldSigTextCleaned,'~');
716
+					$_oldSigText = preg_quote($oldSigTextCleaned, '~');
718 717
 					//error_log(__METHOD__.'Old(masked):'.$_oldSigText.'#');
719
-					$content['body'] = preg_replace('~'.$_oldSigText.'~mi',$sigText,$content['body'],1);
718
+					$content['body'] = preg_replace('~'.$_oldSigText.'~mi', $sigText, $content['body'], 1);
720 719
 					//error_log(__METHOD__.'new Content:'.$content['body'].'#');
721 720
 				}
722 721
 
723
-				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned,true,true)) ==''))
722
+				if ($_oldSig == -2 && (empty($oldSigTextCleaned) || trim($this->convertHTMLToText($oldSigTextCleaned, true, true)) == ''))
724 723
 				{
725 724
 					// if there is no sig selected, there is no way to replace a signature
726 725
 				}
727 726
 
728 727
 				if ($found === false)
729 728
 				{
730
-					if($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
731
-					if($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
729
+					if ($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
730
+					if ($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
732 731
 				}
733 732
 				else
734 733
 				{
@@ -750,7 +749,7 @@  discard block
 block discarded – undo
750 749
 		if ($isFirstLoad)
751 750
 		{
752 751
 			$alwaysAttachVCardAtCompose = false; // we use this to eliminate double attachments, if users VCard is already present/attached
753
-			if ( isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
752
+			if (isset($GLOBALS['egw_info']['apps']['stylite']) && (isset($this->mailPreferences['attachVCardAtCompose']) &&
754 753
 				$this->mailPreferences['attachVCardAtCompose']))
755 754
 			{
756 755
 				$alwaysAttachVCardAtCompose = true;
@@ -759,7 +758,7 @@  discard block
 block discarded – undo
759 758
 					$f = $_REQUEST['preset']['file'];
760 759
 					$_REQUEST['preset']['file'] = array($f);
761 760
 				}
762
-				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')."/.entry";
761
+				$_REQUEST['preset']['file'][] = "vfs://default/apps/addressbook/".$GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')."/.entry";
763 762
 			}
764 763
 			// an app passed the request for fetching and mailing an entry
765 764
 			if (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id']))
@@ -768,33 +767,33 @@  discard block
 block discarded – undo
768 767
 				$mt = $_REQUEST['method'];
769 768
 				$id = $_REQUEST['id'];
770 769
 				// passed method MUST be registered
771
-				$method = Link::get_registry($app,$mt);
770
+				$method = Link::get_registry($app, $mt);
772 771
 				//error_log(__METHOD__.__LINE__.array2string($method));
773 772
 				if ($method)
774 773
 				{
775
-					$res = ExecMethod($method,array($id,'html'));
774
+					$res = ExecMethod($method, array($id, 'html'));
776 775
 					//error_log(__METHOD__.__LINE__.array2string($res));
777 776
 					if (!empty($res))
778 777
 					{
779 778
 						$insertSigOnTop = 'below';
780 779
 						if (isset($res['attachments']) && is_array($res['attachments']))
781 780
 						{
782
-							foreach($res['attachments'] as $f)
781
+							foreach ($res['attachments'] as $f)
783 782
 							{
784 783
 								$_REQUEST['preset']['file'][] = $f;
785 784
 							}
786 785
 						}
787 786
 						$content['subject'] = lang($app).' #'.$res['id'].': ';
788
-						foreach(array('subject','body','mimetype') as $name) {
787
+						foreach (array('subject', 'body', 'mimetype') as $name) {
789 788
 							$sName = $name;
790
-							if ($name=='mimetype'&&$res[$name])
789
+							if ($name == 'mimetype' && $res[$name])
791 790
 							{
792 791
 								$sName = 'mimeType';
793 792
 								$content[$sName] = $res[$name];
794 793
 							}
795 794
 							else
796 795
 							{
797
-								if ($res[$name]) $content[$sName] .= (strlen($content[$sName])>0 ? ' ':'') .$res[$name];
796
+								if ($res[$name]) $content[$sName] .= (strlen($content[$sName]) > 0 ? ' ' : '').$res[$name];
798 797
 							}
799 798
 						}
800 799
 					}
@@ -803,45 +802,45 @@  discard block
 block discarded – undo
803 802
 			// handle preset info/values
804 803
 			if (is_array($_REQUEST['preset']))
805 804
 			{
806
-				$alreadyProcessed=array();
805
+				$alreadyProcessed = array();
807 806
 				//_debug_array($_REQUEST);
808 807
 				if ($_REQUEST['preset']['mailto']) {
809 808
 					// handle mailto strings such as
810 809
 					// mailto:larry,dan?cc=mike&bcc=sue&subject=test&body=type+your&body=message+here
811 810
 					// the above string may be htmlentyty encoded, then multiple body tags are supported
812 811
 					// first, strip the mailto: string out of the mailto URL
813
-					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'],'mailto')===false?$_REQUEST['preset']['mailto']:trim(substr(html_entity_decode($_REQUEST['preset']['mailto']),7)));
812
+					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'], 'mailto') === false ? $_REQUEST['preset']['mailto'] : trim(substr(html_entity_decode($_REQUEST['preset']['mailto']), 7)));
814 813
 					// check if there is more than the to address
815
-					$mailtoArray = explode('?',$tmp_send_to,2);
814
+					$mailtoArray = explode('?', $tmp_send_to, 2);
816 815
 					if ($mailtoArray[1]) {
817 816
 						// check if there are more than one requests
818
-						$addRequests = explode('&',$mailtoArray[1]);
817
+						$addRequests = explode('&', $mailtoArray[1]);
819 818
 						foreach ($addRequests as $key => $reqval) {
820 819
 							// the additional requests should have a =, to separate key from value.
821
-							$keyValuePair = explode('=',$reqval,2);
822
-							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]])>0 ? ' ':'') . $keyValuePair[1];
820
+							$keyValuePair = explode('=', $reqval, 2);
821
+							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]]) > 0 ? ' ' : '').$keyValuePair[1];
823 822
 						}
824 823
 					}
825
-					$content['to']=$mailtoArray[0];
826
-					$alreadyProcessed['to']='to';
824
+					$content['to'] = $mailtoArray[0];
825
+					$alreadyProcessed['to'] = 'to';
827 826
 					// if the mailto string is not htmlentity decoded the arguments are passed as simple requests
828
-					foreach(array('cc','bcc','subject','body') as $name) {
829
-						$alreadyProcessed[$name]=$name;
830
-						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name])>0 ? ( $name == 'cc' || $name == 'bcc' ? ',' : ' ') : '') . $_REQUEST[$name];
827
+					foreach (array('cc', 'bcc', 'subject', 'body') as $name) {
828
+						$alreadyProcessed[$name] = $name;
829
+						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name]) > 0 ? ($name == 'cc' || $name == 'bcc' ? ',' : ' ') : '').$_REQUEST[$name];
831 830
 					}
832 831
 				}
833 832
 
834 833
 				if ($_REQUEST['preset']['mailtocontactbyid']) {
835 834
 					if ($GLOBALS['egw_info']['user']['apps']['addressbook']) {
836 835
 						$contacts_obj = new Api\Contacts();
837
-						$addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
838
-						if (method_exists($contacts_obj,'search')) {
836
+						$addressbookprefs = & $GLOBALS['egw_info']['user']['preferences']['addressbook'];
837
+						if (method_exists($contacts_obj, 'search')) {
839 838
 
840
-							$addressArray = explode(',',$_REQUEST['preset']['mailtocontactbyid']);
839
+							$addressArray = explode(',', $_REQUEST['preset']['mailtocontactbyid']);
841 840
 							foreach ((array)$addressArray as $id => $addressID)
842 841
 							{
843
-								$addressID = (int) $addressID;
844
-								if (!($addressID>0))
842
+								$addressID = (int)$addressID;
843
+								if (!($addressID > 0))
845 844
 								{
846 845
 									unset($addressArray[$id]);
847 846
 								}
@@ -850,44 +849,44 @@  discard block
 block discarded – undo
850 849
 							{
851 850
 								$_searchCond = array('contact_id'=>$addressArray);
852 851
 								//error_log(__METHOD__.__LINE__.$_searchString);
853
-								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $showAccounts=false;
854
-								$filter = ($showAccounts?array():array('account_id' => null));
855
-								$filter['cols_to_search']=array('n_fn','email','email_home');
856
-								$contacts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter);
852
+								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $showAccounts = false;
853
+								$filter = ($showAccounts ? array() : array('account_id' => null));
854
+								$filter['cols_to_search'] = array('n_fn', 'email', 'email_home');
855
+								$contacts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
857 856
 								// additionally search the accounts, if the contact storage is not the account storage
858 857
 								if ($showAccounts &&
859 858
 									$GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
860 859
 									$GLOBALS['egw_info']['server']['contact_repository'] == 'sql')
861 860
 								{
862
-									$accounts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),array('owner' => 0));
861
+									$accounts = $contacts_obj->search($_searchCond, array('n_fn', 'email', 'email_home'), 'n_fn', '', '%', false, 'OR', array(0, 100), array('owner' => 0));
863 862
 
864 863
 									if ($contacts && $accounts)
865 864
 									{
866
-										$contacts = array_merge($contacts,$accounts);
867
-										usort($contacts,create_function('$a,$b','return strcasecmp($a["n_fn"],$b["n_fn"]);'));
865
+										$contacts = array_merge($contacts, $accounts);
866
+										usort($contacts, create_function('$a,$b', 'return strcasecmp($a["n_fn"],$b["n_fn"]);'));
868 867
 									}
869
-									elseif($accounts)
868
+									elseif ($accounts)
870 869
 									{
871
-										$contacts =& $accounts;
870
+										$contacts = & $accounts;
872 871
 									}
873 872
 									unset($accounts);
874 873
 								}
875 874
 							}
876
-							if(is_array($contacts)) {
875
+							if (is_array($contacts)) {
877 876
 								$mailtoArray = array();
878 877
 								$primary = $addressbookprefs['distributionListPreferredMail'];
879 878
 								if ($primary != 'email' && $primary != 'email_home') $primary = 'email';
880
-								$secondary = ($primary == 'email'?'email_home':'email');
879
+								$secondary = ($primary == 'email' ? 'email_home' : 'email');
881 880
 								//error_log(__METHOD__.__LINE__.array2string($contacts));
882
-								foreach($contacts as $contact) {
883
-									$innerCounter=0;
884
-									foreach(array($contact[$primary],$contact[$secondary]) as $email) {
881
+								foreach ($contacts as $contact) {
882
+									$innerCounter = 0;
883
+									foreach (array($contact[$primary], $contact[$secondary]) as $email) {
885 884
 										// use pref distributionListPreferredMail for the primary address
886 885
 										// avoid wrong addresses, if an rfc822 encoded address is in addressbook
887
-										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
888
-										$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
889
-										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>');
890
-										if($innerCounter==0 && !empty($email) && in_array($completeMailString ,$mailtoArray) === false) {
886
+										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/", '$2', $email);
887
+										$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
888
+										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']).' <'.trim($email).'>');
889
+										if ($innerCounter == 0 && !empty($email) && in_array($completeMailString, $mailtoArray) === false) {
891 890
 											$i++;
892 891
 											$innerCounter++;
893 892
 											$mailtoArray[$i] = $completeMailString;
@@ -896,8 +895,8 @@  discard block
 block discarded – undo
896 895
 								}
897 896
 							}
898 897
 							//error_log(__METHOD__.__LINE__.array2string($mailtoArray));
899
-							$alreadyProcessed['to']='to';
900
-							$content['to']=$mailtoArray;
898
+							$alreadyProcessed['to'] = 'to';
899
+							$content['to'] = $mailtoArray;
901 900
 						}
902 901
 					}
903 902
 				}
@@ -912,20 +911,20 @@  discard block
 block discarded – undo
912 911
 					$types = (array)$_REQUEST['preset']['type'];
913 912
 					//if (!empty($types) && in_array('text/calendar; method=request',$types))
914 913
 					$files = (array)$_REQUEST['preset']['file'];
915
-					foreach($files as $k => $path)
914
+					foreach ($files as $k => $path)
916 915
 					{
917
-						if (!empty($types[$k]) && stripos($types[$k],'text/calendar')!==false)
916
+						if (!empty($types[$k]) && stripos($types[$k], 'text/calendar') !== false)
918 917
 						{
919 918
 							$insertSigOnTop = 'below';
920 919
 						}
921 920
 						//error_log(__METHOD__.__LINE__.$path.'->'.array2string(parse_url($path,PHP_URL_SCHEME == 'vfs')));
922
-						if (parse_url($path,PHP_URL_SCHEME == 'vfs'))
921
+						if (parse_url($path, PHP_URL_SCHEME == 'vfs'))
923 922
 						{
924 923
 							//Vfs::load_wrapper('vfs');
925 924
 							$type = Vfs::mime_content_type($path);
926 925
 							// special handling for attaching vCard of iCal --> use their link-title as name
927
-							if (substr($path,-7) != '/.entry' ||
928
-								!(list($app,$id) = array_slice(explode('/',$path),-3)) ||
926
+							if (substr($path, -7) != '/.entry' ||
927
+								!(list($app, $id) = array_slice(explode('/', $path), -3)) ||
929 928
 								!($name = Link::title($app, $id)))
930 929
 							{
931 930
 								$name = Vfs::decodePath(Vfs::basename($path));
@@ -939,7 +938,7 @@  discard block
 block discarded – undo
939 938
 							{
940 939
 								$type = $types[$k];
941 940
 							}
942
-							$path = str_replace('+','%2B',$path);
941
+							$path = str_replace('+', '%2B', $path);
943 942
 							$formData = array(
944 943
 								'name' => $name,
945 944
 								'type' => $type,
@@ -952,7 +951,7 @@  discard block
 block discarded – undo
952 951
 								Framework::message(lang('Directories have to be shared.'), 'info');
953 952
 							}
954 953
 						}
955
-						elseif(is_readable($path))
954
+						elseif (is_readable($path))
956 955
 						{
957 956
 							$formData = array(
958 957
 								'name' => isset($names[$k]) ? $names[$k] : basename($path),
@@ -965,28 +964,28 @@  discard block
 block discarded – undo
965 964
 						{
966 965
 							continue;
967 966
 						}
968
-						$this->addAttachment($formData,$content,($alwaysAttachVCardAtCompose?true:false));
967
+						$this->addAttachment($formData, $content, ($alwaysAttachVCardAtCompose ? true : false));
969 968
 					}
970 969
 					$remember = array();
971 970
 					if (isset($_REQUEST['preset']['mailto']) || (isset($_REQUEST['app']) && isset($_REQUEST['method']) && isset($_REQUEST['id'])))
972 971
 					{
973
-						foreach(array_keys($content) as $k)
972
+						foreach (array_keys($content) as $k)
974 973
 						{
975
-							if (in_array($k,array('to','cc','bcc','subject','body','mimeType'))&&isset($this->sessionData[$k]))
974
+							if (in_array($k, array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType')) && isset($this->sessionData[$k]))
976 975
 							{
977
-								$alreadyProcessed[$k]=$k;
976
+								$alreadyProcessed[$k] = $k;
978 977
 								$remember[$k] = $this->sessionData[$k];
979 978
 							}
980 979
 						}
981 980
 					}
982
-					if(!empty($remember)) $content = array_merge($content,$remember);
981
+					if (!empty($remember)) $content = array_merge($content, $remember);
983 982
 				}
984
-				foreach(array('to','cc','bcc','subject','body','mimeType') as $name)
983
+				foreach (array('to', 'cc', 'bcc', 'subject', 'body', 'mimeType') as $name)
985 984
 				{
986 985
 					//always handle mimeType
987
-					if ($name=='mimeType' && $_REQUEST['preset'][$name])
986
+					if ($name == 'mimeType' && $_REQUEST['preset'][$name])
988 987
 					{
989
-						$_content[$name]=$content[$name]=$_REQUEST['preset'][$name];
988
+						$_content[$name] = $content[$name] = $_REQUEST['preset'][$name];
990 989
 					}
991 990
 					//skip if already processed by "preset Routines"
992 991
 					if ($alreadyProcessed[$name]) continue;
@@ -999,36 +998,36 @@  discard block
 block discarded – undo
999 998
 			{
1000 999
 				$content['to'] = base64_decode($_REQUEST['send_to']);
1001 1000
 				// first check if there is a questionmark or ampersand
1002
-				if (strpos($content['to'],'?')!== false) list($content['to'],$rest) = explode('?',$content['to'],2);
1001
+				if (strpos($content['to'], '?') !== false) list($content['to'], $rest) = explode('?', $content['to'], 2);
1003 1002
 				$content['to'] = html_entity_decode($content['to']);
1004
-				if (($at_pos = strpos($content['to'],'@')) !== false)
1003
+				if (($at_pos = strpos($content['to'], '@')) !== false)
1005 1004
 				{
1006
-					if (($amp_pos = strpos(substr($content['to'],$at_pos),'&')) !== false)
1005
+					if (($amp_pos = strpos(substr($content['to'], $at_pos), '&')) !== false)
1007 1006
 					{
1008 1007
 						//list($email,$addoptions) = explode('&',$value,2);
1009
-						$email = substr($content['to'],0,$amp_pos+$at_pos);
1010
-						$rest = substr($content['to'], $amp_pos+$at_pos+1);
1008
+						$email = substr($content['to'], 0, $amp_pos + $at_pos);
1009
+						$rest = substr($content['to'], $amp_pos + $at_pos + 1);
1011 1010
 						//error_log(__METHOD__.__LINE__.$email.' '.$rest);
1012 1011
 						$content['to'] = $email;
1013 1012
 					}
1014 1013
 				}
1015
-				if (strpos($content['to'],'%40')!== false) $content['to'] = Api\Html::purify(str_replace('%40','@',$content['to']));
1014
+				if (strpos($content['to'], '%40') !== false) $content['to'] = Api\Html::purify(str_replace('%40', '@', $content['to']));
1016 1015
 				$rarr = array(Api\Html::purify($rest));
1017
-				if (isset($rest)&&!empty($rest) && strpos($rest,'&')!== false) $rarr = explode('&',$rest);
1016
+				if (isset($rest) && !empty($rest) && strpos($rest, '&') !== false) $rarr = explode('&', $rest);
1018 1017
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($rarr));
1019 1018
 				$karr = array();
1020 1019
 				foreach ($rarr as &$rval)
1021 1020
 				{
1022 1021
 					//must contain =
1023
-					if (strpos($rval,'=')!== false)
1022
+					if (strpos($rval, '=') !== false)
1024 1023
 					{
1025
-						list($k,$v) = explode('=',$rval,2);
1024
+						list($k, $v) = explode('=', $rval, 2);
1026 1025
 						$karr[$k] = (string)$v;
1027
-						unset($k,$v);
1026
+						unset($k, $v);
1028 1027
 					}
1029 1028
 				}
1030 1029
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($karr));
1031
-				foreach(array('cc','bcc','subject','body') as $name)
1030
+				foreach (array('cc', 'bcc', 'subject', 'body') as $name)
1032 1031
 				{
1033 1032
 					if ($karr[$name]) $content[$name] = $karr[$name];
1034 1033
 				}
@@ -1040,17 +1039,17 @@  discard block
 block discarded – undo
1040 1039
 		if ($isFirstLoad && !empty($_REQUEST['mimeType']))
1041 1040
 		{
1042 1041
 			$_content['mimeType'] = $content['mimeType'];
1043
-			if (($_REQUEST['mimeType']=="text" ||$_REQUEST['mimeType']=="plain") && $content['mimeType'] == 'html')
1042
+			if (($_REQUEST['mimeType'] == "text" || $_REQUEST['mimeType'] == "plain") && $content['mimeType'] == 'html')
1044 1043
 			{
1045
-				$_content['mimeType'] = $content['mimeType']  = 'plain';
1046
-				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1044
+				$_content['mimeType'] = $content['mimeType'] = 'plain';
1045
+				$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1047 1046
 			}
1048
-			if ($_REQUEST['mimeType']=="html" && $content['mimeType'] != 'html')
1047
+			if ($_REQUEST['mimeType'] == "html" && $content['mimeType'] != 'html')
1049 1048
 			{
1050
-				$_content['mimeType'] = $content['mimeType']  = 'html';
1049
+				$_content['mimeType'] = $content['mimeType'] = 'html';
1051 1050
 				$content['body'] = "<pre>".$content['body']."</pre>";
1052 1051
 				// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1053
-				if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1052
+				if (strpos($content['body'], "<pre> \r\n \r\n---") === 0) $content['body'] = substr_replace($content['body'], " <br>\r\n<pre>---", 0, strlen("<pre> \r\n \r\n---") - 1);
1054 1053
 			}
1055 1054
 		}
1056 1055
 		else
@@ -1058,24 +1057,24 @@  discard block
 block discarded – undo
1058 1057
 			// try to enforce a mimeType on reply ( if type is not of the wanted type )
1059 1058
 			if ($isReply)
1060 1059
 			{
1061
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="text" &&
1060
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "text" &&
1062 1061
 					$content['mimeType'] == 'html')
1063 1062
 				{
1064
-					$_content['mimeType'] = $content['mimeType']  = 'plain';
1065
-					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r","\n"),' ',$content['body']));
1063
+					$_content['mimeType'] = $content['mimeType'] = 'plain';
1064
+					$content['body'] = $this->convertHTMLToText(str_replace(array("\n\r", "\n"), ' ', $content['body']));
1066 1065
 				}
1067
-				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions']=="html" &&
1066
+				if (!empty($this->mailPreferences['replyOptions']) && $this->mailPreferences['replyOptions'] == "html" &&
1068 1067
 					$content['mimeType'] != 'html')
1069 1068
 				{
1070
-					$_content['mimeType'] = $content['mimeType']  = 'html';
1069
+					$_content['mimeType'] = $content['mimeType'] = 'html';
1071 1070
 					$content['body'] = "<pre>".$content['body']."</pre>";
1072 1071
 					// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1073
-					if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1072
+					if (strpos($content['body'], "<pre> \r\n \r\n---") === 0) $content['body'] = substr_replace($content['body'], " <br>\r\n<pre>---", 0, strlen("<pre> \r\n \r\n---") - 1);
1074 1073
 				}
1075 1074
 			}
1076 1075
 		}
1077 1076
 
1078
-		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible()===false)
1077
+		if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible() === false)
1079 1078
 		{
1080 1079
 			$_content['mimeType'] = $content['mimeType'] = 'plain';
1081 1080
 			$content['body'] = $this->convertHTMLToText($content['body']);
@@ -1094,36 +1093,36 @@  discard block
 block discarded – undo
1094 1093
 		//_debug_array(($presetSig ? $presetSig : $content['mailidentity']));
1095 1094
 		try
1096 1095
 		{
1097
-			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig,true);
1096
+			$signature = Mail\Account::read_identity($content['mailidentity'] ? $content['mailidentity'] : $presetSig, true);
1098 1097
 		}
1099 1098
 		catch (Exception $e)
1100 1099
 		{
1101 1100
 			//PROBABLY NOT FOUND
1102
-			$signature=array();
1101
+			$signature = array();
1103 1102
 		}
1104 1103
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
1105 1104
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
1106
-			empty($signature['ident_signature']) || trim($this->convertHTMLToText($signature['ident_signature'],true,true)) =='')
1105
+			empty($signature['ident_signature']) || trim($this->convertHTMLToText($signature['ident_signature'], true, true)) == '')
1107 1106
 		{
1108 1107
 			$disableRuler = true;
1109 1108
 		}
1110 1109
 		$font_span = $font_part = '';
1111
-		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1110
+		if ($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1112 1111
 			// User preferences for style
1113 1112
 			$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
1114 1113
 			$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
1115
-			$font_part = '<span style="width:100%; display: inline; '.($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'">';
1114
+			$font_part = '<span style="width:100%; display: inline; '.($font ? 'font-family:'.$font.'; ' : '').($font_size ? 'font-size:'.$font_size.'; ' : '').'">';
1116 1115
 			$font_span = $font_part.'&#8203;</span>';
1117 1116
 			if (empty($font) && empty($font_size)) $font_span = '';
1118 1117
 		}
1119 1118
 		// the font span should only be applied on first load or on switch plain->html and the absence of the font_part of the span
1120
-		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false) $font_span = '';
1119
+		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'], $font_part) === false) $font_span = '';
1121 1120
 		//remove possible html header stuff
1122
-		if (stripos($content['body'],'<html><head></head><body>')!==false) $content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1121
+		if (stripos($content['body'], '<html><head></head><body>') !== false) $content['body'] = str_ireplace(array('<html><head></head><body>', '</body></html>'), array('', ''), $content['body']);
1123 1122
 		//error_log(__METHOD__.__LINE__.array2string($this->mailPreferences));
1124
-		$blockElements = array('address','blockquote','center','del','dir','div','dl','fieldset','form','h1','h2','h3','h4','h5','h6','hr','ins','isindex','menu','noframes','noscript','ol','p','pre','table','ul');
1125
-		if ($this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend' &&
1126
-			!(isset($_POST['mySigID']) && !empty($_POST['mySigID']) ) && !$suppressSigOnTop
1123
+		$blockElements = array('address', 'blockquote', 'center', 'del', 'dir', 'div', 'dl', 'fieldset', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ins', 'isindex', 'menu', 'noframes', 'noscript', 'ol', 'p', 'pre', 'table', 'ul');
1124
+		if ($this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' &&
1125
+			!(isset($_POST['mySigID']) && !empty($_POST['mySigID'])) && !$suppressSigOnTop
1127 1126
 		)
1128 1127
 		{
1129 1128
 			// ON tOP OR BELOW? pREF CAN TELL
@@ -1133,57 +1132,57 @@  discard block
 block discarded – undo
1133 1132
 						'1' => 'before reply, visible during compose',
1134 1133
 						'no_belowaftersend'  => 'appended after reply before sending',
1135 1134
 			*/
1136
-			$insertSigOnTop = ($insertSigOnTop?$insertSigOnTop:($this->mailPreferences['insertSignatureAtTopOfMessage']?$this->mailPreferences['insertSignatureAtTopOfMessage']:'below'));
1137
-			$sigText = Mail::merge($signature['ident_signature'],array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
1135
+			$insertSigOnTop = ($insertSigOnTop ? $insertSigOnTop : ($this->mailPreferences['insertSignatureAtTopOfMessage'] ? $this->mailPreferences['insertSignatureAtTopOfMessage'] : 'below'));
1136
+			$sigText = Mail::merge($signature['ident_signature'], array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
1138 1137
 			if ($content['mimeType'] == 'html')
1139 1138
 			{
1140
-				$sigTextStartsWithBlockElement = ($disableRuler?false:true);
1141
-				foreach($blockElements as $e)
1139
+				$sigTextStartsWithBlockElement = ($disableRuler ? false : true);
1140
+				foreach ($blockElements as $e)
1142 1141
 				{
1143 1142
 					if ($sigTextStartsWithBlockElement) break;
1144
-					if (stripos(trim($sigText),'<'.$e)===0) $sigTextStartsWithBlockElement = true;
1143
+					if (stripos(trim($sigText), '<'.$e) === 0) $sigTextStartsWithBlockElement = true;
1145 1144
 				}
1146 1145
 			}
1147
-			if($content['mimeType'] == 'html') {
1146
+			if ($content['mimeType'] == 'html') {
1148 1147
 				$before = $disableRuler ? '' : '<hr style="border:1px dotted silver; width:100%;">';
1149 1148
 				$inbetween = '';
1150 1149
 			} else {
1151
-				$before = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
1150
+				$before = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
1152 1151
 				$inbetween = "\r\n";
1153 1152
 			}
1154 1153
 			if ($content['mimeType'] == 'html')
1155 1154
 			{
1156
-				$sigText = ($sigTextStartsWithBlockElement?'':"<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement?'':"</div>");
1155
+				$sigText = ($sigTextStartsWithBlockElement ? '' : "<div>")."<!-- HTMLSIGBEGIN -->".$sigText."<!-- HTMLSIGEND -->".($sigTextStartsWithBlockElement ? '' : "</div>");
1157 1156
 			}
1158 1157
 
1159 1158
 			if ($insertSigOnTop === 'below')
1160 1159
 			{
1161
-				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true));
1160
+				$content['body'] = $font_span.$content['body'].$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true));
1162 1161
 			}
1163 1162
 			else
1164 1163
 			{
1165
-				$content['body'] = $font_span.$before.($content['mimeType'] == 'html'?$sigText:$this->convertHTMLToText($sigText,true,true)).$inbetween.$content['body'];
1164
+				$content['body'] = $font_span.$before.($content['mimeType'] == 'html' ? $sigText : $this->convertHTMLToText($sigText, true, true)).$inbetween.$content['body'];
1166 1165
 			}
1167 1166
 		}
1168 1167
 		else
1169 1168
 		{
1170
-			$content['body'] = ($font_span?($isFirstLoad === "switchedplaintohtml"?$font_part:$font_span):/*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml"?"</span>":"");
1169
+			$content['body'] = ($font_span ? ($isFirstLoad === "switchedplaintohtml" ? $font_part : $font_span) : /*($content['mimeType'] == 'html'?'&nbsp;':'')*/'').$content['body'].($isFirstLoad === "switchedplaintohtml" ? "</span>" : "");
1171 1170
 		}
1172 1171
 		//error_log(__METHOD__.__LINE__.$content['body']);
1173 1172
 
1174 1173
 		// prepare body
1175 1174
 		// in a way, this tests if we are having real utf-8 (the displayCharset) by now; we should if charsets reported (or detected) are correct
1176
-		$content['body'] = Api\Translation::convert_jsonsafe($content['body'],'utf-8');
1175
+		$content['body'] = Api\Translation::convert_jsonsafe($content['body'], 'utf-8');
1177 1176
 		//error_log(__METHOD__.__LINE__.array2string($content));
1178 1177
 
1179 1178
 		// get identities of all accounts as "$acc_id:$ident_id" => $identity
1180 1179
 		$sel_options['mailaccount'] = $identities = array();
1181
-		foreach(Mail\Account::search(true,false) as $acc_id => $account)
1180
+		foreach (Mail\Account::search(true, false) as $acc_id => $account)
1182 1181
 		{
1183 1182
 			// do NOT add SMTP only accounts as identities
1184 1183
 			if (!$account->is_imap(false)) continue;
1185 1184
 
1186
-			foreach($account->identities($acc_id) as $ident_id => $identity)
1185
+			foreach ($account->identities($acc_id) as $ident_id => $identity)
1187 1186
 			{
1188 1187
 				$sel_options['mailaccount'][$acc_id.':'.$ident_id] = $identity;
1189 1188
 				$identities[$ident_id] = $identity;
@@ -1194,7 +1193,7 @@  discard block
 block discarded – undo
1194 1193
 		//$content['bcc'] = array('[email protected]','[email protected]');
1195 1194
 		// address stuff like from, to, cc, replyto
1196 1195
 		$destinationRows = 0;
1197
-		foreach(self::$destinations as $destination) {
1196
+		foreach (self::$destinations as $destination) {
1198 1197
 			if (!is_array($content[$destination]))
1199 1198
 			{
1200 1199
 				if (!empty($content[$destination])) $content[$destination] = (array)$content[$destination];
@@ -1202,22 +1201,22 @@  discard block
 block discarded – undo
1202 1201
 			$addr_content = $content[strtolower($destination)];
1203 1202
 			// we clear the given address array and rebuild it
1204 1203
 			unset($content[strtolower($destination)]);
1205
-			foreach((array)$addr_content as $key => $value) {
1206
-				if ($value=="NIL@NIL") continue;
1207
-				if ($destination=='replyto' && str_replace('"','',$value) ==
1208
-					str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
1204
+			foreach ((array)$addr_content as $key => $value) {
1205
+				if ($value == "NIL@NIL") continue;
1206
+				if ($destination == 'replyto' && str_replace('"', '', $value) ==
1207
+					str_replace('"', '', $identities[$this->mail_bo->getDefaultIdentity()]))
1209 1208
 				{
1210 1209
 					// preserve/restore the value to content.
1211
-					$content[strtolower($destination)][]=$value;
1210
+					$content[strtolower($destination)][] = $value;
1212 1211
 					continue;
1213 1212
 				}
1214 1213
 				//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
1215
-				$value = str_replace("\"\"",'"', htmlspecialchars_decode($value, ENT_COMPAT));
1216
-				foreach(Mail::parseAddressList($value) as $addressObject) {
1214
+				$value = str_replace("\"\"", '"', htmlspecialchars_decode($value, ENT_COMPAT));
1215
+				foreach (Mail::parseAddressList($value) as $addressObject) {
1217 1216
 					if ($addressObject->host == '.SYNTAX-ERROR.') continue;
1218
-					$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
1217
+					$address = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
1219 1218
 					//$address = Mail::htmlentities($address, $this->displayCharset);
1220
-					$content[strtolower($destination)][]=$address;
1219
+					$content[strtolower($destination)][] = $address;
1221 1220
 					$destinationRows++;
1222 1221
 				}
1223 1222
 			}
@@ -1225,10 +1224,10 @@  discard block
 block discarded – undo
1225 1224
 		if ($_content)
1226 1225
 		{
1227 1226
 			//input array of _content had no signature information but was seeded later, and content has a valid setting
1228
-			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content)) unset($_content['mailidentity']);
1229
-			$content = array_merge($content,$_content);
1227
+			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity', $_content)) unset($_content['mailidentity']);
1228
+			$content = array_merge($content, $_content);
1230 1229
 
1231
-			if (!empty($content['folder'])) $sel_options['folder']=$this->ajax_searchFolder(0,true);
1230
+			if (!empty($content['folder'])) $sel_options['folder'] = $this->ajax_searchFolder(0, true);
1232 1231
 			if (empty($content['mailaccount'])) $content['mailaccount'] = $this->mail_bo->profileID;
1233 1232
 		}
1234 1233
 		else
@@ -1237,12 +1236,12 @@  discard block
 block discarded – undo
1237 1236
 			$content['mailaccount'] = $this->mail_bo->profileID;
1238 1237
 			//error_log(__METHOD__.__LINE__.$content['body']);
1239 1238
 		}
1240
-		$content['is_html'] = ($content['mimeType'] == 'html'?true:'');
1241
-		$content['is_plain'] = ($content['mimeType'] == 'html'?'':true);
1242
-		$content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text'] =$content['body'];
1243
-		$content['showtempname']=0;
1239
+		$content['is_html'] = ($content['mimeType'] == 'html' ? true : '');
1240
+		$content['is_plain'] = ($content['mimeType'] == 'html' ? '' : true);
1241
+		$content['mail_'.($content['mimeType'] == 'html' ? 'html' : 'plain').'text'] = $content['body'];
1242
+		$content['showtempname'] = 0;
1244 1243
 		//if (is_array($content['attachments']))error_log(__METHOD__.__LINE__.'before merging content with uploadforCompose:'.array2string($content['attachments']));
1245
-		$content['attachments']=(is_array($content['attachments'])&&is_array($content['uploadForCompose'])?array_merge($content['attachments'],(!empty($content['uploadForCompose'])?$content['uploadForCompose']:array())):(is_array($content['uploadForCompose'])?$content['uploadForCompose']:(is_array($content['attachments'])?$content['attachments']:null)));
1244
+		$content['attachments'] = (is_array($content['attachments']) && is_array($content['uploadForCompose']) ? array_merge($content['attachments'], (!empty($content['uploadForCompose']) ? $content['uploadForCompose'] : array())) : (is_array($content['uploadForCompose']) ? $content['uploadForCompose'] : (is_array($content['attachments']) ? $content['attachments'] : null)));
1246 1245
 		//if (is_array($content['attachments'])) foreach($content['attachments'] as $k => &$file) $file['delete['.$file['tmp_name'].']']=0;
1247 1246
 		$content['no_griddata'] = empty($content['attachments']);
1248 1247
 		$preserv['attachments'] = $content['attachments'];
@@ -1276,12 +1275,12 @@  discard block
 block discarded – undo
1276 1275
 		$sel_options['mimeType'] = self::$mimeTypes;
1277 1276
 		$sel_options['priority'] = self::$priorities;
1278 1277
 		$sel_options['filemode'] = Vfs\Sharing::$modes;
1279
-		if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
1278
+		if (!isset($content['priority']) || empty($content['priority'])) $content['priority'] = 3;
1280 1279
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
1281 1280
 		$etpl = new Etemplate('mail.compose');
1282 1281
 
1283 1282
 		$etpl->setElementAttribute('composeToolbar', 'actions', $this->getToolbarActions($_content));
1284
-		if ($content['mimeType']=='html')
1283
+		if ($content['mimeType'] == 'html')
1285 1284
 		{
1286 1285
 			//mode="$cont[rtfEditorFeatures]" validation_rules="$cont[validation_rules]" base_href="$cont[upload_dir]"
1287 1286
 			$_htmlConfig = Mail::$htmLawed_config;
@@ -1291,23 +1290,23 @@  discard block
 block discarded – undo
1291 1290
 			// and not the eGroupware wide pref to prevent users from trying things that will potentially not work
1292 1291
 			// or not work as expected, as a full featured editor that may be wanted in other apps
1293 1292
 			// is way overloading the "normal" needs for composing mails
1294
-			$content['rtfEditorFeatures']='simple-withimage';//Api\Html\CkEditorConfig::get_ckeditor_config();
1293
+			$content['rtfEditorFeatures'] = 'simple-withimage'; //Api\Html\CkEditorConfig::get_ckeditor_config();
1295 1294
 			//$content['rtfEditorFeatures']='advanced';//Api\Html\CkEditorConfig::get_ckeditor_config();
1296
-			$content['validation_rules']= json_encode(Mail::$htmLawed_config);
1297
-			$etpl->setElementAttribute('mail_htmltext','mode',$content['rtfEditorFeatures']);
1298
-			$etpl->setElementAttribute('mail_htmltext','validation_rules',$content['validation_rules']);
1295
+			$content['validation_rules'] = json_encode(Mail::$htmLawed_config);
1296
+			$etpl->setElementAttribute('mail_htmltext', 'mode', $content['rtfEditorFeatures']);
1297
+			$etpl->setElementAttribute('mail_htmltext', 'validation_rules', $content['validation_rules']);
1299 1298
 			Mail::$htmLawed_config = $_htmlConfig;
1300 1299
 		}
1301 1300
 
1302
-		if (isset($content['composeID'])&&!empty($content['composeID']))
1301
+		if (isset($content['composeID']) && !empty($content['composeID']))
1303 1302
 		{
1304 1303
 			$composeCache = $content;
1305 1304
 			unset($composeCache['body']);
1306 1305
 			unset($composeCache['mail_htmltext']);
1307 1306
 			unset($composeCache['mail_plaintext']);
1308
-			Api\Cache::setCache(Api\Cache::SESSION,'mail','composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID,$composeCache,$expiration=60*60*2);
1307
+			Api\Cache::setCache(Api\Cache::SESSION, 'mail', 'composeCache'.trim($GLOBALS['egw_info']['user']['account_id']).'_'.$this->composeID, $composeCache, $expiration = 60 * 60 * 2);
1309 1308
 		}
1310
-		if (!isset($_content['serverID'])||empty($_content['serverID']))
1309
+		if (!isset($_content['serverID']) || empty($_content['serverID']))
1311 1310
 		{
1312 1311
 			$content['serverID'] = $this->mail_bo->profileID;
1313 1312
 		}
@@ -1323,25 +1322,25 @@  discard block
 block discarded – undo
1323 1322
 		$preserv['list-id'] = $content['list-id'];
1324 1323
 		$preserv['mode'] = $content['mode'];
1325 1324
 		// convert it back to checkbox expectations
1326
-		if($content['mimeType'] == 'html') {
1327
-			$content['mimeType']=1;
1325
+		if ($content['mimeType'] == 'html') {
1326
+			$content['mimeType'] = 1;
1328 1327
 		} else {
1329
-			$content['mimeType']=0;
1328
+			$content['mimeType'] = 0;
1330 1329
 		}
1331 1330
 		// set the current selected mailaccount as param for folderselection
1332
-		$etpl->setElementAttribute('folder','autocomplete_params',array('mailaccount'=>$content['mailaccount']));
1331
+		$etpl->setElementAttribute('folder', 'autocomplete_params', array('mailaccount'=>$content['mailaccount']));
1333 1332
 		// join again mailaccount and identity
1334 1333
 		$content['mailaccount'] .= ':'.$content['mailidentity'];
1335 1334
 
1336 1335
 		// Resolve distribution list before send content to client
1337
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $f)
1336
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $f)
1338 1337
 		{
1339
-			if (is_array($content[$f])) $content[$f]= self::resolveEmailAddressList ($content[$f]);
1338
+			if (is_array($content[$f])) $content[$f] = self::resolveEmailAddressList($content[$f]);
1340 1339
 		}
1341 1340
 
1342 1341
 		$content['to'] = self::resolveEmailAddressList($content['to']);
1343 1342
 		//error_log(__METHOD__.__LINE__.array2string($content));
1344
-		$etpl->exec('mail.mail_compose.compose',$content,$sel_options,array(),$preserv,2);
1343
+		$etpl->exec('mail.mail_compose.compose', $content, $sel_options, array(), $preserv, 2);
1345 1344
 	}
1346 1345
 
1347 1346
 	/**
@@ -1362,9 +1361,9 @@  discard block
 block discarded – undo
1362 1361
 		$content = array();
1363 1362
 		//error_log(__METHOD__.__LINE__.array2string($mail_id).", $part_id, $from, $_focusElement, $suppressSigOnTop, $isReply");
1364 1363
 		// on forward we may have to support multiple ids
1365
-		if ($from=='forward')
1364
+		if ($from == 'forward')
1366 1365
 		{
1367
-			$replyIds = explode(',',$mail_id);
1366
+			$replyIds = explode(',', $mail_id);
1368 1367
 			$mail_id = $replyIds[0];
1369 1368
 		}
1370 1369
 		$hA = mail_ui::splitRowID($mail_id);
@@ -1376,15 +1375,15 @@  discard block
 block discarded – undo
1376 1375
 			$this->changeProfile($icServerID);
1377 1376
 		}
1378 1377
 		$icServer = $this->mail_bo->icServer;
1379
-		if (!empty($folder) && !empty($msgUID) )
1378
+		if (!empty($folder) && !empty($msgUID))
1380 1379
 		{
1381 1380
 			// this fill the session data with the values from the original email
1382
-			switch($from)
1381
+			switch ($from)
1383 1382
 			{
1384 1383
 				case 'composefromdraft':
1385 1384
 				case 'composeasnew':
1386 1385
 					$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
1387
-					if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
1386
+					if ($from == 'composefromdraft') $content['mode'] = 'composefromdraft';
1388 1387
 					$content['processedmail_id'] = $mail_id;
1389 1388
 
1390 1389
 					$_focusElement = 'body';
@@ -1400,7 +1399,7 @@  discard block
 block discarded – undo
1400 1399
 					$isReply = true;
1401 1400
 					break;
1402 1401
 				case 'forward':
1403
-					$mode  = ($_GET['mode']=='forwardinline'?'inline':'asmail');
1402
+					$mode = ($_GET['mode'] == 'forwardinline' ? 'inline' : 'asmail');
1404 1403
 					// this fill the session data with the values from the original email
1405 1404
 					foreach ($replyIds as &$mail_id)
1406 1405
 					{
@@ -1410,14 +1409,14 @@  discard block
 block discarded – undo
1410 1409
 						$folder = $hA['folder'];
1411 1410
 						$content = $this->getForwardData($icServer, $folder, $msgUID, $part_id, $mode);
1412 1411
 					}
1413
-					$content['processedmail_id'] = implode(',',$replyIds);
1412
+					$content['processedmail_id'] = implode(',', $replyIds);
1414 1413
 					$content['mode'] = 'forward';
1415
-					$isReply = ($mode?$mode=='inline':$this->mailPreferences['message_forwarding'] == 'inline');
1416
-					$suppressSigOnTop = false;// ($mode && $mode=='inline'?true:false);// may be a better solution
1414
+					$isReply = ($mode ? $mode == 'inline' : $this->mailPreferences['message_forwarding'] == 'inline');
1415
+					$suppressSigOnTop = false; // ($mode && $mode=='inline'?true:false);// may be a better solution
1417 1416
 					$_focusElement = 'to';
1418 1417
 					break;
1419 1418
 				default:
1420
-					error_log('Unhandled compose source: ' . $from);
1419
+					error_log('Unhandled compose source: '.$from);
1421 1420
 			}
1422 1421
 		}
1423 1422
 		else if ($from == 'merge' && $_REQUEST['document'])
@@ -1432,12 +1431,12 @@  discard block
 block discarded – undo
1432 1431
 			$document_merge = new $merge_class();
1433 1432
 			$this->mail_bo->openConnection();
1434 1433
 			$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
1435
-			if (!is_array($merge_ids)) $merge_ids = explode(',',$merge_ids);
1434
+			if (!is_array($merge_ids)) $merge_ids = explode(',', $merge_ids);
1436 1435
 			try
1437 1436
 			{
1438 1437
 				$merged_mail_id = '';
1439 1438
 				$folder = '';
1440
-				if(($error = $document_merge->check_document($_REQUEST['document'],'')))
1439
+				if (($error = $document_merge->check_document($_REQUEST['document'], '')))
1441 1440
 				{
1442 1441
 					$content['msg'] = $error;
1443 1442
 					return $content;
@@ -1447,10 +1446,10 @@  discard block
 block discarded – undo
1447 1446
 				//$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
1448 1447
 
1449 1448
 				// Actually do the merge
1450
-				if(count($merge_ids) <= 1)
1449
+				if (count($merge_ids) <= 1)
1451 1450
 				{
1452 1451
 					$results = $this->mail_bo->importMessageToMergeAndSend(
1453
-						$document_merge, Vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1452
+						$document_merge, Vfs::PREFIX.$_REQUEST['document'], $merge_ids, $folder, $merged_mail_id
1454 1453
 					);
1455 1454
 
1456 1455
 					// Open compose
@@ -1461,9 +1460,9 @@  discard block
 block discarded – undo
1461 1460
 				}
1462 1461
 				else
1463 1462
 				{
1464
-					$success = implode(', ',$results['success']);
1463
+					$success = implode(', ', $results['success']);
1465 1464
 					$fail = implode(', ', $results['failed']);
1466
-					if($success) Framework::message($success, 'success');
1465
+					if ($success) Framework::message($success, 'success');
1467 1466
 					Framework::window_close($fail);
1468 1467
 				}
1469 1468
 			}
@@ -1491,22 +1490,22 @@  discard block
 block discarded – undo
1491 1490
 		return 1;
1492 1491
 	}
1493 1492
 
1494
-	function convertHTMLToText(&$_html,$sourceishtml = true, $stripcrl=false)
1493
+	function convertHTMLToText(&$_html, $sourceishtml = true, $stripcrl = false)
1495 1494
 	{
1496 1495
 		$stripalltags = true;
1497 1496
 		// third param is stripalltags, we may not need that, if the source is already in ascii
1498
-		if (!$sourceishtml) $stripalltags=false;
1499
-		return Api\Mail\Html::convertHTMLToText($_html,$this->displayCharset,$stripcrl,$stripalltags);
1497
+		if (!$sourceishtml) $stripalltags = false;
1498
+		return Api\Mail\Html::convertHTMLToText($_html, $this->displayCharset, $stripcrl, $stripalltags);
1500 1499
 	}
1501 1500
 
1502 1501
 	function generateRFC822Address($_addressObject)
1503 1502
 	{
1504
-		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1505
-			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1506
-		} elseif($_addressObject->mailbox && $_addressObject->host) {
1507
-			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1503
+		if ($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1504
+			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1505
+		} elseif ($_addressObject->mailbox && $_addressObject->host) {
1506
+			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host, 'FORCE'));
1508 1507
 		} else {
1509
-			return $this->mail_bo->decode_header($_addressObject->mailbox,true);
1508
+			return $this->mail_bo->decode_header($_addressObject->mailbox, true);
1510 1509
 		}
1511 1510
 	}
1512 1511
 
@@ -1521,9 +1520,9 @@  discard block
 block discarded – undo
1521 1520
 	// $_mode can be:
1522 1521
 	// single: for a reply to one address
1523 1522
 	// all: for a reply to all
1524
-	function getDraftData($_icServer, $_folder, $_uid, $_partID=NULL)
1523
+	function getDraftData($_icServer, $_folder, $_uid, $_partID = NULL)
1525 1524
 	{
1526
-		unset($_icServer);	// not used
1525
+		unset($_icServer); // not used
1527 1526
 		$this->sessionData['to'] = array();
1528 1527
 
1529 1528
 		$mail_bo = $this->mail_bo;
@@ -1532,7 +1531,7 @@  discard block
 block discarded – undo
1532 1531
 
1533 1532
 		// get message headers for specified message
1534 1533
 		#$headers	= $mail_bo->getMessageHeader($_folder, $_uid);
1535
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID);
1534
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID);
1536 1535
 		$addHeadInfo = $mail_bo->getMessageHeader($_uid, $_partID);
1537 1536
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
1538 1537
 		// horde does not support the encoding of thread-topic, and probably will not no so in the future
@@ -1540,10 +1539,10 @@  discard block
 block discarded – undo
1540 1539
 
1541 1540
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1542 1541
 		if (!empty($addHeadInfo['X-MAILFOLDER'])) {
1543
-			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val ) {
1544
-				$fval=$val;
1542
+			foreach (explode('|', $addHeadInfo['X-MAILFOLDER']) as $val) {
1543
+				$fval = $val;
1545 1544
 				$icServerID = $mail_bo->icServer->ImapServerId;
1546
-				if (stripos($val,'::')!==false) list($icServerID,$fval) = explode('::',$val,2);
1545
+				if (stripos($val, '::') !== false) list($icServerID, $fval) = explode('::', $val, 2);
1547 1546
 				if ($icServerID != $mail_bo->icServer->ImapServerId) continue;
1548 1547
 				if ($mail_bo->folderExists($fval)) $this->sessionData['folder'][] = $val;
1549 1548
 			}
@@ -1579,71 +1578,71 @@  discard block
 block discarded – undo
1579 1578
 			}
1580 1579
 		}
1581 1580
 		// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
1582
-		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);//array('uid'=>$_uid,'folder'=>$_folder);
1581
+		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid); //array('uid'=>$_uid,'folder'=>$_folder);
1583 1582
 		$this->sessionData['uid'] = $_uid;
1584 1583
 		$this->sessionData['messageFolder'] = $_folder;
1585 1584
 		$this->sessionData['isDraft'] = true;
1586 1585
 		$foundAddresses = array();
1587
-		foreach((array)$headers['CC'] as $val) {
1588
-			$rfcAddr=Mail::parseAddressList($val);
1586
+		foreach ((array)$headers['CC'] as $val) {
1587
+			$rfcAddr = Mail::parseAddressList($val);
1589 1588
 			$_rfcAddr = $rfcAddr[0];
1590 1589
 			if (!$_rfcAddr->valid) continue;
1591
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1590
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1592 1591
 				continue;
1593 1592
 			}
1594
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1595
-			if(!$foundAddresses[$keyemail]) {
1596
-				$address = $this->mail_bo->decode_header($val,true);
1593
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1594
+			if (!$foundAddresses[$keyemail]) {
1595
+				$address = $this->mail_bo->decode_header($val, true);
1597 1596
 				$this->sessionData['cc'][] = $val;
1598 1597
 				$foundAddresses[$keyemail] = true;
1599 1598
 			}
1600 1599
 		}
1601 1600
 
1602
-		foreach((array)$headers['TO'] as $val) {
1603
-			if(!is_array($val))
1601
+		foreach ((array)$headers['TO'] as $val) {
1602
+			if (!is_array($val))
1604 1603
 			{
1605 1604
 				$this->sessionData['to'][] = $val;
1606 1605
 				continue;
1607 1606
 			}
1608
-			$rfcAddr=Mail::parseAddressList($val);
1607
+			$rfcAddr = Mail::parseAddressList($val);
1609 1608
 			$_rfcAddr = $rfcAddr[0];
1610 1609
 			if (!$_rfcAddr->valid) continue;
1611
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1610
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host)) {
1612 1611
 				continue;
1613 1612
 			}
1614
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1615
-			if(!$foundAddresses[$keyemail]) {
1616
-				$address = $this->mail_bo->decode_header($val,true);
1613
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1614
+			if (!$foundAddresses[$keyemail]) {
1615
+				$address = $this->mail_bo->decode_header($val, true);
1617 1616
 				$this->sessionData['to'][] = $val;
1618 1617
 				$foundAddresses[$keyemail] = true;
1619 1618
 			}
1620 1619
 		}
1621 1620
 
1622
-		foreach((array)$headers['REPLY-TO'] as $val) {
1623
-			$rfcAddr=Mail::parseAddressList($val);
1621
+		foreach ((array)$headers['REPLY-TO'] as $val) {
1622
+			$rfcAddr = Mail::parseAddressList($val);
1624 1623
 			$_rfcAddr = $rfcAddr[0];
1625 1624
 			if (!$_rfcAddr->valid) continue;
1626
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1625
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1627 1626
 				continue;
1628 1627
 			}
1629
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1630
-			if(!$foundAddresses[$keyemail]) {
1631
-				$address = $this->mail_bo->decode_header($val,true);
1628
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1629
+			if (!$foundAddresses[$keyemail]) {
1630
+				$address = $this->mail_bo->decode_header($val, true);
1632 1631
 				$this->sessionData['replyto'][] = $val;
1633 1632
 				$foundAddresses[$keyemail] = true;
1634 1633
 			}
1635 1634
 		}
1636 1635
 
1637
-		foreach((array)$headers['BCC'] as $val) {
1638
-			$rfcAddr=Mail::parseAddressList($val);
1636
+		foreach ((array)$headers['BCC'] as $val) {
1637
+			$rfcAddr = Mail::parseAddressList($val);
1639 1638
 			$_rfcAddr = $rfcAddr[0];
1640 1639
 			if (!$_rfcAddr->valid) continue;
1641
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1640
+			if ($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host))) {
1642 1641
 				continue;
1643 1642
 			}
1644
-			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1645
-			if(!$foundAddresses[$keyemail]) {
1646
-				$address = $this->mail_bo->decode_header($val,true);
1643
+			$keyemail = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1644
+			if (!$foundAddresses[$keyemail]) {
1645
+				$address = $this->mail_bo->decode_header($val, true);
1647 1646
 				$this->sessionData['bcc'][] = $val;
1648 1647
 				$foundAddresses[$keyemail] = true;
1649 1648
 			}
@@ -1652,48 +1651,48 @@  discard block
 block discarded – undo
1652 1651
 		$this->sessionData['subject']	= $mail_bo->decode_header($headers['SUBJECT']);
1653 1652
 		// remove a printview tag if composing
1654 1653
 		$searchfor = '/^\['.lang('printview').':\]/';
1655
-		$this->sessionData['subject'] = preg_replace($searchfor,'',$this->sessionData['subject']);
1656
-		$bodyParts = $mail_bo->getMessageBody($_uid,'always_display', $_partID);
1654
+		$this->sessionData['subject'] = preg_replace($searchfor, '', $this->sessionData['subject']);
1655
+		$bodyParts = $mail_bo->getMessageBody($_uid, 'always_display', $_partID);
1657 1656
 		//_debug_array($bodyParts);
1658 1657
 		#$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
1659
-		if($bodyParts['0']['mimeType'] == 'text/html') {
1660
-			$this->sessionData['mimeType'] 	= 'html';
1658
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
1659
+			$this->sessionData['mimeType'] = 'html';
1661 1660
 
1662
-			for($i=0; $i<count($bodyParts); $i++) {
1663
-				if($i>0) {
1661
+			for ($i = 0; $i < count($bodyParts); $i++) {
1662
+				if ($i > 0) {
1664 1663
 					$this->sessionData['body'] .= '<hr>';
1665 1664
 				}
1666
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
1665
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
1667 1666
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']);
1668 1667
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
1669 1668
 				}
1670
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1669
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1671 1670
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1672 1671
 				#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1673
-				$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
1672
+				$this->sessionData['body'] .= ($i > 0 ? "<br>" : "").$bodyParts[$i]['body'];
1674 1673
 			}
1675 1674
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID);
1676 1675
 
1677 1676
 		} else {
1678
-			$this->sessionData['mimeType']	= 'plain';
1677
+			$this->sessionData['mimeType'] = 'plain';
1679 1678
 
1680
-			for($i=0; $i<count($bodyParts); $i++) {
1681
-				if($i>0) {
1679
+			for ($i = 0; $i < count($bodyParts); $i++) {
1680
+				if ($i > 0) {
1682 1681
 					$this->sessionData['body'] .= "<hr>";
1683 1682
 				}
1684
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1683
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1685 1684
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1686 1685
 				#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1687
-				$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
1686
+				$this->sessionData['body'] .= ($i > 0 ? "\r\n" : "").$bodyParts[$i]['body'];
1688 1687
 			}
1689
-			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID,'plain');
1688
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'plain');
1690 1689
 		}
1691 1690
 
1692
-		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID))) {
1693
-			foreach($attachments as $attachment) {
1691
+		if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID))) {
1692
+			foreach ($attachments as $attachment) {
1694 1693
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
1695 1694
 				$cid = $attachment['cid'];
1696
-				$match=null;
1695
+				$match = null;
1697 1696
 				preg_match("/cid:{$cid}/", $bodyParts['0']['body'], $match);
1698 1697
 				//error_log(__METHOD__.__LINE__.'searching for cid:'."/cid:{$cid}/".'#'.$r.'#'.array2string($match));
1699 1698
 				if (!$match || !$attachment['cid'])
@@ -1713,7 +1712,7 @@  discard block
 block discarded – undo
1713 1712
 
1714 1713
 	function getErrorInfo()
1715 1714
 	{
1716
-		if(isset($this->errorInfo)) {
1715
+		if (isset($this->errorInfo)) {
1717 1716
 			$errorInfo = $this->errorInfo;
1718 1717
 			unset($this->errorInfo);
1719 1718
 			return $errorInfo;
@@ -1721,39 +1720,39 @@  discard block
 block discarded – undo
1721 1720
 		return false;
1722 1721
 	}
1723 1722
 
1724
-	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode=false)
1723
+	function getForwardData($_icServer, $_folder, $_uid, $_partID, $_mode = false)
1725 1724
 	{
1726 1725
 		if ($_mode)
1727 1726
 		{
1728 1727
 			$modebuff = $this->mailPreferences['message_forwarding'];
1729 1728
 			$this->mailPreferences['message_forwarding'] = $_mode;
1730 1729
 		}
1731
-		if  ($this->mailPreferences['message_forwarding'] == 'inline') {
1730
+		if ($this->mailPreferences['message_forwarding'] == 'inline') {
1732 1731
 			$this->getReplyData('forward', $_icServer, $_folder, $_uid, $_partID);
1733 1732
 		}
1734
-		$mail_bo    = $this->mail_bo;
1733
+		$mail_bo = $this->mail_bo;
1735 1734
 		$mail_bo->openConnection();
1736 1735
 		$mail_bo->reopen($_folder);
1737 1736
 
1738 1737
 		// get message headers for specified message
1739
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder);
1738
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder);
1740 1739
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1741 1740
 		//_debug_array($headers); exit;
1742 1741
 		// check for Re: in subject header
1743
-		$this->sessionData['subject'] 	= "[FWD] " . $mail_bo->decode_header($headers['SUBJECT']);
1742
+		$this->sessionData['subject'] = "[FWD] ".$mail_bo->decode_header($headers['SUBJECT']);
1744 1743
 		// the three attributes below are substituted by processedmail_id and mode
1745 1744
 		//$this->sessionData['sourceFolder']=$_folder;
1746 1745
 		//$this->sessionData['forwardFlag']='forwarded';
1747 1746
 		//$this->sessionData['forwardedUID']=$_uid;
1748
-		if  ($this->mailPreferences['message_forwarding'] == 'asmail') {
1749
-			$this->sessionData['mimeType']  = $this->mailPreferences['composeOptions'];
1750
-			if($headers['SIZE'])
1747
+		if ($this->mailPreferences['message_forwarding'] == 'asmail') {
1748
+			$this->sessionData['mimeType'] = $this->mailPreferences['composeOptions'];
1749
+			if ($headers['SIZE'])
1751 1750
 				$size				= $headers['SIZE'];
1752 1751
 			else
1753 1752
 				$size				= lang('unknown');
1754 1753
 
1755 1754
 			$this->addMessageAttachment($_uid, $_partID, $_folder,
1756
-				$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
1755
+				$mail_bo->decode_header(($headers['SUBJECT'] ? $headers['SUBJECT'] : lang('no subject'))).'.eml',
1757 1756
 				'MESSAGE/RFC822', $size);
1758 1757
 		}
1759 1758
 		else
@@ -1761,10 +1760,10 @@  discard block
 block discarded – undo
1761 1760
 			unset($this->sessionData['in-reply-to']);
1762 1761
 			unset($this->sessionData['to']);
1763 1762
 			unset($this->sessionData['cc']);
1764
-			if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false))) {
1763
+			if (($attachments = $mail_bo->getMessageAttachments($_uid, $_partID, null, true, false, false))) {
1765 1764
 				//error_log(__METHOD__.__LINE__.':'.array2string($attachments));
1766
-				foreach($attachments as $attachment) {
1767
-					if (!($attachment['cid'] && preg_match("/image\//",$attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1765
+				foreach ($attachments as $attachment) {
1766
+					if (!($attachment['cid'] && preg_match("/image\//", $attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1768 1767
 					{
1769 1768
 						$this->addMessageAttachment($_uid, $attachment['partID'],
1770 1769
 							$_folder,
@@ -1793,7 +1792,7 @@  discard block
 block discarded – undo
1793 1792
 	 * @param array $_content the content passed to the function and to be modified
1794 1793
 	 * @return void
1795 1794
 	 */
1796
-	function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false)
1795
+	function addAttachment($_formData, &$_content, $eliminateDoubleAttachments = false)
1797 1796
 	{
1798 1797
 		//error_log(__METHOD__.__LINE__.' Formdata:'.array2string($_formData).' Content:'.array2string($_content));
1799 1798
 
@@ -1802,7 +1801,7 @@  discard block
 block discarded – undo
1802 1801
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
1803 1802
 		try
1804 1803
 		{
1805
-			$tmpFileName = Mail::checkFileBasics($_formData,$this->composeID,false);
1804
+			$tmpFileName = Mail::checkFileBasics($_formData, $this->composeID, false);
1806 1805
 		}
1807 1806
 		catch (Api\Exception\WrongUserinput $e)
1808 1807
 		{
@@ -1818,8 +1817,8 @@  discard block
 block discarded – undo
1818 1817
 			foreach ((array)$_content['attachments'] as $attach)
1819 1818
 			{
1820 1819
 				if ($attach['name'] && $attach['name'] == $_formData['name'] &&
1821
-					strtolower($_formData['type'])== strtolower($attach['type']) &&
1822
-					stripos($_formData['file'],'vfs://') !== false) return;
1820
+					strtolower($_formData['type']) == strtolower($attach['type']) &&
1821
+					stripos($_formData['file'], 'vfs://') !== false) return;
1823 1822
 			}
1824 1823
 		}
1825 1824
 		if ($attachfailed === false)
@@ -1831,7 +1830,7 @@  discard block
 block discarded – undo
1831 1830
 				'tmp_name'	=> $tmpFileName,
1832 1831
 				'size'	=> $_formData['size']
1833 1832
 			);
1834
-			if (!is_array($_content['attachments'])) $_content['attachments']=array();
1833
+			if (!is_array($_content['attachments'])) $_content['attachments'] = array();
1835 1834
 			$_content['attachments'][] = $buffer;
1836 1835
 			unset($buffer);
1837 1836
 		}
@@ -1841,9 +1840,9 @@  discard block
 block discarded – undo
1841 1840
 		}
1842 1841
 	}
1843 1842
 
1844
-	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail= null)
1843
+	function addMessageAttachment($_uid, $_partID, $_folder, $_name, $_type, $_size, $_is_winmail = null)
1845 1844
 	{
1846
-		$this->sessionData['attachments'][]=array (
1845
+		$this->sessionData['attachments'][] = array(
1847 1846
 			'uid'		=> $_uid,
1848 1847
 			'partID'	=> $_partID,
1849 1848
 			'name'		=> $_name,
@@ -1851,7 +1850,7 @@  discard block
 block discarded – undo
1851 1850
 			'size'		=> $_size,
1852 1851
 			'folder'	=> $_folder,
1853 1852
 			'winmailFlag' => $_is_winmail,
1854
-			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID)?$_partID:count($this->sessionData['attachments'])+1),
1853
+			'tmp_name'	=> mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid).'_'.(!empty($_partID) ? $_partID : count($this->sessionData['attachments']) + 1),
1855 1854
 		);
1856 1855
 	}
1857 1856
 
@@ -1860,7 +1859,7 @@  discard block
 block discarded – undo
1860 1859
 		// read attachment data from etemplate request, use tmpname only to identify it
1861 1860
 		if (($request = Etemplate\Request::read($_GET['etemplate_exec_id'])))
1862 1861
 		{
1863
-			foreach($request->preserv['attachments'] as $attachment)
1862
+			foreach ($request->preserv['attachments'] as $attachment)
1864 1863
 			{
1865 1864
 				if ($_GET['tmpname'] === $attachment['tmp_name']) break;
1866 1865
 			}
@@ -1872,7 +1871,7 @@  discard block
 block discarded – undo
1872 1871
 		}
1873 1872
 
1874 1873
 		//error_log(__METHOD__.__LINE__.array2string($_GET));
1875
-		if (parse_url($attachment['tmp_name'],PHP_URL_SCHEME) == 'vfs')
1874
+		if (parse_url($attachment['tmp_name'], PHP_URL_SCHEME) == 'vfs')
1876 1875
 		{
1877 1876
 			Vfs::load_wrapper('vfs');
1878 1877
 		}
@@ -1881,7 +1880,7 @@  discard block
 block discarded – undo
1881 1880
 		{
1882 1881
 			$attachment['tmp_name'] = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['tmp_name']);
1883 1882
 		}
1884
-		if(!file_exists($attachment['tmp_name']))
1883
+		if (!file_exists($attachment['tmp_name']))
1885 1884
 		{
1886 1885
 			header('HTTP/1.1 404 Not found');
1887 1886
 			die('Attachment '.htmlspecialchars($attachment['tmp_name']).' NOT found!');
@@ -1894,7 +1893,7 @@  discard block
 block discarded – undo
1894 1893
 			if (strtoupper($attachment['type']) == 'TEXT/DIRECTORY')
1895 1894
 			{
1896 1895
 				$sfxMimeType = $attachment['type'];
1897
-				$buff = explode('.',$attachment['tmp_name']);
1896
+				$buff = explode('.', $attachment['tmp_name']);
1898 1897
 				$suffix = '';
1899 1898
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
1900 1899
 				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
@@ -1906,10 +1905,10 @@  discard block
 block discarded – undo
1906 1905
 			{
1907 1906
 				//error_log(__METHOD__."about to call calendar_ical");
1908 1907
 				$calendar_ical = new calendar_ical();
1909
-				$eventid = $calendar_ical->search($attachment['attachment'],-1);
1908
+				$eventid = $calendar_ical->search($attachment['attachment'], -1);
1910 1909
 				//error_log(__METHOD__.array2string($eventid));
1911 1910
 				if (!$eventid) $eventid = -1;
1912
-				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
1911
+				$event = $calendar_ical->importVCal($attachment['attachment'], (is_array($eventid) ? $eventid[0] : $eventid), null, true);
1913 1912
 				//error_log(__METHOD__.$event);
1914 1913
 				if ((int)$event > 0)
1915 1914
 				{
@@ -1917,7 +1916,7 @@  discard block
 block discarded – undo
1917 1916
 						'menuaction'      => 'calendar.calendar_uiforms.edit',
1918 1917
 						'cal_id'      => $event,
1919 1918
 					);
1920
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1919
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1921 1920
 				}
1922 1921
 				//Import failed, download content anyway
1923 1922
 			}
@@ -1932,13 +1931,13 @@  discard block
 block discarded – undo
1932 1931
 				{
1933 1932
 					$vcard['uid'] = trim($vcard['uid']);
1934 1933
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
1935
-					$contact = $addressbook_vcal->find_contact($vcard,false);
1934
+					$contact = $addressbook_vcal->find_contact($vcard, false);
1936 1935
 				}
1937 1936
 				if (!$contact) $contact = null;
1938 1937
 				// 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))
1939
-				if ($contact || count($vcard)>2)
1938
+				if ($contact || count($vcard) > 2)
1940 1939
 				{
1941
-					$contact = $addressbook_vcal->addVCard($attachment['attachment'],(is_array($contact)?array_shift($contact):$contact),true);
1940
+					$contact = $addressbook_vcal->addVCard($attachment['attachment'], (is_array($contact) ? array_shift($contact) : $contact), true);
1942 1941
 				}
1943 1942
 				if ((int)$contact > 0)
1944 1943
 				{
@@ -1946,13 +1945,13 @@  discard block
 block discarded – undo
1946 1945
 						'menuaction'	=> 'addressbook.addressbook_ui.edit',
1947 1946
 						'contact_id'	=> $contact,
1948 1947
 					);
1949
-					$GLOBALS['egw']->redirect_link('../index.php',$vars);
1948
+					$GLOBALS['egw']->redirect_link('../index.php', $vars);
1950 1949
 				}
1951 1950
 				//Import failed, download content anyway
1952 1951
 			}
1953 1952
 		}
1954 1953
 		//error_log(__METHOD__.__LINE__.'->'.array2string($attachment));
1955
-		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size=0, true, $_GET['mode'] == "save");
1954
+		Api\Header\Content::safe($attachment['attachment'], $attachment['name'], $attachment['type'], $size = 0, true, $_GET['mode'] == "save");
1956 1955
 		echo $attachment['attachment'];
1957 1956
 
1958 1957
 		exit();
@@ -1965,11 +1964,11 @@  discard block
 block discarded – undo
1965 1964
 	 * @param string haystack
1966 1965
 	 * @return boolean
1967 1966
 	 */
1968
-	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack) {
1967
+	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst, $haystack) {
1969 1968
 		foreach (array_keys($arrayToTestAgainst) as $k)
1970 1969
 		{
1971 1970
 			//error_log(__METHOD__.__LINE__.':'.$k.'<->'.$haystack);
1972
-			if (stripos($haystack,$k)!==false)
1971
+			if (stripos($haystack, $k) !== false)
1973 1972
 			{
1974 1973
 				//error_log(__METHOD__.__LINE__.':FOUND:'.$k.'<->'.$haystack.function_backtrace());
1975 1974
 				return true;
@@ -1992,10 +1991,10 @@  discard block
 block discarded – undo
1992 1991
 	 */
1993 1992
 	function getReplyData($_mode, $_icServer, $_folder, $_uid, $_partID)
1994 1993
 	{
1995
-		unset($_icServer);	// not used
1994
+		unset($_icServer); // not used
1996 1995
 		$foundAddresses = array();
1997 1996
 
1998
-		$mail_bo  = $this->mail_bo;
1997
+		$mail_bo = $this->mail_bo;
1999 1998
 		$mail_bo->openConnection();
2000 1999
 		$mail_bo->reopen($_folder);
2001 2000
 
@@ -2003,20 +2002,20 @@  discard block
 block discarded – undo
2003 2002
 
2004 2003
 		// get message headers for specified message
2005 2004
 		//print "AAAA: $_folder, $_uid, $_partID<br>";
2006
-		$headers	= $mail_bo->getMessageEnvelope($_uid, $_partID,false,$_folder,$useHeaderInsteadOfEnvelope=true);
2005
+		$headers = $mail_bo->getMessageEnvelope($_uid, $_partID, false, $_folder, $useHeaderInsteadOfEnvelope = true);
2007 2006
 		//$headers	= $mail_bo->getMessageHeader($_uid, $_partID, true, true, $_folder);
2008 2007
 		$this->sessionData['uid'] = $_uid;
2009 2008
 		$this->sessionData['messageFolder'] = $_folder;
2010
-		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO']?$headers['IN-REPLY-TO']:$headers['MESSAGE_ID']);
2011
-		$this->sessionData['references'] = ($headers['REFERENCES']?$headers['REFERENCES']:$headers['MESSAGE_ID']);
2009
+		$this->sessionData['in-reply-to'] = ($headers['IN-REPLY-TO'] ? $headers['IN-REPLY-TO'] : $headers['MESSAGE_ID']);
2010
+		$this->sessionData['references'] = ($headers['REFERENCES'] ? $headers['REFERENCES'] : $headers['MESSAGE_ID']);
2012 2011
 
2013 2012
 		// break reference into multiple lines if they're greater than 998 chars
2014 2013
 		// and remove comma seperation. Fix error serer does not support binary
2015 2014
 		// data due to long references.
2016
-		if (strlen($this->sessionData['references'])> 998)
2015
+		if (strlen($this->sessionData['references']) > 998)
2017 2016
 		{
2018
-			$temp_refs = explode(',',$this->sessionData['references']);
2019
-			$this->sessionData['references'] = implode(" ",$temp_refs);
2017
+			$temp_refs = explode(',', $this->sessionData['references']);
2018
+			$this->sessionData['references'] = implode(" ", $temp_refs);
2020 2019
 		}
2021 2020
 
2022 2021
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
@@ -2026,36 +2025,36 @@  discard block
 block discarded – undo
2026 2025
 		if ($headers['LIST-ID']) $this->sessionData['list-id'] = $headers['LIST-ID'];
2027 2026
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_mode.':'.array2string($headers));
2028 2027
 		// check for Reply-To: header and use if available
2029
-		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2030
-			foreach($headers['REPLY-TO'] as $val) {
2031
-				if(!$foundAddresses[$val]) {
2028
+		if (!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2029
+			foreach ($headers['REPLY-TO'] as $val) {
2030
+				if (!$foundAddresses[$val]) {
2032 2031
 					$oldTo[] = $val;
2033 2032
 					$foundAddresses[$val] = true;
2034 2033
 				}
2035 2034
 			}
2036
-			$oldToAddress	= (is_array($headers['REPLY-TO'])?$headers['REPLY-TO'][0]:$headers['REPLY-TO']);
2035
+			$oldToAddress = (is_array($headers['REPLY-TO']) ? $headers['REPLY-TO'][0] : $headers['REPLY-TO']);
2037 2036
 		} else {
2038
-			foreach($headers['FROM'] as $val) {
2039
-				if(!$foundAddresses[$val]) {
2037
+			foreach ($headers['FROM'] as $val) {
2038
+				if (!$foundAddresses[$val]) {
2040 2039
 					$oldTo[] = $val;
2041 2040
 					$foundAddresses[$val] = true;
2042 2041
 				}
2043 2042
 			}
2044
-			$oldToAddress	= (is_array($headers['FROM'])?$headers['FROM'][0]:$headers['FROM']);
2043
+			$oldToAddress = (is_array($headers['FROM']) ? $headers['FROM'][0] : $headers['FROM']);
2045 2044
 		}
2046 2045
 		//error_log(__METHOD__.__LINE__.' OldToAddress:'.$oldToAddress.'#');
2047
-		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) ) {
2046
+		if ($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $oldToAddress))) {
2048 2047
 			$this->sessionData['to'] = $oldTo;
2049 2048
 		}
2050 2049
 
2051
-		if($_mode == 'all') {
2050
+		if ($_mode == 'all') {
2052 2051
 			// reply to any address which is cc, but not to my self
2053 2052
 			#if($headers->cc) {
2054
-				foreach($headers['CC'] as $val) {
2055
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2053
+				foreach ($headers['CC'] as $val) {
2054
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2056 2055
 						continue;
2057 2056
 					}
2058
-					if(!$foundAddresses[$val]) {
2057
+					if (!$foundAddresses[$val]) {
2059 2058
 						$this->sessionData['cc'][] = $val;
2060 2059
 						$foundAddresses[$val] = true;
2061 2060
 					}
@@ -2064,11 +2063,11 @@  discard block
 block discarded – undo
2064 2063
 
2065 2064
 			// reply to any address which is to, but not to my self
2066 2065
 			#if($headers->to) {
2067
-				foreach($headers['TO'] as $val) {
2068
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2066
+				foreach ($headers['TO'] as $val) {
2067
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2069 2068
 						continue;
2070 2069
 					}
2071
-					if(!$foundAddresses[$val]) {
2070
+					if (!$foundAddresses[$val]) {
2072 2071
 						$this->sessionData['to'][] = $val;
2073 2072
 						$foundAddresses[$val] = true;
2074 2073
 					}
@@ -2076,12 +2075,12 @@  discard block
 block discarded – undo
2076 2075
 			#}
2077 2076
 
2078 2077
 			#if($headers->from) {
2079
-				foreach($headers['FROM'] as $val) {
2080
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2078
+				foreach ($headers['FROM'] as $val) {
2079
+					if ($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses, $val)) {
2081 2080
 						continue;
2082 2081
 					}
2083 2082
 					//error_log(__METHOD__.__LINE__.' '.$val);
2084
-					if(!$foundAddresses[$val]) {
2083
+					if (!$foundAddresses[$val]) {
2085 2084
 						$this->sessionData['to'][] = $val;
2086 2085
 						$foundAddresses[$val] = true;
2087 2086
 					}
@@ -2090,59 +2089,59 @@  discard block
 block discarded – undo
2090 2089
 		}
2091 2090
 
2092 2091
 		// check for Re: in subject header
2093
-		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2092
+		if (strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2094 2093
 			$this->sessionData['subject'] = $mail_bo->decode_header($headers['SUBJECT']);
2095 2094
 		} else {
2096
-			$this->sessionData['subject'] = "Re: " . $mail_bo->decode_header($headers['SUBJECT']);
2095
+			$this->sessionData['subject'] = "Re: ".$mail_bo->decode_header($headers['SUBJECT']);
2097 2096
 		}
2098 2097
 
2099 2098
 		//_debug_array($headers);
2100 2099
 		//error_log(__METHOD__.__LINE__.'->'.array2string($this->mailPreferences['htmlOptions']));
2101
-		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions']?$this->mailPreferences['htmlOptions']:''), $_partID);
2100
+		$bodyParts = $mail_bo->getMessageBody($_uid, ($this->mailPreferences['htmlOptions'] ? $this->mailPreferences['htmlOptions'] : ''), $_partID);
2102 2101
 		//_debug_array($bodyParts);
2103 2102
 		$styles = Mail::getStyles($bodyParts);
2104 2103
 
2105
-		$fromAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$headers['FROM']));
2104
+		$fromAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $headers['FROM']));
2106 2105
 
2107 2106
 		$toAddressA = array();
2108 2107
 		$toAddress = '';
2109 2108
 		foreach ($headers['TO'] as $mailheader) {
2110
-			$toAddressA[] =  $mailheader;
2109
+			$toAddressA[] = $mailheader;
2111 2110
 		}
2112
-		if (count($toAddressA)>0)
2111
+		if (count($toAddressA) > 0)
2113 2112
 		{
2114
-			$toAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$toAddressA));
2115
-			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2113
+			$toAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $toAddressA));
2114
+			$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2116 2115
 		}
2117 2116
 		$ccAddressA = array();
2118 2117
 		$ccAddress = '';
2119 2118
 		foreach ($headers['CC'] as $mailheader) {
2120
-			$ccAddressA[] =  $mailheader;
2119
+			$ccAddressA[] = $mailheader;
2121 2120
 		}
2122
-		if (count($ccAddressA)>0)
2121
+		if (count($ccAddressA) > 0)
2123 2122
 		{
2124
-			$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA));
2125
-			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2123
+			$ccAddress = implode(', ', str_replace(array('<', '>'), array('[', ']'), $ccAddressA));
2124
+			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html' ? "<br>" : "\r\n");
2126 2125
 		}
2127
-		if($bodyParts['0']['mimeType'] == 'text/html') {
2128
-			$this->sessionData['body']	= /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2126
+		if ($bodyParts['0']['mimeType'] == 'text/html') {
2127
+			$this->sessionData['body'] = /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2129 2128
 				@htmlspecialchars(lang("from")).": ".$fromAddress."<br>".
2130 2129
 				$toAddress.$ccAddress.
2131
-				@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>".
2130
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."<br>".
2132 2131
 				'----------------------------------------------------------'."</div>";
2133
-			$this->sessionData['mimeType'] 	= 'html';
2132
+			$this->sessionData['mimeType'] = 'html';
2134 2133
 			if (!empty($styles)) $this->sessionData['body'] .= $styles;
2135
-			$this->sessionData['body']	.= '<blockquote type="cite">';
2134
+			$this->sessionData['body'] .= '<blockquote type="cite">';
2136 2135
 
2137
-			for($i=0; $i<count($bodyParts); $i++) {
2138
-				if($i>0) {
2136
+			for ($i = 0; $i < count($bodyParts); $i++) {
2137
+				if ($i > 0) {
2139 2138
 					$this->sessionData['body'] .= '<hr>';
2140 2139
 				}
2141
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
2140
+				if ($bodyParts[$i]['mimeType'] == 'text/plain') {
2142 2141
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>";
2143 2142
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
2144 2143
 				}
2145
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2144
+				if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2146 2145
 
2147 2146
 				$_htmlConfig = Mail::$htmLawed_config;
2148 2147
 				Mail::$htmLawed_config['comment'] = 2;
@@ -2152,30 +2151,30 @@  discard block
 block discarded – undo
2152 2151
 				#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2153 2152
 			}
2154 2153
 
2155
-			$this->sessionData['body']	.= '</blockquote><br>';
2156
-			$this->sessionData['body'] =  mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2154
+			$this->sessionData['body'] .= '</blockquote><br>';
2155
+			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2157 2156
 		} else {
2158 2157
 			//$this->sessionData['body']	= @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n";
2159 2158
 			// 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)
2160
-            $this->sessionData['body']  = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2159
+            $this->sessionData['body'] = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
2161 2160
                 @htmlspecialchars(lang("from")).": ".$fromAddress."\r\n".
2162 2161
 				$toAddress.$ccAddress.
2163
-				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
2162
+				@htmlspecialchars(lang("date").": ".$headers['DATE'], ENT_QUOTES|ENT_IGNORE, Mail::$displayCharset, false)."\r\n".
2164 2163
                 '-------------------------------------------------'."\r\n \r\n ";
2165
-			$this->sessionData['mimeType']	= 'plain';
2164
+			$this->sessionData['mimeType'] = 'plain';
2166 2165
 
2167
-			for($i=0; $i<count($bodyParts); $i++) {
2168
-				if($i>0) {
2166
+			for ($i = 0; $i < count($bodyParts); $i++) {
2167
+				if ($i > 0) {
2169 2168
 					$this->sessionData['body'] .= "<hr>";
2170 2169
 				}
2171 2170
 
2172 2171
 				// add line breaks to $bodyParts
2173
-				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']);
2172
+				$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
2174 2173
 				#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
2175 2174
 				$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
2176 2175
 				$this->sessionData['body'] .= "\r\n";
2177 2176
 				// create body new, with good line breaks and indention
2178
-				foreach(explode("\n",$newBody) as $value) {
2177
+				foreach (explode("\n", $newBody) as $value) {
2179 2178
 					// the explode is removing the character
2180 2179
 					if (trim($value) != '') {
2181 2180
 						#if ($value != "\r") $value .= "\n";
@@ -2183,12 +2182,12 @@  discard block
 block discarded – undo
2183 2182
 					$numberOfChars = strspn(trim($value), ">");
2184 2183
 					$appendString = str_repeat('>', $numberOfChars + 1);
2185 2184
 
2186
-					$bodyAppend = $this->mail_bo->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
2185
+					$bodyAppend = $this->mail_bo->wordwrap($value, 76 - strlen("\r\n$appendString "), "\r\n$appendString ", '>');
2187 2186
 
2188
-					if($bodyAppend[0] == '>') {
2189
-						$bodyAppend = '>'. $bodyAppend;
2187
+					if ($bodyAppend[0] == '>') {
2188
+						$bodyAppend = '>'.$bodyAppend;
2190 2189
 					} else {
2191
-						$bodyAppend = '> '. $bodyAppend;
2190
+						$bodyAppend = '> '.$bodyAppend;
2192 2191
 					}
2193 2192
 
2194 2193
 					$this->sessionData['body'] .= $bodyAppend;
@@ -2211,16 +2210,16 @@  discard block
 block discarded – undo
2211 2210
 	 */
2212 2211
 	static function _getCleanHTML($_body, $_useTidy = false)
2213 2212
 	{
2214
-		static $nonDisplayAbleCharacters = array('[\016]','[\017]',
2215
-				'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
2216
-				'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
2213
+		static $nonDisplayAbleCharacters = array('[\016]', '[\017]',
2214
+				'[\020]', '[\021]', '[\022]', '[\023]', '[\024]', '[\025]', '[\026]', '[\027]',
2215
+				'[\030]', '[\031]', '[\032]', '[\033]', '[\034]', '[\035]', '[\036]', '[\037]');
2217 2216
 
2218
-		if ($_useTidy && extension_loaded('tidy') )
2217
+		if ($_useTidy && extension_loaded('tidy'))
2219 2218
 		{
2220 2219
 			$tidy = new tidy();
2221
-			$cleaned = $tidy->repairString($_body, Mail::$tidy_config,'utf8');
2220
+			$cleaned = $tidy->repairString($_body, Mail::$tidy_config, 'utf8');
2222 2221
 			// Found errors. Strip it all so there's some output
2223
-			if($tidy->getStatus() == 2)
2222
+			if ($tidy->getStatus() == 2)
2224 2223
 			{
2225 2224
 				error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
2226 2225
 			}
@@ -2254,13 +2253,13 @@  discard block
 block discarded – undo
2254 2253
 	 *
2255 2254
 	 * @return array returns found inline images as attachment structure
2256 2255
 	 */
2257
-	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving=false)
2256
+	function createMessage(Api\Mailer $_mailObject, array $_formData, array $_identity, $_autosaving = false)
2258 2257
 	{
2259 2258
 		if (substr($_formData['body'], 0, 27) == '-----BEGIN PGP MESSAGE-----')
2260 2259
 		{
2261 2260
 			$_formData['mimeType'] = 'openpgp';
2262 2261
 		}
2263
-		$mail_bo	= $this->mail_bo;
2262
+		$mail_bo = $this->mail_bo;
2264 2263
 		$activeMailProfile = Mail\Account::read($this->mail_bo->profileID);
2265 2264
 
2266 2265
 		// you need to set the sender, if you work with different identities, since most smtp servers, dont allow
@@ -2269,37 +2268,37 @@  discard block
 block discarded – undo
2269 2268
 		{
2270 2269
 			error_log(__METHOD__.__LINE__.' Faking From/SenderInfo for '.$activeMailProfile['ident_email'].' with ID:'.$activeMailProfile['ident_id'].'. Identitiy to use for sending:'.array2string($_identity));
2271 2270
 		}
2272
-		$email_From =  $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2271
+		$email_From = $_identity['ident_email'] ? $_identity['ident_email'] : $activeMailProfile['ident_email'];
2273 2272
 		// Try to fix identity email with no domain part set
2274 2273
 		$_mailObject->setFrom(Mail::fixInvalidAliasAddress(Api\Accounts::id2name($_identity['account_id'], 'account_email'), $email_From),
2275
-			Mail::generateIdentityString($_identity,false));
2274
+			Mail::generateIdentityString($_identity, false));
2276 2275
 
2277 2276
 		$_mailObject->addHeader('X-Priority', $_formData['priority']);
2278 2277
 		$_mailObject->addHeader('X-Mailer', 'EGroupware-Mail');
2279
-		if(!empty($_formData['in-reply-to'])) {
2280
-			if (stripos($_formData['in-reply-to'],'<')===false) $_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2278
+		if (!empty($_formData['in-reply-to'])) {
2279
+			if (stripos($_formData['in-reply-to'], '<') === false) $_formData['in-reply-to'] = '<'.trim($_formData['in-reply-to']).'>';
2281 2280
 			$_mailObject->addHeader('In-Reply-To', $_formData['in-reply-to']);
2282 2281
 		}
2283
-		if(!empty($_formData['references'])) {
2284
-			if (stripos($_formData['references'],'<')===false)
2282
+		if (!empty($_formData['references'])) {
2283
+			if (stripos($_formData['references'], '<') === false)
2285 2284
 			{
2286
-				$_formData['references']='<'.trim($_formData['references']).'>';
2285
+				$_formData['references'] = '<'.trim($_formData['references']).'>';
2287 2286
 			}
2288 2287
 			$_mailObject->addHeader('References', $_formData['references']);
2289 2288
 		}
2290 2289
 
2291
-		if(!empty($_formData['thread-index'])) {
2290
+		if (!empty($_formData['thread-index'])) {
2292 2291
 			$_mailObject->addHeader('Thread-Index', $_formData['thread-index']);
2293 2292
 		}
2294
-		if(!empty($_formData['list-id'])) {
2293
+		if (!empty($_formData['list-id'])) {
2295 2294
 			$_mailObject->addHeader('List-Id', $_formData['list-id']);
2296 2295
 		}
2297
-		if($_formData['disposition']=='on') {
2296
+		if ($_formData['disposition'] == 'on') {
2298 2297
 			$_mailObject->addHeader('Disposition-Notification-To', $_identity['ident_email']);
2299 2298
 		}
2300 2299
 
2301 2300
 		// Expand any mailing lists
2302
-		foreach(array('to', 'cc', 'bcc', 'replyto')  as $field)
2301
+		foreach (array('to', 'cc', 'bcc', 'replyto')  as $field)
2303 2302
 		{
2304 2303
 			if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2305 2304
 
@@ -2315,7 +2314,7 @@  discard block
 block discarded – undo
2315 2314
 		}
2316 2315
 		$disableRuler = false;
2317 2316
 		$signature = $_identity['ident_signature'];
2318
-		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend'?1:0;
2317
+		$sigAlreadyThere = $this->mailPreferences['insertSignatureAtTopOfMessage'] != 'no_belowaftersend' ? 1 : 0;
2319 2318
 		if ($sigAlreadyThere)
2320 2319
 		{
2321 2320
 			// note: if you use stationery ' s the insert signatures at the top does not apply here anymore, as the signature
@@ -2324,7 +2323,7 @@  discard block
 block discarded – undo
2324 2323
 		}
2325 2324
 		if ((isset($this->mailPreferences['disableRulerForSignatureSeparation']) &&
2326 2325
 			$this->mailPreferences['disableRulerForSignatureSeparation']) ||
2327
-			empty($signature) || trim($this->convertHTMLToText($signature)) =='')
2326
+			empty($signature) || trim($this->convertHTMLToText($signature)) == '')
2328 2327
 		{
2329 2328
 			$disableRuler = true;
2330 2329
 		}
@@ -2335,7 +2334,7 @@  discard block
 block discarded – undo
2335 2334
 				array_unique(array_merge((array)$_formData['to'], (array)$_formData['cc'], (array)$_formData['bcc'])),
2336 2335
 				$_formData['expiration'], $_formData['password']);
2337 2336
 		}
2338
-		if($_formData['mimeType'] == 'html')
2337
+		if ($_formData['mimeType'] == 'html')
2339 2338
 		{
2340 2339
 			$body = $_formData['body'];
2341 2340
 			if ($attachment_links)
@@ -2349,13 +2348,13 @@  discard block
 block discarded – undo
2349 2348
 					$body .= $attachment_links;
2350 2349
 				}
2351 2350
 			}
2352
-			if(!empty($signature))
2351
+			if (!empty($signature))
2353 2352
 			{
2354 2353
 				$_mailObject->setBody($this->convertHTMLToText($body, true, true).
2355 2354
 					($disableRuler ? "\r\n" : "\r\n-- \r\n").
2356 2355
 					$this->convertHTMLToText($signature, true, true));
2357 2356
 
2358
-				$body .= ($disableRuler ?'<br>':'<hr style="border:1px dotted silver; width:90%;">').$signature;
2357
+				$body .= ($disableRuler ? '<br>' : '<hr style="border:1px dotted silver; width:90%;">').$signature;
2359 2358
 			}
2360 2359
 			else
2361 2360
 			{
@@ -2363,11 +2362,11 @@  discard block
 block discarded – undo
2363 2362
 			}
2364 2363
 			// convert URL Images to inline images - if possible
2365 2364
 			if (!$_autosaving) $inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2366
-			if (strpos($body,"<!-- HTMLSIGBEGIN -->")!==false)
2365
+			if (strpos($body, "<!-- HTMLSIGBEGIN -->") !== false)
2367 2366
 			{
2368
-				$body = str_replace(array('<!-- HTMLSIGBEGIN -->','<!-- HTMLSIGEND -->'),'',$body);
2367
+				$body = str_replace(array('<!-- HTMLSIGBEGIN -->', '<!-- HTMLSIGEND -->'), '', $body);
2369 2368
 			}
2370
-			$_mailObject->setHtmlBody($body, null, false);	// false = no automatic alternative, we called setBody()
2369
+			$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
2371 2370
 		}
2372 2371
 		elseif ($_formData['mimeType'] == 'openpgp')
2373 2372
 		{
@@ -2375,14 +2374,14 @@  discard block
 block discarded – undo
2375 2374
 		}
2376 2375
 		else
2377 2376
 		{
2378
-			$body = $this->convertHTMLToText($_formData['body'],false);
2377
+			$body = $this->convertHTMLToText($_formData['body'], false);
2379 2378
 
2380 2379
 			if ($attachment_links) $body .= $attachment_links;
2381 2380
 
2382 2381
 			#$_mailObject->Body = $_formData['body'];
2383
-			if(!empty($signature)) {
2384
-				$body .= ($disableRuler ?"\r\n":"\r\n-- \r\n").
2385
-					$this->convertHTMLToText($signature,true,true);
2382
+			if (!empty($signature)) {
2383
+				$body .= ($disableRuler ? "\r\n" : "\r\n-- \r\n").
2384
+					$this->convertHTMLToText($signature, true, true);
2386 2385
 			}
2387 2386
 			$_mailObject->setBody($body);
2388 2387
 		}
@@ -2391,8 +2390,8 @@  discard block
 block discarded – undo
2391 2390
 		{
2392 2391
 			$connection_opened = false;
2393 2392
 			$tnfattachments = null;
2394
-			foreach((array)$_formData['attachments'] as $attachment) {
2395
-				if(is_array($attachment))
2393
+			foreach ((array)$_formData['attachments'] as $attachment) {
2394
+				if (is_array($attachment))
2396 2395
 				{
2397 2396
 					if (!empty($attachment['uid']) && !empty($attachment['folder'])) {
2398 2397
 						/* Example:
@@ -2410,20 +2409,20 @@  discard block
 block discarded – undo
2410 2409
 							$connection_opened = true;
2411 2410
 						}
2412 2411
 						$mail_bo->reopen($attachment['folder']);
2413
-						switch(strtoupper($attachment['type'])) {
2412
+						switch (strtoupper($attachment['type'])) {
2414 2413
 							case 'MESSAGE/RFC':
2415 2414
 							case 'MESSAGE/RFC822':
2416
-								$rawBody='';
2415
+								$rawBody = '';
2417 2416
 								if (isset($attachment['partID'])) {
2418
-									$eml = $mail_bo->getAttachment($attachment['uid'],$attachment['partID'],0,false,true,$attachment['folder']);
2419
-									$rawBody=$eml['attachment'];
2417
+									$eml = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false, true, $attachment['folder']);
2418
+									$rawBody = $eml['attachment'];
2420 2419
 								} else {
2421
-									$rawBody        = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'],$attachment['folder']);
2420
+									$rawBody = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'], $attachment['folder']);
2422 2421
 								}
2423 2422
 								$_mailObject->addStringAttachment($rawBody, $attachment['name'], 'message/rfc822');
2424 2423
 								break;
2425 2424
 							default:
2426
-								$attachmentData	= $mail_bo->getAttachment($attachment['uid'], $attachment['partID'],0,false);
2425
+								$attachmentData = $mail_bo->getAttachment($attachment['uid'], $attachment['partID'], 0, false);
2427 2426
 								if ($attachmentData['type'] == 'APPLICATION/MS-TNEF')
2428 2427
 								{
2429 2428
 									if (!is_array($tnfattachments)) $tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
@@ -2431,7 +2430,7 @@  discard block
 block discarded – undo
2431 2430
 									{
2432 2431
 										if ($k['name'] == $attachment['name'])
2433 2432
 										{
2434
-											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'],$k['is_winmail']);
2433
+											$tnfpart = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID'], $k['is_winmail']);
2435 2434
 											$attachmentData['attachment'] = $tnfpart['attachment'];
2436 2435
 											break;
2437 2436
 										}
@@ -2444,7 +2443,7 @@  discard block
 block discarded – undo
2444 2443
 					// attach files not for autosaving
2445 2444
 					elseif ($_formData['filemode'] == Vfs\Sharing::ATTACH && !$_autosaving)
2446 2445
 					{
2447
-						if (isset($attachment['file']) && parse_url($attachment['file'],PHP_URL_SCHEME) == 'vfs')
2446
+						if (isset($attachment['file']) && parse_url($attachment['file'], PHP_URL_SCHEME) == 'vfs')
2448 2447
 						{
2449 2448
 							Vfs::load_wrapper('vfs');
2450 2449
 							$tmp_path = $attachment['file'];
@@ -2453,7 +2452,7 @@  discard block
 block discarded – undo
2453 2452
 						{
2454 2453
 							$tmp_path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($attachment['file']);
2455 2454
 						}
2456
-						$_mailObject->addAttachment (
2455
+						$_mailObject->addAttachment(
2457 2456
 							$tmp_path,
2458 2457
 							$attachment['name'],
2459 2458
 							$attachment['type']
@@ -2463,7 +2462,7 @@  discard block
 block discarded – undo
2463 2462
 			}
2464 2463
 			if ($connection_opened) $mail_bo->closeConnection();
2465 2464
 		}
2466
-		return is_array($inline_images)?$inline_images:array();
2465
+		return is_array($inline_images) ? $inline_images : array();
2467 2466
 	}
2468 2467
 
2469 2468
 	/**
@@ -2479,16 +2478,16 @@  discard block
 block discarded – undo
2479 2478
 	 * @param string $password =null
2480 2479
 	 * @return string might be empty if no file attachments found
2481 2480
 	 */
2482
-	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
2481
+	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients = array(), $expiration = null, $password = null)
2483 2482
 	{
2484 2483
 		if ($filemode == Vfs\Sharing::ATTACH) return '';
2485 2484
 
2486 2485
 		$links = array();
2487
-		foreach($attachments as $attachment)
2486
+		foreach ($attachments as $attachment)
2488 2487
 		{
2489 2488
 			$path = $attachment['file'];
2490
-			if (empty($path)) continue;	// we only care about file attachments, not forwarded messages or parts
2491
-			if (parse_url($attachment['file'],PHP_URL_SCHEME) != 'vfs')
2489
+			if (empty($path)) continue; // we only care about file attachments, not forwarded messages or parts
2490
+			if (parse_url($attachment['file'], PHP_URL_SCHEME) != 'vfs')
2492 2491
 			{
2493 2492
 				$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($path);
2494 2493
 			}
@@ -2518,7 +2517,7 @@  discard block
 block discarded – undo
2518 2517
 		}
2519 2518
 		if (!$links)
2520 2519
 		{
2521
-			return null;	// no file attachments found
2520
+			return null; // no file attachments found
2522 2521
 		}
2523 2522
 		elseif ($html)
2524 2523
 		{
@@ -2533,7 +2532,7 @@  discard block
 block discarded – undo
2533 2532
 	 * @param array $content content sent from client-side
2534 2533
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2535 2534
 	 */
2536
-	public function ajax_saveAsDraft ($content, $action='button[saveAsDraft]')
2535
+	public function ajax_saveAsDraft($content, $action = 'button[saveAsDraft]')
2537 2536
 	{
2538 2537
 		//error_log(__METHOD__.__LINE__.array2string($content)."(, action=$action)");
2539 2538
 		$response = Api\Json\Response::get();
@@ -2547,8 +2546,8 @@  discard block
 block discarded – undo
2547 2546
 
2548 2547
 		$formData = array_merge($content, array(
2549 2548
 			'isDrafted' => 1,
2550
-			'body' => $content['mail_'.($content['mimeType']?'htmltext':'plaintext')],
2551
-			'mimeType' => $content['mimeType']?'html':'plain' // checkbox has only true|false value
2549
+			'body' => $content['mail_'.($content['mimeType'] ? 'htmltext' : 'plaintext')],
2550
+			'mimeType' => $content['mimeType'] ? 'html' : 'plain' // checkbox has only true|false value
2552 2551
 		));
2553 2552
 
2554 2553
 		//Saving draft procedure
@@ -2560,8 +2559,8 @@  discard block
 block discarded – undo
2560 2559
 			if (($messageUid = $this->saveAsDraft($formData, $folder, $action)))
2561 2560
 			{
2562 2561
 				// saving as draft, does not mean closing the message
2563
-				$messageUid = ($messageUid===true ? $status['uidnext'] : $messageUid);
2564
-				if (is_array($this->mail_bo->getMessageHeader($messageUid, '',false, false, $folder)))
2562
+				$messageUid = ($messageUid === true ? $status['uidnext'] : $messageUid);
2563
+				if (is_array($this->mail_bo->getMessageHeader($messageUid, '', false, false, $folder)))
2565 2564
 				{
2566 2565
 					$draft_id = mail_ui::generateRowID($this->mail_bo->profileID, $folder, $messageUid);
2567 2566
 					if ($content['lastDrafted'] != $draft_id && isset($content['lastDrafted']))
@@ -2570,7 +2569,7 @@  discard block
 block discarded – undo
2570 2569
 						$duid = $dhA['msgUID'];
2571 2570
 						$dmailbox = $dhA['folder'];
2572 2571
 						// beware: do not delete the original mail as found in processedmail_id
2573
-						$pMuid='';
2572
+						$pMuid = '';
2574 2573
 						if ($content['processedmail_id'])
2575 2574
 						{
2576 2575
 							$pMhA = mail_ui::splitRowID($content['processedmail_id']);
@@ -2578,15 +2577,15 @@  discard block
 block discarded – undo
2578 2577
 						}
2579 2578
 						//error_log(__METHOD__.__LINE__."#$pMuid#$pMuid!=$duid#".array2string($content['attachments']));
2580 2579
 						// do not delete the original message if attachments are present
2581
-						if (empty($pMuid) || $pMuid!=$duid || empty($content['attachments']))
2580
+						if (empty($pMuid) || $pMuid != $duid || empty($content['attachments']))
2582 2581
 						{
2583 2582
 							try
2584 2583
 							{
2585
-								$this->mail_bo->deleteMessages($duid,$dmailbox,'remove_immediately');
2584
+								$this->mail_bo->deleteMessages($duid, $dmailbox, 'remove_immediately');
2586 2585
 							}
2587 2586
 							catch (Api\Exception $e)
2588 2587
 							{
2589
-								$msg = str_replace('"',"'",$e->getMessage());
2588
+								$msg = str_replace('"', "'", $e->getMessage());
2590 2589
 								$success = false;
2591 2590
 								error_log(__METHOD__.__LINE__.$msg);
2592 2591
 							}
@@ -2607,7 +2606,7 @@  discard block
 block discarded – undo
2607 2606
 		}
2608 2607
 		catch (Api\Exception\WrongUserinput $e)
2609 2608
 		{
2610
-			$msg = str_replace('"',"'",$e->getMessage());
2609
+			$msg = str_replace('"', "'", $e->getMessage());
2611 2610
 			error_log(__METHOD__.__LINE__.$msg);
2612 2611
 			$success = false;
2613 2612
 		}
@@ -2631,17 +2630,17 @@  discard block
 block discarded – undo
2631 2630
 	static function resolveEmailAddressList($_emailAddressList)
2632 2631
 	{
2633 2632
 		$contacts_obs = null;
2634
-		$addrFromList=array();
2635
-		foreach((array)$_emailAddressList as $ak => $address)
2633
+		$addrFromList = array();
2634
+		foreach ((array)$_emailAddressList as $ak => $address)
2636 2635
 		{
2637
-			if(is_int($address))
2636
+			if (is_int($address))
2638 2637
 			{
2639 2638
 				if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts();
2640 2639
 				// List was selected, expand to addresses
2641 2640
 				unset($_emailAddressList[$ak]);
2642
-				$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));
2641
+				$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));
2643 2642
 				// Just add email addresses, they'll be checked below
2644
-				foreach($list as $email)
2643
+				foreach ($list as $email)
2645 2644
 				{
2646 2645
 					$addrFromList[] = $email['email'] ? $email['email'] : $email['email_home'];
2647 2646
 				}
@@ -2651,7 +2650,7 @@  discard block
 block discarded – undo
2651 2650
 		{
2652 2651
 			foreach ($addrFromList as $addr)
2653 2652
 			{
2654
-				if (!empty($addr)) $_emailAddressList[]=$addr;
2653
+				if (!empty($addr)) $_emailAddressList[] = $addr;
2655 2654
 			}
2656 2655
 		}
2657 2656
 		return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList;
@@ -2665,15 +2664,15 @@  discard block
 block discarded – undo
2665 2664
 	 * @param string $action ='button[saveAsDraft]' 'autosaving', 'button[saveAsDraft]' or 'button[saveAsDraftAndPrint]'
2666 2665
 	 * @return boolean return messageUID| false due to an error
2667 2666
 	 */
2668
-	function saveAsDraft($_formData, &$savingDestination='', $action='button[saveAsDraft]')
2667
+	function saveAsDraft($_formData, &$savingDestination = '', $action = 'button[saveAsDraft]')
2669 2668
 	{
2670 2669
 		//error_log(__METHOD__."(..., $savingDestination, action=$action)");
2671
-		$mail_bo	= $this->mail_bo;
2672
-		$mail		= new Api\Mailer($this->mail_bo->profileID);
2670
+		$mail_bo = $this->mail_bo;
2671
+		$mail = new Api\Mailer($this->mail_bo->profileID);
2673 2672
 
2674 2673
 		// preserve the bcc and if possible the save to folder information
2675
-		$this->sessionData['folder']    = $_formData['folder'];
2676
-		$this->sessionData['bcc']   = $_formData['bcc'];
2674
+		$this->sessionData['folder'] = $_formData['folder'];
2675
+		$this->sessionData['bcc'] = $_formData['bcc'];
2677 2676
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2678 2677
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2679 2678
 		$this->sessionData['mailaccount']  = $_formData['mailaccount'];
@@ -2682,11 +2681,11 @@  discard block
 block discarded – undo
2682 2681
 		{
2683 2682
 			$acc = Mail\Account::read($this->sessionData['mailaccount']);
2684 2683
 			//error_log(__METHOD__.__LINE__.array2string($acc));
2685
-			$identity = Mail\Account::read_identity($acc['ident_id'],true);
2684
+			$identity = Mail\Account::read_identity($acc['ident_id'], true);
2686 2685
 		}
2687 2686
 		catch (Exception $e)
2688 2687
 		{
2689
-			$identity=array();
2688
+			$identity = array();
2690 2689
 		}
2691 2690
 
2692 2691
 		$flags = '\\Seen \\Draft';
@@ -2696,7 +2695,7 @@  discard block
 block discarded – undo
2696 2695
 		// folder list as Customheader
2697 2696
 		if (!empty($this->sessionData['folder']))
2698 2697
 		{
2699
-			$folders = implode('|',array_unique($this->sessionData['folder']));
2698
+			$folders = implode('|', array_unique($this->sessionData['folder']));
2700 2699
 			$mail->addHeader('X-Mailfolder', $folders);
2701 2700
 		}
2702 2701
 		$mail->addHeader('X-Mailidentity', $this->sessionData['mailidentity']);
@@ -2716,25 +2715,25 @@  discard block
 block discarded – undo
2716 2715
 			$savingDestination = $this->sessionData['messageFolder'];
2717 2716
 			//error_log(__METHOD__.__LINE__.' SavingDestination:'.$savingDestination);
2718 2717
 		}
2719
-		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 ) $savingDestination = $mail_bo->getDraftFolder();
2718
+		if (!empty($_formData['printit']) && $_formData['printit'] == 0) $savingDestination = $mail_bo->getDraftFolder();
2720 2719
 
2721 2720
 		// normaly Bcc is only added to recipients, but not as header visible to all recipients
2722 2721
 		$mail->forceBccHeader();
2723 2722
 
2724 2723
 		$mail_bo->openConnection();
2725
-		if ($mail_bo->folderExists($savingDestination,true)) {
2724
+		if ($mail_bo->folderExists($savingDestination, true)) {
2726 2725
 			try
2727 2726
 			{
2728 2727
 				$messageUid = $mail_bo->appendMessage($savingDestination, $mail->getRaw(), null, $flags);
2729 2728
 			}
2730 2729
 			catch (Api\Exception\WrongUserinput $e)
2731 2730
 			{
2732
-				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",__METHOD__,$savingDestination,$e->getMessage()));
2731
+				error_log(__METHOD__.__LINE__.lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", __METHOD__, $savingDestination, $e->getMessage()));
2733 2732
 				return false;
2734 2733
 			}
2735 2734
 
2736 2735
 		} else {
2737
-			error_log(__METHOD__.__LINE__."->".lang("folder")." ". $savingDestination." ".lang("does not exist on IMAP Server."));
2736
+			error_log(__METHOD__.__LINE__."->".lang("folder")." ".$savingDestination." ".lang("does not exist on IMAP Server."));
2738 2737
 			return false;
2739 2738
 		}
2740 2739
 		$mail_bo->closeConnection();
@@ -2743,26 +2742,26 @@  discard block
 block discarded – undo
2743 2742
 
2744 2743
 	function send($_formData)
2745 2744
 	{
2746
-		$mail_bo	= $this->mail_bo;
2747
-		$mail 		= new Api\Mailer($mail_bo->profileID);
2748
-		$messageIsDraft	=  false;
2745
+		$mail_bo = $this->mail_bo;
2746
+		$mail = new Api\Mailer($mail_bo->profileID);
2747
+		$messageIsDraft = false;
2749 2748
 
2750
-		$this->sessionData['mailaccount']	= $_formData['mailaccount'];
2749
+		$this->sessionData['mailaccount'] = $_formData['mailaccount'];
2751 2750
 		$this->sessionData['to']	= self::resolveEmailAddressList($_formData['to']);
2752 2751
 		$this->sessionData['cc']	= self::resolveEmailAddressList($_formData['cc']);
2753
-		$this->sessionData['bcc']	= self::resolveEmailAddressList($_formData['bcc']);
2754
-		$this->sessionData['folder']	= $_formData['folder'];
2752
+		$this->sessionData['bcc'] = self::resolveEmailAddressList($_formData['bcc']);
2753
+		$this->sessionData['folder'] = $_formData['folder'];
2755 2754
 		$this->sessionData['replyto']	= $_formData['replyto'];
2756 2755
 		$this->sessionData['subject']	= trim($_formData['subject']);
2757
-		$this->sessionData['body']	= $_formData['body'];
2758
-		$this->sessionData['priority']	= $_formData['priority'];
2756
+		$this->sessionData['body'] = $_formData['body'];
2757
+		$this->sessionData['priority'] = $_formData['priority'];
2759 2758
 		$this->sessionData['mailidentity'] = $_formData['mailidentity'];
2760 2759
 		//$this->sessionData['stationeryID'] = $_formData['stationeryID'];
2761 2760
 		$this->sessionData['disposition'] = $_formData['disposition'];
2762
-		$this->sessionData['mimeType']	= $_formData['mimeType'];
2761
+		$this->sessionData['mimeType'] = $_formData['mimeType'];
2763 2762
 		$this->sessionData['to_infolog'] = $_formData['to_infolog'];
2764 2763
 		$this->sessionData['to_tracker'] = $_formData['to_tracker'];
2765
-		$this->sessionData['attachments']  = $_formData['attachments'];
2764
+		$this->sessionData['attachments'] = $_formData['attachments'];
2766 2765
 
2767 2766
 		if (isset($_formData['lastDrafted']) && !empty($_formData['lastDrafted']))
2768 2767
 		{
@@ -2771,11 +2770,11 @@  discard block
 block discarded – undo
2771 2770
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_formData['mode'].' PID:'.$_formData['processedmail_id']);
2772 2771
 		if (isset($_formData['mode']) && !empty($_formData['mode']))
2773 2772
 		{
2774
-			if ($_formData['mode']=='forward' && !empty($_formData['processedmail_id']))
2773
+			if ($_formData['mode'] == 'forward' && !empty($_formData['processedmail_id']))
2775 2774
 			{
2776
-				$this->sessionData['forwardFlag']='forwarded';
2777
-				$_formData['processedmail_id'] = explode(',',$_formData['processedmail_id']);
2778
-				$this->sessionData['uid']=array();
2775
+				$this->sessionData['forwardFlag'] = 'forwarded';
2776
+				$_formData['processedmail_id'] = explode(',', $_formData['processedmail_id']);
2777
+				$this->sessionData['uid'] = array();
2779 2778
 				foreach ($_formData['processedmail_id'] as $k =>$rowid)
2780 2779
 				{
2781 2780
 					$fhA = mail_ui::splitRowID($rowid);
@@ -2784,13 +2783,13 @@  discard block
 block discarded – undo
2784 2783
 					if (!empty($fhA['folder'])) $this->sessionData['sourceFolder'] = $fhA['folder'];
2785 2784
 				}
2786 2785
 			}
2787
-			if ($_formData['mode']=='reply' && !empty($_formData['processedmail_id']))
2786
+			if ($_formData['mode'] == 'reply' && !empty($_formData['processedmail_id']))
2788 2787
 			{
2789 2788
 				$rhA = mail_ui::splitRowID($_formData['processedmail_id']);
2790 2789
 				$this->sessionData['uid'] = $rhA['msgUID'];
2791 2790
 				$this->sessionData['messageFolder'] = $rhA['folder'];
2792 2791
 			}
2793
-			if ($_formData['mode']=='composefromdraft' && !empty($_formData['processedmail_id']))
2792
+			if ($_formData['mode'] == 'composefromdraft' && !empty($_formData['processedmail_id']))
2794 2793
 			{
2795 2794
 				$dhA = mail_ui::splitRowID($_formData['processedmail_id']);
2796 2795
 				$this->sessionData['uid'] = $dhA['msgUID'];
@@ -2799,26 +2798,26 @@  discard block
 block discarded – undo
2799 2798
 		}
2800 2799
 		// if the body is empty, maybe someone pasted something with scripts, into the message body
2801 2800
 		// this should not happen anymore, unless you call send directly, since the check was introduced with the action command
2802
-		if(empty($this->sessionData['body']))
2801
+		if (empty($this->sessionData['body']))
2803 2802
 		{
2804 2803
 			// this is to be found with the egw_unset_vars array for the _POST['body'] array
2805
-			$name='_POST';
2806
-			$key='body';
2804
+			$name = '_POST';
2805
+			$key = 'body';
2807 2806
 			#error_log($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2808 2807
 			if (isset($GLOBALS['egw_unset_vars'][$name.'['.$key.']']))
2809 2808
 			{
2810
-				$this->sessionData['body'] = self::_getCleanHTML( $GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2811
-				$_formData['body']=$this->sessionData['body'];
2809
+				$this->sessionData['body'] = self::_getCleanHTML($GLOBALS['egw_unset_vars'][$name.'['.$key.']']);
2810
+				$_formData['body'] = $this->sessionData['body'];
2812 2811
 			}
2813 2812
 			#error_log($this->sessionData['body']);
2814 2813
 		}
2815
-		if(empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2814
+		if (empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2816 2815
 		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder'])) {
2817 2816
 		   	$messageIsDraft = true;
2818 2817
 		}
2819 2818
 		try
2820 2819
 		{
2821
-			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'],true);
2820
+			$identity = Mail\Account::read_identity((int)$this->sessionData['mailidentity'], true);
2822 2821
 		}
2823 2822
 		catch (Exception $e)
2824 2823
 		{
@@ -2829,7 +2828,7 @@  discard block
 block discarded – undo
2829 2828
 		// create the messages and store inline images
2830 2829
 		$inline_images = $this->createMessage($mail, $_formData, $identity);
2831 2830
 		// remember the identity
2832
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2831
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From; //$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2833 2832
 		#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
2834 2833
 		#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";
2835 2834
 		#exit;
@@ -2840,12 +2839,12 @@  discard block
 block discarded – undo
2840 2839
 		$folderOnMailAccount = array();
2841 2840
 		foreach ($folderToCheck as $k => $f)
2842 2841
 		{
2843
-			$fval=$f;
2844
-			$icServerID = $_formData['serverID'];//folders always assumed with serverID
2845
-			if (stripos($f,'::')!==false) list($icServerID,$fval) = explode('::',$f,2);
2846
-			if ($_formData['serverID']!=$_formData['mailaccount'])
2842
+			$fval = $f;
2843
+			$icServerID = $_formData['serverID']; //folders always assumed with serverID
2844
+			if (stripos($f, '::') !== false) list($icServerID, $fval) = explode('::', $f, 2);
2845
+			if ($_formData['serverID'] != $_formData['mailaccount'])
2847 2846
 			{
2848
-				if ($icServerID == $_formData['serverID'] )
2847
+				if ($icServerID == $_formData['serverID'])
2849 2848
 				{
2850 2849
 					$folder[$fval] = $fval;
2851 2850
 					$folderOnServerID[] = $fval;
@@ -2858,7 +2857,7 @@  discard block
 block discarded – undo
2858 2857
 			}
2859 2858
 			else
2860 2859
 			{
2861
-				if ($icServerID == $_formData['serverID'] )
2860
+				if ($icServerID == $_formData['serverID'])
2862 2861
 				{
2863 2862
 					$folder[$fval] = $fval;
2864 2863
 					$folderOnServerID[] = $fval;
@@ -2875,7 +2874,7 @@  discard block
 block discarded – undo
2875 2874
 		// we use the sentFolder settings of the choosen mailaccount
2876 2875
 		// sentFolder is account specific
2877 2876
 		$changeProfileOnSentFolderNeeded = false;
2878
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2877
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2879 2878
 		{
2880 2879
 			$this->changeProfile($_formData['mailaccount']);
2881 2880
 			//error_log(__METHOD__.__LINE__.'#'.$this->mail_bo->profileID.'<->'.$mail_bo->profileID.'#');
@@ -2883,30 +2882,30 @@  discard block
 block discarded – undo
2883 2882
 			// sentFolder is account specific
2884 2883
 			$sentFolder = $this->mail_bo->getSentFolder();
2885 2884
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2886
-			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2885
+			if ($sentFolder && $sentFolder != 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2887 2886
 		}
2888 2887
 		else
2889 2888
 		{
2890 2889
 			$sentFolder = $mail_bo->getSentFolder();
2891 2890
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2892
-			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
2891
+			if ($sentFolder && $sentFolder != 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder = false;
2893 2892
 		}
2894 2893
 		//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2895 2894
 
2896 2895
 		// we switch $this->mail_bo back to the account we used to work on
2897
-		if ($_formData['serverID']!=$_formData['mailaccount'])
2896
+		if ($_formData['serverID'] != $_formData['mailaccount'])
2898 2897
 		{
2899 2898
 			$this->changeProfile($_formData['serverID']);
2900 2899
 		}
2901 2900
 
2902 2901
 
2903
-		if(isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2902
+		if (isset($sentFolder) && $sentFolder && $sentFolder != 'none' &&
2904 2903
 			$this->mailPreferences['sendOptions'] != 'send_only' &&
2905 2904
 			$messageIsDraft == false)
2906 2905
 		{
2907 2906
 			if ($sentFolder)
2908 2907
 			{
2909
-				if ($_formData['serverID']!=$_formData['mailaccount'])
2908
+				if ($_formData['serverID'] != $_formData['mailaccount'])
2910 2909
 				{
2911 2910
 					$folderOnMailAccount[] = $sentFolder;
2912 2911
 				}
@@ -2923,14 +2922,14 @@  discard block
 block discarded – undo
2923 2922
 		}
2924 2923
 		else
2925 2924
 		{
2926
-			if (((!isset($sentFolder)||$sentFolder==false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2925
+			if (((!isset($sentFolder) || $sentFolder == false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2927 2926
 				($this->mailPreferences['sendOptions'] != 'send_only' &&
2928 2927
 				$sentFolder != 'none')) $this->errorInfo = lang("No Send Folder set in preferences");
2929 2928
 		}
2930 2929
 		// draftFolder is on Server we start from
2931
-		if($messageIsDraft == true) {
2930
+		if ($messageIsDraft == true) {
2932 2931
 			$draftFolder = $mail_bo->getDraftFolder();
2933
-			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true)) {
2932
+			if (!empty($draftFolder) && $mail_bo->folderExists($draftFolder, true)) {
2934 2933
 				$this->sessionData['folder'] = array($draftFolder);
2935 2934
 				$folderOnServerID[] = $draftFolder;
2936 2935
 				$folder[$draftFolder] = $draftFolder;
@@ -2939,10 +2938,10 @@  discard block
 block discarded – undo
2939 2938
 		if ($folderOnServerID) $folderOnServerID = array_unique($folderOnServerID);
2940 2939
 		if ($folderOnMailAccount) $folderOnMailAccount = array_unique($folderOnMailAccount);
2941 2940
 		if (($this->mailPreferences['sendOptions'] != 'send_only' && $sentFolder != 'none') &&
2942
-			!( count($folder) > 0) &&
2943
-			!($_formData['to_infolog']=='on' || $_formData['to_tracker']=='on'))
2941
+			!(count($folder) > 0) &&
2942
+			!($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on'))
2944 2943
 		{
2945
-			$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:'');
2944
+			$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 : '');
2946 2945
 			#error_log($this->errorInfo);
2947 2946
 			return false;
2948 2947
 		}
@@ -2951,18 +2950,18 @@  discard block
 block discarded – undo
2951 2950
 		@set_time_limit(120);
2952 2951
 		//$mail->SMTPDebug = 10;
2953 2952
 		//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']));
2954
-		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2953
+		if (count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
2955 2954
 			try {
2956 2955
 				$mail->send();
2957 2956
 			}
2958
-			catch(Exception $e) {
2957
+			catch (Exception $e) {
2959 2958
 				_egw_log_exception($e);
2960 2959
 				//if( $e->details ) error_log(__METHOD__.__LINE__.array2string($e->details));
2961
-				$this->errorInfo = $e->getMessage().($e->details?'<br/>'.$e->details:'');
2960
+				$this->errorInfo = $e->getMessage().($e->details ? '<br/>'.$e->details : '');
2962 2961
 				return false;
2963 2962
 			}
2964 2963
 		} else {
2965
-			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder'])) {
2964
+			if (count(array($this->sessionData['folder'])) > 0 && !empty($this->sessionData['folder'])) {
2966 2965
 				//error_log(__METHOD__.__LINE__."Folders:".print_r($this->sessionData['folder'],true));
2967 2966
 			} else {
2968 2967
 				$this->errorInfo = lang("Error: ").lang("No Address TO/CC/BCC supplied, and no folder to save message to provided.");
@@ -2990,15 +2989,15 @@  discard block
 block discarded – undo
2990 2989
 		// copying mail to folder
2991 2990
 		if (count($folder) > 0)
2992 2991
 		{
2993
-			foreach($folderOnServerID as $folderName) {
2992
+			foreach ($folderOnServerID as $folderName) {
2994 2993
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
2995 2994
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
2996 2995
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
2997 2996
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
2998
-				if ($mail_bo->folderExists($folderName,true)) {
2999
-					if($mail_bo->isSentFolder($folderName)) {
2997
+				if ($mail_bo->folderExists($folderName, true)) {
2998
+					if ($mail_bo->isSentFolder($folderName)) {
3000 2999
 						$flags = '\\Seen';
3001
-					} elseif($mail_bo->isDraftFolder($folderName)) {
3000
+					} elseif ($mail_bo->isDraftFolder($folderName)) {
3002 3001
 						$flags = '\\Draft';
3003 3002
 					} else {
3004 3003
 						$flags = '\\Seen';
@@ -3014,25 +3013,25 @@  discard block
 block discarded – undo
3014 3013
 					}
3015 3014
 					catch (Api\Exception\WrongUserinput $e)
3016 3015
 					{
3017
-						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()));
3016
+						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()));
3018 3017
 					}
3019 3018
 				}
3020 3019
 				else
3021 3020
 				{
3022
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3021
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3023 3022
 				}
3024 3023
 			}
3025 3024
 			// if we choose to send from a differing profile
3026 3025
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['mailaccount']);
3027
-			foreach($folderOnMailAccount as $folderName) {
3026
+			foreach ($folderOnMailAccount as $folderName) {
3028 3027
 				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3029 3028
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3030 3029
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3031 3030
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3032
-				if ($this->mail_bo->folderExists($folderName,true)) {
3033
-					if($this->mail_bo->isSentFolder($folderName)) {
3031
+				if ($this->mail_bo->folderExists($folderName, true)) {
3032
+					if ($this->mail_bo->isSentFolder($folderName)) {
3034 3033
 						$flags = '\\Seen';
3035
-					} elseif($this->mail_bo->isDraftFolder($folderName)) {
3034
+					} elseif ($this->mail_bo->isDraftFolder($folderName)) {
3036 3035
 						$flags = '\\Draft';
3037 3036
 					} else {
3038 3037
 						$flags = '\\Seen';
@@ -3048,12 +3047,12 @@  discard block
 block discarded – undo
3048 3047
 					}
3049 3048
 					catch (Api\Exception\WrongUserinput $e)
3050 3049
 					{
3051
-						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()));
3050
+						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()));
3052 3051
 					}
3053 3052
 				}
3054 3053
 				else
3055 3054
 				{
3056
-					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3055
+					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $this->sessionData['subject'], $folderName));
3057 3056
 				}
3058 3057
 			}
3059 3058
 			if ($folderOnMailAccount)  $this->changeProfile($_formData['serverID']);
@@ -3064,27 +3063,27 @@  discard block
 block discarded – undo
3064 3063
 		$lastDrafted = false;
3065 3064
 		if (isset($this->sessionData['lastDrafted']))
3066 3065
 		{
3067
-			$lastDrafted=array();
3066
+			$lastDrafted = array();
3068 3067
 			$dhA = mail_ui::splitRowID($this->sessionData['lastDrafted']);
3069 3068
 			$lastDrafted['uid'] = $dhA['msgUID'];
3070 3069
 			$lastDrafted['folder'] = $dhA['folder'];
3071
-			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
3070
+			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid'] = trim($lastDrafted['uid']);
3072 3071
 			// manually drafted, do not delete
3073 3072
 			// will be handled later on IF mode was $_formData['mode']=='composefromdraft'
3074
-			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
3073
+			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted = false;
3075 3074
 			//error_log(__METHOD__.__LINE__.array2string($lastDrafted));
3076 3075
 		}
3077 3076
 		if ($lastDrafted && is_array($lastDrafted) && $mail_bo->isDraftFolder($lastDrafted['folder']))
3078 3077
 		{
3079 3078
 			try
3080 3079
 			{
3081
-				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode']=='composefromdraft' &&
3082
-					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )&&$this->sessionData['attachments']))
3080
+				if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode'] == 'composefromdraft' &&
3081
+					($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3083 3082
 				{
3084 3083
 					//error_log(__METHOD__.__LINE__."#".$lastDrafted['uid'].'#'.$lastDrafted['folder'].array2string($_formData));
3085 3084
 					//error_log(__METHOD__.__LINE__."#".array2string($_formData));
3086 3085
 					//error_log(__METHOD__.__LINE__."#".array2string($this->sessionData));
3087
-					$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
3086
+					$mail_bo->deleteMessages($lastDrafted['uid'], $lastDrafted['folder'], 'remove_immediately');
3088 3087
 				}
3089 3088
 			}
3090 3089
 			catch (Api\Exception $e)
@@ -3096,22 +3095,22 @@  discard block
 block discarded – undo
3096 3095
 		unset($this->sessionData['lastDrafted']);
3097 3096
 
3098 3097
 		//error_log("handling draft messages, flagging and such");
3099
-		if((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3098
+		if ((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3100 3099
 			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3101 3100
 			// mark message as answered
3102 3101
 			$mail_bo->openConnection();
3103
-			$mail_bo->reopen(($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3102
+			$mail_bo->reopen(($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3104 3103
 			// if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send
3105 3104
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
3106 3105
 			if ($mail_bo->isDraftFolder($this->sessionData['messageFolder']) && !$mail_bo->isTemplateFolder($this->sessionData['messageFolder']))
3107 3106
 			{
3108 3107
 				try // message may be deleted already, as it maybe done by autosave
3109 3108
 				{
3110
-					if ($_formData['mode']=='composefromdraft' &&
3109
+					if ($_formData['mode'] == 'composefromdraft' &&
3111 3110
 						!(($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
3112 3111
 					{
3113 3112
 						//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
3114
-						$mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder']);
3113
+						$mail_bo->deleteMessages(array($this->sessionData['uid']), $this->sessionData['messageFolder']);
3115 3114
 					}
3116 3115
 				}
3117 3116
 				catch (Api\Exception $e)
@@ -3120,14 +3119,14 @@  discard block
 block discarded – undo
3120 3119
 					unset($e);
3121 3120
 				}
3122 3121
 			} else {
3123
-				$mail_bo->flagMessages("answered", $this->sessionData['uid'],($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3122
+				$mail_bo->flagMessages("answered", $this->sessionData['uid'], ($this->sessionData['messageFolder'] ? $this->sessionData['messageFolder'] : $this->sessionData['sourceFolder']));
3124 3123
 				//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)).':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3125
-				if (array_key_exists('forwardFlag',$this->sessionData) && $this->sessionData['forwardFlag']=='forwarded')
3124
+				if (array_key_exists('forwardFlag', $this->sessionData) && $this->sessionData['forwardFlag'] == 'forwarded')
3126 3125
 				{
3127 3126
 					try
3128 3127
 					{
3129 3128
 						//error_log(__METHOD__.__LINE__.':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3130
-						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'],$this->sessionData['sourceFolder']);
3129
+						$mail_bo->flagMessages("forwarded", $this->sessionData['forwardedUID'], $this->sessionData['sourceFolder']);
3131 3130
 					}
3132 3131
 					catch (Api\Exception $e)
3133 3132
 					{
@@ -3155,49 +3154,49 @@  discard block
 block discarded – undo
3155 3154
 		if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc'];
3156 3155
 		if (!empty($mailaddresses)) $mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3157 3156
 
3158
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )
3157
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on')
3159 3158
 		{
3160 3159
 			$this->sessionData['attachments'] = array_merge((array)$this->sessionData['attachments'], (array)$inline_images);
3161 3160
 
3162
-			foreach(array('to_infolog','to_tracker','to_calendar') as $app_key)
3161
+			foreach (array('to_infolog', 'to_tracker', 'to_calendar') as $app_key)
3163 3162
 			{
3164 3163
 				$entryid = $_formData['to_integrate_ids'][0][$app_key];
3165 3164
 				if ($_formData[$app_key] == 'on')
3166 3165
 				{
3167
-					$app_name = substr($app_key,3);
3166
+					$app_name = substr($app_key, 3);
3168 3167
 					// Get registered hook data of the app called for integration
3169
-					$hook = Api\Hooks::single(array('location'=> 'mail_import'),$app_name);
3168
+					$hook = Api\Hooks::single(array('location'=> 'mail_import'), $app_name);
3170 3169
 
3171 3170
 					// store mail / eml in temp. file to not have to download it from mail-server again
3172
-					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'mail_integrate');
3171
+					$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'mail_integrate');
3173 3172
 					$eml_fp = fopen($eml, 'w');
3174 3173
 					stream_copy_to_stream($mail->getRaw(), $eml_fp);
3175 3174
 					fclose($eml_fp);
3176 3175
 					$target = array(
3177 3176
 						'menuaction' => $hook['menuaction'],
3178
-						'egw_data' => Link::set_data(null,'mail_integration::integrate',array(
3177
+						'egw_data' => Link::set_data(null, 'mail_integration::integrate', array(
3179 3178
 							$mailaddresses,
3180 3179
 							$this->sessionData['subject'],
3181 3180
 							$this->convertHTMLToText($this->sessionData['body']),
3182 3181
 							$this->sessionData['attachments'],
3183 3182
 							false, // date
3184 3183
 							$eml,
3185
-							$_formData['serverID']),true),
3184
+							$_formData['serverID']), true),
3186 3185
 						'app' => $app_name
3187 3186
 					);
3188 3187
 					if ($entryid) $target['entry_id'] = $entryid;
3189 3188
 					// Open the app called for integration in a popup
3190 3189
 					// and store the mail raw data as egw_data, in order to
3191 3190
 					// be stored from registered app method later
3192
-					Framework::popup(Egw::link('/index.php', $target),'_blank',$hook['popup']);
3191
+					Framework::popup(Egw::link('/index.php', $target), '_blank', $hook['popup']);
3193 3192
 				}
3194 3193
 			}
3195 3194
 		}
3196 3195
 		// only clean up temp-files, if we dont need them for mail_integration::integrate
3197
-		elseif(is_array($this->sessionData['attachments']))
3196
+		elseif (is_array($this->sessionData['attachments']))
3198 3197
 		{
3199
-			foreach($this->sessionData['attachments'] as $value) {
3200
-				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3198
+			foreach ($this->sessionData['attachments'] as $value) {
3199
+				if (!empty($value['file']) && parse_url($value['file'], PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3201 3200
 					unlink($GLOBALS['egw_info']['server']['temp_dir'].'/'.$value['file']);
3202 3201
 				}
3203 3202
 			}
@@ -3214,7 +3213,7 @@  discard block
 block discarded – undo
3214 3213
 	 * @param array $content
3215 3214
 	 * @return array - the input, enriched with some not set attributes
3216 3215
 	 */
3217
-	function setDefaults($content=array())
3216
+	function setDefaults($content = array())
3218 3217
 	{
3219 3218
 		// if there's not already an identity selected for current account
3220 3219
 		if (empty($content['mailidentity']))
@@ -3223,7 +3222,7 @@  discard block
 block discarded – undo
3223 3222
 			if (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed']))
3224 3223
 			{
3225 3224
 				$sigPref = $GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed'];
3226
-				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID]>0)
3225
+				if (!empty($sigPref[$this->mail_bo->profileID]) && $sigPref[$this->mail_bo->profileID] > 0)
3227 3226
 				{
3228 3227
 					$content['mailidentity'] = $sigPref[$this->mail_bo->profileID];
3229 3228
 				}
@@ -3232,7 +3231,7 @@  discard block
 block discarded – undo
3232 3231
 			if (empty($content['mailidentity']))
3233 3232
 			{
3234 3233
 				$default_identity = null;
3235
-				foreach(Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3234
+				foreach (Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3236 3235
 				{
3237 3236
 					if (!isset($default_identity)) $default_identity = $identity['ident_id'];
3238 3237
 					if (!empty($identity['ident_signature']))
@@ -3247,7 +3246,7 @@  discard block
 block discarded – undo
3247 3246
 		if (!isset($content['mimeType']) || empty($content['mimeType']))
3248 3247
 		{
3249 3248
 			$content['mimeType'] = 'html';
3250
-			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text") $content['mimeType']  = 'plain';
3249
+			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions'] == "text") $content['mimeType'] = 'plain';
3251 3250
 		}
3252 3251
 		return $content;
3253 3252
 
@@ -3270,7 +3269,7 @@  discard block
 block discarded – undo
3270 3269
 	 * @param boolean $_noPrefixId = false, if set to true folders name does not get prefixed by account id
3271 3270
 	 * @return type
3272 3271
 	 */
3273
-	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false) {
3272
+	function ajax_searchFolder($_searchStringLength = 2, $_returnList = false, $_mailaccountToSearch = null, $_noPrefixId = false) {
3274 3273
 		//error_log(__METHOD__.__LINE__.':'.array2string($_REQUEST));
3275 3274
 		static $useCacheIfPossible = null;
3276 3275
 		if (is_null($useCacheIfPossible)) $useCacheIfPossible = true;
@@ -3283,36 +3282,36 @@  discard block
 block discarded – undo
3283 3282
 		{
3284 3283
 			$this->changeProfile($_mailaccountToSearch);
3285 3284
 		}
3286
-		if (strlen($_searchString)>=$_searchStringLength && isset($this->mail_bo->icServer))
3285
+		if (strlen($_searchString) >= $_searchStringLength && isset($this->mail_bo->icServer))
3287 3286
 		{
3288 3287
 			//error_log(__METHOD__.__LINE__.':'.$this->mail_bo->icServer->ImapServerId);
3289 3288
 			$this->mail_bo->openConnection($this->mail_bo->icServer->ImapServerId);
3290 3289
 			//error_log(__METHOD__.__LINE__.array2string($_searchString).'<->'.$searchString);
3291
-			$folderObjects = $this->mail_bo->getFolderObjects(true,false,true,$useCacheIfPossible);
3292
-			if (count($folderObjects)<=1) {
3290
+			$folderObjects = $this->mail_bo->getFolderObjects(true, false, true, $useCacheIfPossible);
3291
+			if (count($folderObjects) <= 1) {
3293 3292
 				$useCacheIfPossible = false;
3294 3293
 			}
3295 3294
 			else
3296 3295
 			{
3297 3296
 				$useCacheIfPossible = true;
3298 3297
 			}
3299
-			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset,'UTF7-IMAP');
3298
+			$searchString = Api\Translation::convert($_searchString, Mail::$displayCharset, 'UTF7-IMAP');
3300 3299
 			foreach ($folderObjects as $k =>$fA)
3301 3300
 			{
3302 3301
 				//error_log(__METHOD__.__LINE__.$_searchString.'/'.$searchString.' in '.$k.'->'.$fA->displayName);
3303
-				$f=false;
3304
-				$key = $_noPrefixId?$k:$_mailaccountToSearch.'::'.$k;
3305
-				if ($_searchStringLength<=0)
3302
+				$f = false;
3303
+				$key = $_noPrefixId ? $k : $_mailaccountToSearch.'::'.$k;
3304
+				if ($_searchStringLength <= 0)
3306 3305
 				{
3307
-					$f=true;
3306
+					$f = true;
3308 3307
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3309 3308
 				}
3310
-				if ($f==false && stripos($fA->displayName,$_searchString)!==false)
3309
+				if ($f == false && stripos($fA->displayName, $_searchString) !== false)
3311 3310
 				{
3312
-					$f=true;
3311
+					$f = true;
3313 3312
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3314 3313
 				}
3315
-				if ($f==false && stripos($k,$searchString)!==false)
3314
+				if ($f == false && stripos($k, $searchString) !== false)
3316 3315
 				{
3317 3316
 					$results[] = array('id'=>$key, 'label' => htmlspecialchars($fA->displayName));
3318 3317
 				}
@@ -3340,7 +3339,7 @@  discard block
 block discarded – undo
3340 3339
 		exit();
3341 3340
 	}
3342 3341
 
3343
-	public static function ajax_searchAddress($_searchStringLength=2) {
3342
+	public static function ajax_searchAddress($_searchStringLength = 2) {
3344 3343
 		//error_log(__METHOD__. "request from seachAddress " . $_REQUEST['query']);
3345 3344
 		$_searchString = trim($_REQUEST['query']);
3346 3345
 		$include_lists = (boolean)$_REQUEST['include_lists'];
@@ -3349,7 +3348,7 @@  discard block
 block discarded – undo
3349 3348
 		$results = array();
3350 3349
 
3351 3350
 		// Add up to 5 matching mailing lists
3352
-		if($include_lists)
3351
+		if ($include_lists)
3353 3352
 		{
3354 3353
 			$lists = array_filter(
3355 3354
 				$contacts_obj->get_lists(Acl::READ),
@@ -3358,7 +3357,7 @@  discard block
 block discarded – undo
3358 3357
 				}
3359 3358
 			);
3360 3359
 			$list_count = 0;
3361
-			foreach($lists as $key => $list_name)
3360
+			foreach ($lists as $key => $list_name)
3362 3361
 			{
3363 3362
 				$results[] = array(
3364 3363
 					'id'	=> $key,
@@ -3368,11 +3367,11 @@  discard block
 block discarded – undo
3368 3367
 					'title' => lang('Mailinglist'),
3369 3368
 					'data'	=> $key
3370 3369
 				);
3371
-				if($list_count++ > 5) break;
3370
+				if ($list_count++ > 5) break;
3372 3371
 			}
3373 3372
 		}
3374 3373
 
3375
-		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString)>=$_searchStringLength)
3374
+		if ($GLOBALS['egw_info']['user']['apps']['addressbook'] && strlen($_searchString) >= $_searchStringLength)
3376 3375
 		{
3377 3376
 			//error_log(__METHOD__.__LINE__.array2string($_searchString));
3378 3377
 			$showAccounts = empty($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']);
@@ -3381,64 +3380,64 @@  discard block
 block discarded – undo
3381 3380
 			{
3382 3381
 				if (mb_strlen($v) < 3) unset($search[$k]);
3383 3382
 			}
3384
-			$search_str = implode(' +', $search);	// tell contacts/so_sql to AND search patterns
3383
+			$search_str = implode(' +', $search); // tell contacts/so_sql to AND search patterns
3385 3384
 			//error_log(__METHOD__.__LINE__.$_searchString);
3386 3385
 			$filter = $showAccounts ? array() : array('account_id' => null);
3387
-			$filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home');
3388
-			$cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home');
3389
-			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter);
3386
+			$filter['cols_to_search'] = array('n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3387
+			$cols = array('n_fn', 'n_prefix', 'n_given', 'n_family', 'org_name', 'email', 'email_home');
3388
+			$contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3390 3389
 			// additionally search the accounts, if the contact storage is not the account storage
3391 3390
 			if ($showAccounts && $contacts_obj->so_accounts)
3392 3391
 			{
3393 3392
 				$filter['owner'] = 0;
3394
-				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false,'OR', array(0,100), $filter);
3393
+				$accounts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0, 100), $filter);
3395 3394
 
3396 3395
 				if ($contacts && $accounts)
3397 3396
 				{
3398
-					$contacts = array_merge($contacts,$accounts);
3399
-					usort($contacts,function($a, $b)
3397
+					$contacts = array_merge($contacts, $accounts);
3398
+					usort($contacts, function($a, $b)
3400 3399
 					{
3401 3400
 						return strcasecmp($a['n_fn'], $b['n_fn']);
3402 3401
 					});
3403 3402
 				}
3404
-				elseif($accounts)
3403
+				elseif ($accounts)
3405 3404
 				{
3406
-					$contacts =& $accounts;
3405
+					$contacts = & $accounts;
3407 3406
 				}
3408 3407
 				unset($accounts);
3409 3408
 			}
3410 3409
 		}
3411 3410
 		
3412
-		if(is_array($contacts)) {
3413
-			foreach($contacts as $contact) {
3414
-				foreach(array($contact['email'],$contact['email_home']) as $email) {
3411
+		if (is_array($contacts)) {
3412
+			foreach ($contacts as $contact) {
3413
+				foreach (array($contact['email'], $contact['email_home']) as $email) {
3415 3414
 					// avoid wrong addresses, if an rfc822 encoded address is in addressbook
3416 3415
 					//$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
3417 3416
 					$rfcAddr = Mail::parseAddressList($email);
3418
-					$_rfcAddr=$rfcAddr->first();
3417
+					$_rfcAddr = $rfcAddr->first();
3419 3418
 					if (!$_rfcAddr->valid)
3420 3419
 					{
3421 3420
 						continue; // skip address if we encounter an error here
3422 3421
 					}
3423 3422
 					$email = $_rfcAddr->mailbox.'@'.$_rfcAddr->host;
3424 3423
 
3425
-					if (method_exists($contacts_obj,'search'))
3424
+					if (method_exists($contacts_obj, 'search'))
3426 3425
 					{
3427
-						$contact['n_fn']='';
3426
+						$contact['n_fn'] = '';
3428 3427
 						if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
3429
-						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3430
-						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3431
-						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3432
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3428
+						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_given'];
3429
+						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').$contact['n_family'];
3430
+						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn'] ? ' ' : '').'('.$contact['org_name'].')';
3431
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3433 3432
 					}
3434 3433
 					else
3435 3434
 					{
3436
-						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3435
+						$contact['n_fn'] = str_replace(array(',', '@'), ' ', $contact['n_fn']);
3437 3436
 					}
3438 3437
 					$args = explode('@', trim($email));
3439 3438
 					$args[] = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']);
3440 3439
 					$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
3441
-					if(!empty($email) && in_array($completeMailString ,$results) === false) {
3440
+					if (!empty($email) && in_array($completeMailString, $results) === false) {
3442 3441
 						$results[] = array(
3443 3442
 							'id'=>$completeMailString,
3444 3443
 							'label' => $completeMailString,
@@ -3454,10 +3453,10 @@  discard block
 block discarded – undo
3454 3453
 		// Add groups
3455 3454
 		$group_options = array('account_type' => 'groups');
3456 3455
 		$groups = $GLOBALS['egw']->accounts->link_query($_searchString, $group_options);
3457
-		foreach($groups as $g_id => $name)
3456
+		foreach ($groups as $g_id => $name)
3458 3457
 		{
3459 3458
 			$group = $GLOBALS['egw']->accounts->read($g_id);
3460
-			if(!$group['account_email']) continue;
3459
+			if (!$group['account_email']) continue;
3461 3460
 			$args = explode('@', trim($group['account_email']));
3462 3461
 			$args[] = $name;
3463 3462
 			$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
@@ -3487,7 +3486,7 @@  discard block
 block discarded – undo
3487 3486
 	public function ajax_merge($contact_id)
3488 3487
 	{
3489 3488
 		$response = Api\Json\Response::get();
3490
-		if(class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3489
+		if (class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
3491 3490
 		{
3492 3491
 			$document_merge = new $_REQUEST['merge']();
3493 3492
 		}
@@ -3497,7 +3496,7 @@  discard block
 block discarded – undo
3497 3496
 		}
3498 3497
 		$this->mail_bo->openConnection();
3499 3498
 
3500
-		if(($error = $document_merge->check_document($_REQUEST['document'],'')))
3499
+		if (($error = $document_merge->check_document($_REQUEST['document'], '')))
3501 3500
 		{
3502 3501
 			$response->error($error);
3503 3502
 			return;
@@ -3508,11 +3507,11 @@  discard block
 block discarded – undo
3508 3507
 		try
3509 3508
 		{
3510 3509
 			$results = $this->mail_bo->importMessageToMergeAndSend(
3511
-				$document_merge, Vfs::PREFIX . $_REQUEST['document'],
3510
+				$document_merge, Vfs::PREFIX.$_REQUEST['document'],
3512 3511
 				// Send an extra non-numeric ID to force actual send of document
3513 3512
 				// instead of save as draft
3514 3513
 				array((int)$contact_id, ''),
3515
-				$folder,$merged_mail_id
3514
+				$folder, $merged_mail_id
3516 3515
 			);
3517 3516
 		}
3518 3517
 		catch (Exception $e)
@@ -3526,13 +3525,13 @@  discard block
 block discarded – undo
3526 3525
 			);
3527 3526
 		}
3528 3527
 
3529
-		if($results['success'])
3528
+		if ($results['success'])
3530 3529
 		{
3531
-			$response->data(implode(',',$results['success']));
3530
+			$response->data(implode(',', $results['success']));
3532 3531
 		}
3533
-		if($results['failed'])
3532
+		if ($results['failed'])
3534 3533
 		{
3535
-			$response->error(implode(',',$results['failed']));
3534
+			$response->error(implode(',', $results['failed']));
3536 3535
 		}
3537 3536
 	}
3538 3537
 }
Please login to merge, or discard this patch.
Braces   +803 added lines, -269 removed lines patch added patch discarded remove patch
@@ -82,7 +82,10 @@  discard block
 block discarded – undo
82 82
 		{
83 83
 			$this->mailPreferences['message_forwarding'] = 'asmail';
84 84
 		}
85
-		if (is_null(Mail::$mailConfig)) Mail::$mailConfig = Api\Config::read('mail');
85
+		if (is_null(Mail::$mailConfig))
86
+		{
87
+			Mail::$mailConfig = Api\Config::read('mail');
88
+		}
86 89
 
87 90
 		$this->mailPreferences  =& $this->mail_bo->mailPreferences;
88 91
 	}
@@ -96,11 +99,21 @@  discard block
 block discarded – undo
96 99
 	{
97 100
 		if ($this->mail_bo->profileID!=$_icServerID)
98 101
 		{
99
-			if (Mail::$debug) error_log(__METHOD__.__LINE__.'->'.$this->mail_bo->profileID.'<->'.$_icServerID);
102
+			if (Mail::$debug)
103
+			{
104
+				error_log(__METHOD__.__LINE__.'->'.$this->mail_bo->profileID.'<->'.$_icServerID);
105
+			}
100 106
 			$this->mail_bo = Mail::getInstance(false,$_icServerID);
101
-			if (Mail::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$this->mail_bo->profileID.':'.function_backtrace());
107
+			if (Mail::$debug)
108
+			{
109
+				error_log(__METHOD__.__LINE__.' Fetched IC Server:'.$this->mail_bo->profileID.':'.function_backtrace());
110
+			}
102 111
 			// no icServer Object: something failed big time
103
-			if (!isset($this->mail_bo->icServer)) exit; // ToDo: Exception or the dialog for setting up a server config
112
+			if (!isset($this->mail_bo->icServer))
113
+			{
114
+				exit;
115
+			}
116
+			// ToDo: Exception or the dialog for setting up a server config
104 117
 			$this->mail_bo->openConnection($this->mail_bo->profileID);
105 118
 			$this->mailPreferences  =& $this->mail_bo->mailPreferences;
106 119
 		}
@@ -242,7 +255,8 @@  discard block
 block discarded – undo
242 255
 		{
243 256
 			foreach (array_keys($actions) as $key)
244 257
 			{
245
-				if (!in_array($key, array('send','button[saveAsDraft]','uploadForCompose' ))) {
258
+				if (!in_array($key, array('send','button[saveAsDraft]','uploadForCompose' )))
259
+				{
246 260
 					$actions[$key]['toolbarDefault'] = false;
247 261
 				}
248 262
 			}
@@ -268,7 +282,10 @@  discard block
 block discarded – undo
268 282
 	 */
269 283
 	function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false)
270 284
 	{
271
-		if ($msg) Framework::message($msg);
285
+		if ($msg)
286
+		{
287
+			Framework::message($msg);
288
+		}
272 289
 
273 290
 		if (!empty($GLOBALS['egw_info']['user']['preferences']['mail']['LastSignatureIDUsed']))
274 291
 		{
@@ -289,8 +306,14 @@  discard block
 block discarded – undo
289 306
 		//error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace());
290 307
 		$_contentHasSigID = $_content?array_key_exists('mailidentity',(array)$_content):false;
291 308
 		$_contentHasMimeType = $_content? array_key_exists('mimeType',(array)$_content):false;
292
-		if (isset($_GET['reply_id'])) $replyID = $_GET['reply_id'];
293
-		if (!$replyID && isset($_GET['id'])) $replyID = $_GET['id'];
309
+		if (isset($_GET['reply_id']))
310
+		{
311
+			$replyID = $_GET['reply_id'];
312
+		}
313
+		if (!$replyID && isset($_GET['id']))
314
+		{
315
+			$replyID = $_GET['id'];
316
+		}
294 317
 
295 318
 		// Process different places we can use as a start for composing an email
296 319
 		$actionToProcess = 'compose';
@@ -357,7 +380,10 @@  discard block
 block discarded – undo
357 380
 			$suppressSigOnTop = true;
358 381
 			foreach ($_content['uploadForCompose'] as $i => &$upload)
359 382
 			{
360
-				if (!isset($upload['file'])) $upload['file'] = $upload['tmp_name'];
383
+				if (!isset($upload['file']))
384
+				{
385
+					$upload['file'] = $upload['tmp_name'];
386
+				}
361 387
 				try
362 388
 				{
363 389
 					$upload['file'] = $upload['tmp_name'] = Mail::checkFileBasics($upload,$this->composeID,false);
@@ -391,9 +417,15 @@  discard block
 block discarded – undo
391 417
 				$remove=false;
392 418
 				foreach(array_keys($toDelete) as $k)
393 419
 				{
394
-					if ($att['tmp_name']==$k) $remove=true;
420
+					if ($att['tmp_name']==$k)
421
+					{
422
+						$remove=true;
423
+					}
424
+				}
425
+				if (!$remove)
426
+				{
427
+					$_content['attachments'][] = $att;
395 428
 				}
396
-				if (!$remove) $_content['attachments'][] = $att;
397 429
 			}
398 430
 		}
399 431
 		// someone clicked something like send, or saveAsDraft
@@ -408,8 +440,7 @@  discard block
 block discarded – undo
408 440
 		//error_log(__METHOD__.__LINE__.array2string($_content));
409 441
 		if (!empty($_content['serverID']) && $_content['serverID'] != $this->mail_bo->profileID &&
410 442
 			($_content['composeToolbar'] === 'send' || $_content['button']['saveAsDraft']||$_content['button']['saveAsDraftAndPrint'])
411
-		)
412
-		{
443
+		) {
413 444
 			$this->changeProfile($_content['serverID']);
414 445
 			$composeProfile = $this->mail_bo->profileID;
415 446
 		}
@@ -489,7 +520,10 @@  discard block
 block discarded – undo
489 520
 							//$this->sessionData['uid'][] = $fhA['msgUID'];
490 521
 							//$this->sessionData['forwardedUID'][] = $fhA['msgUID'];
491 522
 							$idsForRefresh[] = mail_ui::generateRowID($fhA['profileID'], $fhA['folder'], $fhA['msgUID'], $_prependApp=false);
492
-							if (!empty($fhA['folder'])) $workingFolder = $fhA['folder'];
523
+							if (!empty($fhA['folder']))
524
+							{
525
+								$workingFolder = $fhA['folder'];
526
+							}
493 527
 						}
494 528
 					}
495 529
 					if ($_content['mode']=='reply' && !empty($_content['processedmail_id']))
@@ -540,7 +574,10 @@  discard block
 block discarded – undo
540 574
 			}
541 575
 		}
542 576
 
543
-		if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile);
577
+		if ($activeProfile != $composeProfile)
578
+		{
579
+			$this->changeProfile($activeProfile);
580
+		}
544 581
 		$insertSigOnTop = false;
545 582
 		$content = (is_array($_content)?$_content:array());
546 583
 		if ($_contentHasMimeType)
@@ -569,7 +606,10 @@  discard block
 block discarded – undo
569 606
 				{
570 607
 					foreach ($contentArr as $k =>&$elem)
571 608
 					{
572
-						if (stripos($elem,'<pre>')!==false) $elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
609
+						if (stripos($elem,'<pre>')!==false)
610
+						{
611
+							$elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
612
+						}
573 613
 					}
574 614
 					$content['mail_htmltext'] = implode('',$contentArr);
575 615
 				}
@@ -611,8 +651,7 @@  discard block
 block discarded – undo
611 651
 		if ( !empty($content['body']) &&
612 652
 			(!empty($composeCache['mailaccount']) && !empty($_content['mailaccount']) && $_content['mailaccount'] != $composeCache['mailaccount']) ||
613 653
 			(!empty($composeCache['mailidentity']) && !empty($_content['mailidentity']) && $_content['mailidentity'] != $composeCache['mailidentity'])
614
-		)
615
-		{
654
+		) {
616 655
 			$buttonClicked = true;
617 656
 			$suppressSigOnTop = true;
618 657
 			if (!empty($composeCache['mailaccount']) && !empty($_content['mailaccount']) && $_content['mailaccount'] != $composeCache['mailaccount'])
@@ -628,7 +667,10 @@  discard block
 block discarded – undo
628 667
 				else
629 668
 				{
630 669
 					$newSig = $this->mail_bo->getDefaultIdentity();
631
-					if ($newSig === false) $newSig = -2;
670
+					if ($newSig === false)
671
+					{
672
+						$newSig = -2;
673
+					}
632 674
 				}
633 675
 			}
634 676
 			$_oldSig = $composeCache['mailidentity'];
@@ -636,7 +678,10 @@  discard block
 block discarded – undo
636 678
 
637 679
 			if ($_oldSig != $_signatureid)
638 680
 			{
639
-				if($this->_debug) error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
681
+				if($this->_debug)
682
+				{
683
+					error_log(__METHOD__.__LINE__.' old,new ->'.$_oldSig.','.$_signatureid.'#'.$content['body']);
684
+				}
640 685
 				// prepare signatures, the selected sig may be used on top of the body
641 686
 				try
642 687
 				{
@@ -666,7 +711,10 @@  discard block
 block discarded – undo
666 711
 				{
667 712
 					$oldSigText = $this->convertHTMLToText($oldSigText,true,true);
668 713
 					$sigText = $this->convertHTMLToText($sigText,true,true);
669
-					if($this->_debug) error_log(__METHOD__." Old signature:".$oldSigText);
714
+					if($this->_debug)
715
+					{
716
+						error_log(__METHOD__." Old signature:".$oldSigText);
717
+					}
670 718
 				}
671 719
 
672 720
 				//$oldSigText = Mail::merge($oldSigText,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
@@ -682,7 +730,11 @@  discard block
 block discarded – undo
682 730
 				{
683 731
 					$content['body'] = str_replace("\n",'\n',$content['body']);	// dont know why, but \n screws up preg_replace
684 732
 					$styles = Mail::getStyles(array(array('body'=>$content['body'])));
685
-					if (stripos($content['body'],'style')!==false) Api\Mail\Html::replaceTagsCompletley($content['body'],'style',$endtag='',true); // clean out empty or pagewide style definitions / left over tags
733
+					if (stripos($content['body'],'style')!==false)
734
+					{
735
+						Api\Mail\Html::replaceTagsCompletley($content['body'],'style',$endtag='',true);
736
+					}
737
+					// clean out empty or pagewide style definitions / left over tags
686 738
 				}
687 739
 				$content['body'] = str_replace(array("\r", "\t", "<br />\n", ": "), array("", "", "<br />", ":"),
688 740
 					$_currentMode == 'html' ? Api\Html::purify($content['body'], Mail::$htmLawed_config, array(), true) : $content['body']);
@@ -727,8 +779,14 @@  discard block
 block discarded – undo
727 779
 
728 780
 				if ($found === false)
729 781
 				{
730
-					if($this->_debug) error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
731
-					if($this->_debug) error_log(__METHOD__." Compare content:".$content['body']);
782
+					if($this->_debug)
783
+					{
784
+						error_log(__METHOD__." Old Signature failed to match:".$oldSigTextCleaned);
785
+					}
786
+					if($this->_debug)
787
+					{
788
+						error_log(__METHOD__." Compare content:".$content['body']);
789
+					}
732 790
 				}
733 791
 				else
734 792
 				{
@@ -746,7 +804,10 @@  discard block
 block discarded – undo
746 804
 		$_currentMode == 'html' ? Api\Html::purify($content['body'], Mail::$htmLawed_config, array(), true) : $content['body']);
747 805
 
748 806
 		// do not double insert a signature on a server roundtrip
749
-		if ($buttonClicked) $suppressSigOnTop = true;
807
+		if ($buttonClicked)
808
+		{
809
+			$suppressSigOnTop = true;
810
+		}
750 811
 		if ($isFirstLoad)
751 812
 		{
752 813
 			$alwaysAttachVCardAtCompose = false; // we use this to eliminate double attachments, if users VCard is already present/attached
@@ -785,7 +846,8 @@  discard block
 block discarded – undo
785 846
 							}
786 847
 						}
787 848
 						$content['subject'] = lang($app).' #'.$res['id'].': ';
788
-						foreach(array('subject','body','mimetype') as $name) {
849
+						foreach(array('subject','body','mimetype') as $name)
850
+						{
789 851
 							$sName = $name;
790 852
 							if ($name=='mimetype'&&$res[$name])
791 853
 							{
@@ -794,7 +856,10 @@  discard block
 block discarded – undo
794 856
 							}
795 857
 							else
796 858
 							{
797
-								if ($res[$name]) $content[$sName] .= (strlen($content[$sName])>0 ? ' ':'') .$res[$name];
859
+								if ($res[$name])
860
+								{
861
+									$content[$sName] .= (strlen($content[$sName])>0 ? ' ':'') .$res[$name];
862
+								}
798 863
 							}
799 864
 						}
800 865
 					}
@@ -805,7 +870,8 @@  discard block
 block discarded – undo
805 870
 			{
806 871
 				$alreadyProcessed=array();
807 872
 				//_debug_array($_REQUEST);
808
-				if ($_REQUEST['preset']['mailto']) {
873
+				if ($_REQUEST['preset']['mailto'])
874
+				{
809 875
 					// handle mailto strings such as
810 876
 					// mailto:larry,dan?cc=mike&bcc=sue&subject=test&body=type+your&body=message+here
811 877
 					// the above string may be htmlentyty encoded, then multiple body tags are supported
@@ -813,10 +879,12 @@  discard block
 block discarded – undo
813 879
 					$tmp_send_to = (stripos($_REQUEST['preset']['mailto'],'mailto')===false?$_REQUEST['preset']['mailto']:trim(substr(html_entity_decode($_REQUEST['preset']['mailto']),7)));
814 880
 					// check if there is more than the to address
815 881
 					$mailtoArray = explode('?',$tmp_send_to,2);
816
-					if ($mailtoArray[1]) {
882
+					if ($mailtoArray[1])
883
+					{
817 884
 						// check if there are more than one requests
818 885
 						$addRequests = explode('&',$mailtoArray[1]);
819
-						foreach ($addRequests as $key => $reqval) {
886
+						foreach ($addRequests as $key => $reqval)
887
+						{
820 888
 							// the additional requests should have a =, to separate key from value.
821 889
 							$keyValuePair = explode('=',$reqval,2);
822 890
 							$content[$keyValuePair[0]] .= (strlen($content[$keyValuePair[0]])>0 ? ' ':'') . $keyValuePair[1];
@@ -825,17 +893,24 @@  discard block
 block discarded – undo
825 893
 					$content['to']=$mailtoArray[0];
826 894
 					$alreadyProcessed['to']='to';
827 895
 					// if the mailto string is not htmlentity decoded the arguments are passed as simple requests
828
-					foreach(array('cc','bcc','subject','body') as $name) {
896
+					foreach(array('cc','bcc','subject','body') as $name)
897
+					{
829 898
 						$alreadyProcessed[$name]=$name;
830
-						if ($_REQUEST[$name]) $content[$name] .= (strlen($content[$name])>0 ? ( $name == 'cc' || $name == 'bcc' ? ',' : ' ') : '') . $_REQUEST[$name];
899
+						if ($_REQUEST[$name])
900
+						{
901
+							$content[$name] .= (strlen($content[$name])>0 ? ( $name == 'cc' || $name == 'bcc' ? ',' : ' ') : '') . $_REQUEST[$name];
902
+						}
831 903
 					}
832 904
 				}
833 905
 
834
-				if ($_REQUEST['preset']['mailtocontactbyid']) {
835
-					if ($GLOBALS['egw_info']['user']['apps']['addressbook']) {
906
+				if ($_REQUEST['preset']['mailtocontactbyid'])
907
+				{
908
+					if ($GLOBALS['egw_info']['user']['apps']['addressbook'])
909
+					{
836 910
 						$contacts_obj = new Api\Contacts();
837 911
 						$addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
838
-						if (method_exists($contacts_obj,'search')) {
912
+						if (method_exists($contacts_obj,'search'))
913
+						{
839 914
 
840 915
 							$addressArray = explode(',',$_REQUEST['preset']['mailtocontactbyid']);
841 916
 							foreach ((array)$addressArray as $id => $addressID)
@@ -850,7 +925,10 @@  discard block
 block discarded – undo
850 925
 							{
851 926
 								$_searchCond = array('contact_id'=>$addressArray);
852 927
 								//error_log(__METHOD__.__LINE__.$_searchString);
853
-								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $showAccounts=false;
928
+								if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'])
929
+								{
930
+									$showAccounts=false;
931
+								}
854 932
 								$filter = ($showAccounts?array():array('account_id' => null));
855 933
 								$filter['cols_to_search']=array('n_fn','email','email_home');
856 934
 								$contacts = $contacts_obj->search($_searchCond,array('n_fn','email','email_home'),'n_fn','','%',false,'OR',array(0,100),$filter);
@@ -873,21 +951,28 @@  discard block
 block discarded – undo
873 951
 									unset($accounts);
874 952
 								}
875 953
 							}
876
-							if(is_array($contacts)) {
954
+							if(is_array($contacts))
955
+							{
877 956
 								$mailtoArray = array();
878 957
 								$primary = $addressbookprefs['distributionListPreferredMail'];
879
-								if ($primary != 'email' && $primary != 'email_home') $primary = 'email';
958
+								if ($primary != 'email' && $primary != 'email_home')
959
+								{
960
+									$primary = 'email';
961
+								}
880 962
 								$secondary = ($primary == 'email'?'email_home':'email');
881 963
 								//error_log(__METHOD__.__LINE__.array2string($contacts));
882
-								foreach($contacts as $contact) {
964
+								foreach($contacts as $contact)
965
+								{
883 966
 									$innerCounter=0;
884
-									foreach(array($contact[$primary],$contact[$secondary]) as $email) {
967
+									foreach(array($contact[$primary],$contact[$secondary]) as $email)
968
+									{
885 969
 										// use pref distributionListPreferredMail for the primary address
886 970
 										// avoid wrong addresses, if an rfc822 encoded address is in addressbook
887 971
 										$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
888 972
 										$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
889 973
 										$completeMailString = addslashes(trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']) .' <'. trim($email) .'>');
890
-										if($innerCounter==0 && !empty($email) && in_array($completeMailString ,$mailtoArray) === false) {
974
+										if($innerCounter==0 && !empty($email) && in_array($completeMailString ,$mailtoArray) === false)
975
+										{
891 976
 											$i++;
892 977
 											$innerCounter++;
893 978
 											$mailtoArray[$i] = $completeMailString;
@@ -979,7 +1064,10 @@  discard block
 block discarded – undo
979 1064
 							}
980 1065
 						}
981 1066
 					}
982
-					if(!empty($remember)) $content = array_merge($content,$remember);
1067
+					if(!empty($remember))
1068
+					{
1069
+						$content = array_merge($content,$remember);
1070
+					}
983 1071
 				}
984 1072
 				foreach(array('to','cc','bcc','subject','body','mimeType') as $name)
985 1073
 				{
@@ -989,9 +1077,15 @@  discard block
 block discarded – undo
989 1077
 						$_content[$name]=$content[$name]=$_REQUEST['preset'][$name];
990 1078
 					}
991 1079
 					//skip if already processed by "preset Routines"
992
-					if ($alreadyProcessed[$name]) continue;
1080
+					if ($alreadyProcessed[$name])
1081
+					{
1082
+						continue;
1083
+					}
993 1084
 					//error_log(__METHOD__.__LINE__.':'.$name.'->'. $_REQUEST['preset'][$name]);
994
-					if ($_REQUEST['preset'][$name]) $content[$name] = $_REQUEST['preset'][$name];
1085
+					if ($_REQUEST['preset'][$name])
1086
+					{
1087
+						$content[$name] = $_REQUEST['preset'][$name];
1088
+					}
995 1089
 				}
996 1090
 			}
997 1091
 			// is the to address set already?
@@ -999,7 +1093,10 @@  discard block
 block discarded – undo
999 1093
 			{
1000 1094
 				$content['to'] = base64_decode($_REQUEST['send_to']);
1001 1095
 				// first check if there is a questionmark or ampersand
1002
-				if (strpos($content['to'],'?')!== false) list($content['to'],$rest) = explode('?',$content['to'],2);
1096
+				if (strpos($content['to'],'?')!== false)
1097
+				{
1098
+					list($content['to'],$rest) = explode('?',$content['to'],2);
1099
+				}
1003 1100
 				$content['to'] = html_entity_decode($content['to']);
1004 1101
 				if (($at_pos = strpos($content['to'],'@')) !== false)
1005 1102
 				{
@@ -1012,9 +1109,15 @@  discard block
 block discarded – undo
1012 1109
 						$content['to'] = $email;
1013 1110
 					}
1014 1111
 				}
1015
-				if (strpos($content['to'],'%40')!== false) $content['to'] = Api\Html::purify(str_replace('%40','@',$content['to']));
1112
+				if (strpos($content['to'],'%40')!== false)
1113
+				{
1114
+					$content['to'] = Api\Html::purify(str_replace('%40','@',$content['to']));
1115
+				}
1016 1116
 				$rarr = array(Api\Html::purify($rest));
1017
-				if (isset($rest)&&!empty($rest) && strpos($rest,'&')!== false) $rarr = explode('&',$rest);
1117
+				if (isset($rest)&&!empty($rest) && strpos($rest,'&')!== false)
1118
+				{
1119
+					$rarr = explode('&',$rest);
1120
+				}
1018 1121
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($rarr));
1019 1122
 				$karr = array();
1020 1123
 				foreach ($rarr as &$rval)
@@ -1030,9 +1133,15 @@  discard block
 block discarded – undo
1030 1133
 				//error_log(__METHOD__.__LINE__.$content['to'].'->'.array2string($karr));
1031 1134
 				foreach(array('cc','bcc','subject','body') as $name)
1032 1135
 				{
1033
-					if ($karr[$name]) $content[$name] = $karr[$name];
1136
+					if ($karr[$name])
1137
+					{
1138
+						$content[$name] = $karr[$name];
1139
+					}
1140
+				}
1141
+				if (!empty($_REQUEST['subject']))
1142
+				{
1143
+					$content['subject'] = Api\Html::purify(trim(html_entity_decode($_REQUEST['subject'])));
1034 1144
 				}
1035
-				if (!empty($_REQUEST['subject'])) $content['subject'] = Api\Html::purify(trim(html_entity_decode($_REQUEST['subject'])));
1036 1145
 			}
1037 1146
 		}
1038 1147
 		//error_log(__METHOD__.__LINE__.array2string($content));
@@ -1050,7 +1159,10 @@  discard block
 block discarded – undo
1050 1159
 				$_content['mimeType'] = $content['mimeType']  = 'html';
1051 1160
 				$content['body'] = "<pre>".$content['body']."</pre>";
1052 1161
 				// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1053
-				if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1162
+				if (strpos($content['body'],"<pre> \r\n \r\n---")===0)
1163
+				{
1164
+					$content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1165
+				}
1054 1166
 			}
1055 1167
 		}
1056 1168
 		else
@@ -1070,7 +1182,10 @@  discard block
 block discarded – undo
1070 1182
 					$_content['mimeType'] = $content['mimeType']  = 'html';
1071 1183
 					$content['body'] = "<pre>".$content['body']."</pre>";
1072 1184
 					// take care this assumption is made on the creation of the reply header in bocompose::getReplyData
1073
-					if (strpos($content['body'],"<pre> \r\n \r\n---")===0) $content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1185
+					if (strpos($content['body'],"<pre> \r\n \r\n---")===0)
1186
+					{
1187
+						$content['body'] = substr_replace($content['body']," <br>\r\n<pre>---",0,strlen("<pre> \r\n \r\n---")-1);
1188
+					}
1074 1189
 				}
1075 1190
 			}
1076 1191
 		}
@@ -1108,24 +1223,33 @@  discard block
 block discarded – undo
1108 1223
 			$disableRuler = true;
1109 1224
 		}
1110 1225
 		$font_span = $font_part = '';
1111
-		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/) {
1226
+		if($content['mimeType'] == 'html' /*&& trim($content['body'])==''*/)
1227
+		{
1112 1228
 			// User preferences for style
1113 1229
 			$font = $GLOBALS['egw_info']['user']['preferences']['common']['rte_font'];
1114 1230
 			$font_size = Api\Html\CkEditorConfig::font_size_from_prefs();
1115 1231
 			$font_part = '<span style="width:100%; display: inline; '.($font?'font-family:'.$font.'; ':'').($font_size?'font-size:'.$font_size.'; ':'').'">';
1116 1232
 			$font_span = $font_part.'&#8203;</span>';
1117
-			if (empty($font) && empty($font_size)) $font_span = '';
1233
+			if (empty($font) && empty($font_size))
1234
+			{
1235
+				$font_span = '';
1236
+			}
1118 1237
 		}
1119 1238
 		// the font span should only be applied on first load or on switch plain->html and the absence of the font_part of the span
1120
-		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false) $font_span = '';
1239
+		if (!$isFirstLoad && !empty($font_span) && stripos($content['body'],$font_part)===false)
1240
+		{
1241
+			$font_span = '';
1242
+		}
1121 1243
 		//remove possible html header stuff
1122
-		if (stripos($content['body'],'<html><head></head><body>')!==false) $content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1244
+		if (stripos($content['body'],'<html><head></head><body>')!==false)
1245
+		{
1246
+			$content['body'] = str_ireplace(array('<html><head></head><body>','</body></html>'),array('',''),$content['body']);
1247
+		}
1123 1248
 		//error_log(__METHOD__.__LINE__.array2string($this->mailPreferences));
1124 1249
 		$blockElements = array('address','blockquote','center','del','dir','div','dl','fieldset','form','h1','h2','h3','h4','h5','h6','hr','ins','isindex','menu','noframes','noscript','ol','p','pre','table','ul');
1125 1250
 		if ($this->mailPreferences['insertSignatureAtTopOfMessage']!='no_belowaftersend' &&
1126 1251
 			!(isset($_POST['mySigID']) && !empty($_POST['mySigID']) ) && !$suppressSigOnTop
1127
-		)
1128
-		{
1252
+		) {
1129 1253
 			// ON tOP OR BELOW? pREF CAN TELL
1130 1254
 			/*
1131 1255
 				Signature behavior preference changed. New default, if not set -> 0
@@ -1140,14 +1264,23 @@  discard block
 block discarded – undo
1140 1264
 				$sigTextStartsWithBlockElement = ($disableRuler?false:true);
1141 1265
 				foreach($blockElements as $e)
1142 1266
 				{
1143
-					if ($sigTextStartsWithBlockElement) break;
1144
-					if (stripos(trim($sigText),'<'.$e)===0) $sigTextStartsWithBlockElement = true;
1267
+					if ($sigTextStartsWithBlockElement)
1268
+					{
1269
+						break;
1270
+					}
1271
+					if (stripos(trim($sigText),'<'.$e)===0)
1272
+					{
1273
+						$sigTextStartsWithBlockElement = true;
1274
+					}
1145 1275
 				}
1146 1276
 			}
1147
-			if($content['mimeType'] == 'html') {
1277
+			if($content['mimeType'] == 'html')
1278
+			{
1148 1279
 				$before = $disableRuler ? '' : '<hr style="border:1px dotted silver; width:100%;">';
1149 1280
 				$inbetween = '';
1150
-			} else {
1281
+			}
1282
+			else
1283
+			{
1151 1284
 				$before = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
1152 1285
 				$inbetween = "\r\n";
1153 1286
 			}
@@ -1181,7 +1314,10 @@  discard block
 block discarded – undo
1181 1314
 		foreach(Mail\Account::search(true,false) as $acc_id => $account)
1182 1315
 		{
1183 1316
 			// do NOT add SMTP only accounts as identities
1184
-			if (!$account->is_imap(false)) continue;
1317
+			if (!$account->is_imap(false))
1318
+			{
1319
+				continue;
1320
+			}
1185 1321
 
1186 1322
 			foreach($account->identities($acc_id) as $ident_id => $identity)
1187 1323
 			{
@@ -1194,16 +1330,24 @@  discard block
 block discarded – undo
1194 1330
 		//$content['bcc'] = array('[email protected]','[email protected]');
1195 1331
 		// address stuff like from, to, cc, replyto
1196 1332
 		$destinationRows = 0;
1197
-		foreach(self::$destinations as $destination) {
1333
+		foreach(self::$destinations as $destination)
1334
+		{
1198 1335
 			if (!is_array($content[$destination]))
1199 1336
 			{
1200
-				if (!empty($content[$destination])) $content[$destination] = (array)$content[$destination];
1337
+				if (!empty($content[$destination]))
1338
+				{
1339
+					$content[$destination] = (array)$content[$destination];
1340
+				}
1201 1341
 			}
1202 1342
 			$addr_content = $content[strtolower($destination)];
1203 1343
 			// we clear the given address array and rebuild it
1204 1344
 			unset($content[strtolower($destination)]);
1205
-			foreach((array)$addr_content as $key => $value) {
1206
-				if ($value=="NIL@NIL") continue;
1345
+			foreach((array)$addr_content as $key => $value)
1346
+			{
1347
+				if ($value=="NIL@NIL")
1348
+				{
1349
+					continue;
1350
+				}
1207 1351
 				if ($destination=='replyto' && str_replace('"','',$value) ==
1208 1352
 					str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
1209 1353
 				{
@@ -1213,8 +1357,12 @@  discard block
 block discarded – undo
1213 1357
 				}
1214 1358
 				//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
1215 1359
 				$value = str_replace("\"\"",'"', htmlspecialchars_decode($value, ENT_COMPAT));
1216
-				foreach(Mail::parseAddressList($value) as $addressObject) {
1217
-					if ($addressObject->host == '.SYNTAX-ERROR.') continue;
1360
+				foreach(Mail::parseAddressList($value) as $addressObject)
1361
+				{
1362
+					if ($addressObject->host == '.SYNTAX-ERROR.')
1363
+					{
1364
+						continue;
1365
+					}
1218 1366
 					$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
1219 1367
 					//$address = Mail::htmlentities($address, $this->displayCharset);
1220 1368
 					$content[strtolower($destination)][]=$address;
@@ -1225,11 +1373,20 @@  discard block
 block discarded – undo
1225 1373
 		if ($_content)
1226 1374
 		{
1227 1375
 			//input array of _content had no signature information but was seeded later, and content has a valid setting
1228
-			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content)) unset($_content['mailidentity']);
1376
+			if (!$_contentHasSigID && $content['mailidentity'] && array_key_exists('mailidentity',$_content))
1377
+			{
1378
+				unset($_content['mailidentity']);
1379
+			}
1229 1380
 			$content = array_merge($content,$_content);
1230 1381
 
1231
-			if (!empty($content['folder'])) $sel_options['folder']=$this->ajax_searchFolder(0,true);
1232
-			if (empty($content['mailaccount'])) $content['mailaccount'] = $this->mail_bo->profileID;
1382
+			if (!empty($content['folder']))
1383
+			{
1384
+				$sel_options['folder']=$this->ajax_searchFolder(0,true);
1385
+			}
1386
+			if (empty($content['mailaccount']))
1387
+			{
1388
+				$content['mailaccount'] = $this->mail_bo->profileID;
1389
+			}
1233 1390
 		}
1234 1391
 		else
1235 1392
 		{
@@ -1272,11 +1429,17 @@  discard block
 block discarded – undo
1272 1429
 		//error_log(__METHOD__.__LINE__.' ComposeID:'.$preserv['composeID']);
1273 1430
 		$preserv['is_html'] = $content['is_html'];
1274 1431
 		$preserv['is_plain'] = $content['is_plain'];
1275
-		if (isset($content['mimeType'])) $preserv['mimeType'] = $content['mimeType'];
1432
+		if (isset($content['mimeType']))
1433
+		{
1434
+			$preserv['mimeType'] = $content['mimeType'];
1435
+		}
1276 1436
 		$sel_options['mimeType'] = self::$mimeTypes;
1277 1437
 		$sel_options['priority'] = self::$priorities;
1278 1438
 		$sel_options['filemode'] = Vfs\Sharing::$modes;
1279
-		if (!isset($content['priority']) || empty($content['priority'])) $content['priority']=3;
1439
+		if (!isset($content['priority']) || empty($content['priority']))
1440
+		{
1441
+			$content['priority']=3;
1442
+		}
1280 1443
 		//$GLOBALS['egw_info']['flags']['currentapp'] = 'mail';//should not be needed
1281 1444
 		$etpl = new Etemplate('mail.compose');
1282 1445
 
@@ -1323,9 +1486,12 @@  discard block
 block discarded – undo
1323 1486
 		$preserv['list-id'] = $content['list-id'];
1324 1487
 		$preserv['mode'] = $content['mode'];
1325 1488
 		// convert it back to checkbox expectations
1326
-		if($content['mimeType'] == 'html') {
1489
+		if($content['mimeType'] == 'html')
1490
+		{
1327 1491
 			$content['mimeType']=1;
1328
-		} else {
1492
+		}
1493
+		else
1494
+		{
1329 1495
 			$content['mimeType']=0;
1330 1496
 		}
1331 1497
 		// set the current selected mailaccount as param for folderselection
@@ -1336,7 +1502,10 @@  discard block
 block discarded – undo
1336 1502
 		// Resolve distribution list before send content to client
1337 1503
 		foreach(array('to', 'cc', 'bcc', 'replyto')  as $f)
1338 1504
 		{
1339
-			if (is_array($content[$f])) $content[$f]= self::resolveEmailAddressList ($content[$f]);
1505
+			if (is_array($content[$f]))
1506
+			{
1507
+				$content[$f]= self::resolveEmailAddressList ($content[$f]);
1508
+			}
1340 1509
 		}
1341 1510
 
1342 1511
 		$content['to'] = self::resolveEmailAddressList($content['to']);
@@ -1384,7 +1553,10 @@  discard block
 block discarded – undo
1384 1553
 				case 'composefromdraft':
1385 1554
 				case 'composeasnew':
1386 1555
 					$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
1387
-					if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
1556
+					if ($from =='composefromdraft')
1557
+					{
1558
+						$content['mode'] = 'composefromdraft';
1559
+					}
1388 1560
 					$content['processedmail_id'] = $mail_id;
1389 1561
 
1390 1562
 					$_focusElement = 'body';
@@ -1432,7 +1604,10 @@  discard block
 block discarded – undo
1432 1604
 			$document_merge = new $merge_class();
1433 1605
 			$this->mail_bo->openConnection();
1434 1606
 			$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
1435
-			if (!is_array($merge_ids)) $merge_ids = explode(',',$merge_ids);
1607
+			if (!is_array($merge_ids))
1608
+			{
1609
+				$merge_ids = explode(',',$merge_ids);
1610
+			}
1436 1611
 			try
1437 1612
 			{
1438 1613
 				$merged_mail_id = '';
@@ -1463,7 +1638,10 @@  discard block
 block discarded – undo
1463 1638
 				{
1464 1639
 					$success = implode(', ',$results['success']);
1465 1640
 					$fail = implode(', ', $results['failed']);
1466
-					if($success) Framework::message($success, 'success');
1641
+					if($success)
1642
+					{
1643
+						Framework::message($success, 'success');
1644
+					}
1467 1645
 					Framework::window_close($fail);
1468 1646
 				}
1469 1647
 			}
@@ -1495,17 +1673,25 @@  discard block
 block discarded – undo
1495 1673
 	{
1496 1674
 		$stripalltags = true;
1497 1675
 		// third param is stripalltags, we may not need that, if the source is already in ascii
1498
-		if (!$sourceishtml) $stripalltags=false;
1676
+		if (!$sourceishtml)
1677
+		{
1678
+			$stripalltags=false;
1679
+		}
1499 1680
 		return Api\Mail\Html::convertHTMLToText($_html,$this->displayCharset,$stripcrl,$stripalltags);
1500 1681
 	}
1501 1682
 
1502 1683
 	function generateRFC822Address($_addressObject)
1503 1684
 	{
1504
-		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
1685
+		if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host)
1686
+		{
1505 1687
 			return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1506
-		} elseif($_addressObject->mailbox && $_addressObject->host) {
1688
+		}
1689
+		elseif($_addressObject->mailbox && $_addressObject->host)
1690
+		{
1507 1691
 			return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
1508
-		} else {
1692
+		}
1693
+		else
1694
+		{
1509 1695
 			return $this->mail_bo->decode_header($_addressObject->mailbox,true);
1510 1696
 		}
1511 1697
 	}
@@ -1539,16 +1725,28 @@  discard block
 block discarded – undo
1539 1725
 		//if ($addHeadInfo['THREAD-TOPIC']) $this->sessionData['thread-topic'] = $addHeadInfo['THREAD-TOPIC'];
1540 1726
 
1541 1727
 		//error_log(__METHOD__.__LINE__.array2string($headers));
1542
-		if (!empty($addHeadInfo['X-MAILFOLDER'])) {
1543
-			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val ) {
1728
+		if (!empty($addHeadInfo['X-MAILFOLDER']))
1729
+		{
1730
+			foreach ( explode('|',$addHeadInfo['X-MAILFOLDER']) as $val )
1731
+			{
1544 1732
 				$fval=$val;
1545 1733
 				$icServerID = $mail_bo->icServer->ImapServerId;
1546
-				if (stripos($val,'::')!==false) list($icServerID,$fval) = explode('::',$val,2);
1547
-				if ($icServerID != $mail_bo->icServer->ImapServerId) continue;
1548
-				if ($mail_bo->folderExists($fval)) $this->sessionData['folder'][] = $val;
1734
+				if (stripos($val,'::')!==false)
1735
+				{
1736
+					list($icServerID,$fval) = explode('::',$val,2);
1737
+				}
1738
+				if ($icServerID != $mail_bo->icServer->ImapServerId)
1739
+				{
1740
+					continue;
1741
+				}
1742
+				if ($mail_bo->folderExists($fval))
1743
+				{
1744
+					$this->sessionData['folder'][] = $val;
1745
+				}
1549 1746
 			}
1550 1747
 		}
1551
-		if (!empty($addHeadInfo['X-MAILIDENTITY'])) {
1748
+		if (!empty($addHeadInfo['X-MAILIDENTITY']))
1749
+		{
1552 1750
 			// with the new system it would be the identity
1553 1751
 			try
1554 1752
 			{
@@ -1564,7 +1762,8 @@  discard block
 block discarded – undo
1564 1762
 			$this->sessionData['stationeryID'] = $addHeadInfo['X-STATIONERY'];
1565 1763
 		}
1566 1764
 		*/
1567
-		if (!empty($addHeadInfo['X-MAILACCOUNT'])) {
1765
+		if (!empty($addHeadInfo['X-MAILACCOUNT']))
1766
+		{
1568 1767
 			// with the new system it would the identity is the account id
1569 1768
 			try
1570 1769
 			{
@@ -1579,27 +1778,38 @@  discard block
 block discarded – undo
1579 1778
 			}
1580 1779
 		}
1581 1780
 		// if the message is located within the draft folder, add it as last drafted version (for possible cleanup on abort))
1582
-		if ($mail_bo->isDraftFolder($_folder)) $this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);//array('uid'=>$_uid,'folder'=>$_folder);
1781
+		if ($mail_bo->isDraftFolder($_folder))
1782
+		{
1783
+			$this->sessionData['lastDrafted'] = mail_ui::generateRowID($this->mail_bo->profileID, $_folder, $_uid);
1784
+		}
1785
+		//array('uid'=>$_uid,'folder'=>$_folder);
1583 1786
 		$this->sessionData['uid'] = $_uid;
1584 1787
 		$this->sessionData['messageFolder'] = $_folder;
1585 1788
 		$this->sessionData['isDraft'] = true;
1586 1789
 		$foundAddresses = array();
1587
-		foreach((array)$headers['CC'] as $val) {
1790
+		foreach((array)$headers['CC'] as $val)
1791
+		{
1588 1792
 			$rfcAddr=Mail::parseAddressList($val);
1589 1793
 			$_rfcAddr = $rfcAddr[0];
1590
-			if (!$_rfcAddr->valid) continue;
1591
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1794
+			if (!$_rfcAddr->valid)
1795
+			{
1796
+				continue;
1797
+			}
1798
+			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) )
1799
+			{
1592 1800
 				continue;
1593 1801
 			}
1594 1802
 			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1595
-			if(!$foundAddresses[$keyemail]) {
1803
+			if(!$foundAddresses[$keyemail])
1804
+			{
1596 1805
 				$address = $this->mail_bo->decode_header($val,true);
1597 1806
 				$this->sessionData['cc'][] = $val;
1598 1807
 				$foundAddresses[$keyemail] = true;
1599 1808
 			}
1600 1809
 		}
1601 1810
 
1602
-		foreach((array)$headers['TO'] as $val) {
1811
+		foreach((array)$headers['TO'] as $val)
1812
+		{
1603 1813
 			if(!is_array($val))
1604 1814
 			{
1605 1815
 				$this->sessionData['to'][] = $val;
@@ -1607,42 +1817,59 @@  discard block
 block discarded – undo
1607 1817
 			}
1608 1818
 			$rfcAddr=Mail::parseAddressList($val);
1609 1819
 			$_rfcAddr = $rfcAddr[0];
1610
-			if (!$_rfcAddr->valid) continue;
1611
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
1820
+			if (!$_rfcAddr->valid)
1821
+			{
1822
+				continue;
1823
+			}
1824
+			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) )
1825
+			{
1612 1826
 				continue;
1613 1827
 			}
1614 1828
 			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1615
-			if(!$foundAddresses[$keyemail]) {
1829
+			if(!$foundAddresses[$keyemail])
1830
+			{
1616 1831
 				$address = $this->mail_bo->decode_header($val,true);
1617 1832
 				$this->sessionData['to'][] = $val;
1618 1833
 				$foundAddresses[$keyemail] = true;
1619 1834
 			}
1620 1835
 		}
1621 1836
 
1622
-		foreach((array)$headers['REPLY-TO'] as $val) {
1837
+		foreach((array)$headers['REPLY-TO'] as $val)
1838
+		{
1623 1839
 			$rfcAddr=Mail::parseAddressList($val);
1624 1840
 			$_rfcAddr = $rfcAddr[0];
1625
-			if (!$_rfcAddr->valid) continue;
1626
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1841
+			if (!$_rfcAddr->valid)
1842
+			{
1843
+				continue;
1844
+			}
1845
+			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) )
1846
+			{
1627 1847
 				continue;
1628 1848
 			}
1629 1849
 			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1630
-			if(!$foundAddresses[$keyemail]) {
1850
+			if(!$foundAddresses[$keyemail])
1851
+			{
1631 1852
 				$address = $this->mail_bo->decode_header($val,true);
1632 1853
 				$this->sessionData['replyto'][] = $val;
1633 1854
 				$foundAddresses[$keyemail] = true;
1634 1855
 			}
1635 1856
 		}
1636 1857
 
1637
-		foreach((array)$headers['BCC'] as $val) {
1858
+		foreach((array)$headers['BCC'] as $val)
1859
+		{
1638 1860
 			$rfcAddr=Mail::parseAddressList($val);
1639 1861
 			$_rfcAddr = $rfcAddr[0];
1640
-			if (!$_rfcAddr->valid) continue;
1641
-			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
1862
+			if (!$_rfcAddr->valid)
1863
+			{
1864
+				continue;
1865
+			}
1866
+			if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) )
1867
+			{
1642 1868
 				continue;
1643 1869
 			}
1644 1870
 			$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
1645
-			if(!$foundAddresses[$keyemail]) {
1871
+			if(!$foundAddresses[$keyemail])
1872
+			{
1646 1873
 				$address = $this->mail_bo->decode_header($val,true);
1647 1874
 				$this->sessionData['bcc'][] = $val;
1648 1875
 				$foundAddresses[$keyemail] = true;
@@ -1656,32 +1883,46 @@  discard block
 block discarded – undo
1656 1883
 		$bodyParts = $mail_bo->getMessageBody($_uid,'always_display', $_partID);
1657 1884
 		//_debug_array($bodyParts);
1658 1885
 		#$fromAddress = ($headers['FROM'][0]['PERSONAL_NAME'] != 'NIL') ? $headers['FROM'][0]['RFC822_EMAIL'] : $headers['FROM'][0]['EMAIL'];
1659
-		if($bodyParts['0']['mimeType'] == 'text/html') {
1886
+		if($bodyParts['0']['mimeType'] == 'text/html')
1887
+		{
1660 1888
 			$this->sessionData['mimeType'] 	= 'html';
1661 1889
 
1662
-			for($i=0; $i<count($bodyParts); $i++) {
1663
-				if($i>0) {
1890
+			for($i=0; $i<count($bodyParts); $i++)
1891
+			{
1892
+				if($i>0)
1893
+				{
1664 1894
 					$this->sessionData['body'] .= '<hr>';
1665 1895
 				}
1666
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
1896
+				if($bodyParts[$i]['mimeType'] == 'text/plain')
1897
+				{
1667 1898
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body']);
1668 1899
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
1669 1900
 				}
1670
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1901
+				if ($bodyParts[$i]['charSet']===false)
1902
+				{
1903
+					$bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1904
+				}
1671 1905
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1672 1906
 				#error_log( "GetDraftData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1673 1907
 				$this->sessionData['body'] .= ($i>0?"<br>":""). $bodyParts[$i]['body'] ;
1674 1908
 			}
1675 1909
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID);
1676 1910
 
1677
-		} else {
1911
+		}
1912
+		else
1913
+		{
1678 1914
 			$this->sessionData['mimeType']	= 'plain';
1679 1915
 
1680
-			for($i=0; $i<count($bodyParts); $i++) {
1681
-				if($i>0) {
1916
+			for($i=0; $i<count($bodyParts); $i++)
1917
+			{
1918
+				if($i>0)
1919
+				{
1682 1920
 					$this->sessionData['body'] .= "<hr>";
1683 1921
 				}
1684
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1922
+				if ($bodyParts[$i]['charSet']===false)
1923
+				{
1924
+					$bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
1925
+				}
1685 1926
 				$bodyParts[$i]['body'] = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
1686 1927
 				#error_log( "GetDraftData (Plain) CharSet".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
1687 1928
 				$this->sessionData['body'] .= ($i>0?"\r\n":""). $bodyParts[$i]['body'] ;
@@ -1689,8 +1930,10 @@  discard block
 block discarded – undo
1689 1930
 			$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID,'plain');
1690 1931
 		}
1691 1932
 
1692
-		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID))) {
1693
-			foreach($attachments as $attachment) {
1933
+		if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID)))
1934
+		{
1935
+			foreach($attachments as $attachment)
1936
+			{
1694 1937
 				//error_log(__METHOD__.__LINE__.array2string($attachment));
1695 1938
 				$cid = $attachment['cid'];
1696 1939
 				$match=null;
@@ -1713,7 +1956,8 @@  discard block
 block discarded – undo
1713 1956
 
1714 1957
 	function getErrorInfo()
1715 1958
 	{
1716
-		if(isset($this->errorInfo)) {
1959
+		if(isset($this->errorInfo))
1960
+		{
1717 1961
 			$errorInfo = $this->errorInfo;
1718 1962
 			unset($this->errorInfo);
1719 1963
 			return $errorInfo;
@@ -1728,7 +1972,8 @@  discard block
 block discarded – undo
1728 1972
 			$modebuff = $this->mailPreferences['message_forwarding'];
1729 1973
 			$this->mailPreferences['message_forwarding'] = $_mode;
1730 1974
 		}
1731
-		if  ($this->mailPreferences['message_forwarding'] == 'inline') {
1975
+		if  ($this->mailPreferences['message_forwarding'] == 'inline')
1976
+		{
1732 1977
 			$this->getReplyData('forward', $_icServer, $_folder, $_uid, $_partID);
1733 1978
 		}
1734 1979
 		$mail_bo    = $this->mail_bo;
@@ -1745,12 +1990,16 @@  discard block
 block discarded – undo
1745 1990
 		//$this->sessionData['sourceFolder']=$_folder;
1746 1991
 		//$this->sessionData['forwardFlag']='forwarded';
1747 1992
 		//$this->sessionData['forwardedUID']=$_uid;
1748
-		if  ($this->mailPreferences['message_forwarding'] == 'asmail') {
1993
+		if  ($this->mailPreferences['message_forwarding'] == 'asmail')
1994
+		{
1749 1995
 			$this->sessionData['mimeType']  = $this->mailPreferences['composeOptions'];
1750 1996
 			if($headers['SIZE'])
1751
-				$size				= $headers['SIZE'];
1752
-			else
1753
-				$size				= lang('unknown');
1997
+			{
1998
+							$size				= $headers['SIZE'];
1999
+			}
2000
+			else {
2001
+							$size				= lang('unknown');
2002
+			}
1754 2003
 
1755 2004
 			$this->addMessageAttachment($_uid, $_partID, $_folder,
1756 2005
 				$mail_bo->decode_header(($headers['SUBJECT']?$headers['SUBJECT']:lang('no subject'))).'.eml',
@@ -1761,9 +2010,11 @@  discard block
 block discarded – undo
1761 2010
 			unset($this->sessionData['in-reply-to']);
1762 2011
 			unset($this->sessionData['to']);
1763 2012
 			unset($this->sessionData['cc']);
1764
-			if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false))) {
2013
+			if(($attachments = $mail_bo->getMessageAttachments($_uid,$_partID,null,true,false,false)))
2014
+			{
1765 2015
 				//error_log(__METHOD__.__LINE__.':'.array2string($attachments));
1766
-				foreach($attachments as $attachment) {
2016
+				foreach($attachments as $attachment)
2017
+				{
1767 2018
 					if (!($attachment['cid'] && preg_match("/image\//",$attachment['mimeType'])) || $attachment['disposition'] == 'attachment')
1768 2019
 					{
1769 2020
 						$this->addMessageAttachment($_uid, $attachment['partID'],
@@ -1819,7 +2070,10 @@  discard block
 block discarded – undo
1819 2070
 			{
1820 2071
 				if ($attach['name'] && $attach['name'] == $_formData['name'] &&
1821 2072
 					strtolower($_formData['type'])== strtolower($attach['type']) &&
1822
-					stripos($_formData['file'],'vfs://') !== false) return;
2073
+					stripos($_formData['file'],'vfs://') !== false)
2074
+				{
2075
+					return;
2076
+				}
1823 2077
 			}
1824 2078
 		}
1825 2079
 		if ($attachfailed === false)
@@ -1831,7 +2085,10 @@  discard block
 block discarded – undo
1831 2085
 				'tmp_name'	=> $tmpFileName,
1832 2086
 				'size'	=> $_formData['size']
1833 2087
 			);
1834
-			if (!is_array($_content['attachments'])) $_content['attachments']=array();
2088
+			if (!is_array($_content['attachments']))
2089
+			{
2090
+				$_content['attachments']=array();
2091
+			}
1835 2092
 			$_content['attachments'][] = $buffer;
1836 2093
 			unset($buffer);
1837 2094
 		}
@@ -1862,7 +2119,10 @@  discard block
 block discarded – undo
1862 2119
 		{
1863 2120
 			foreach($request->preserv['attachments'] as $attachment)
1864 2121
 			{
1865
-				if ($_GET['tmpname'] === $attachment['tmp_name']) break;
2122
+				if ($_GET['tmpname'] === $attachment['tmp_name'])
2123
+				{
2124
+					break;
2125
+				}
1866 2126
 			}
1867 2127
 		}
1868 2128
 		if (!$request || $_GET['tmpname'] !== $attachment['tmp_name'])
@@ -1896,10 +2156,20 @@  discard block
 block discarded – undo
1896 2156
 				$sfxMimeType = $attachment['type'];
1897 2157
 				$buff = explode('.',$attachment['tmp_name']);
1898 2158
 				$suffix = '';
1899
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
1900
-				if (!empty($suffix)) $sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2159
+				if (is_array($buff))
2160
+				{
2161
+					$suffix = array_pop($buff);
2162
+				}
2163
+				// take the last extension to check with ext2mime
2164
+				if (!empty($suffix))
2165
+				{
2166
+					$sfxMimeType = Api\MimeMagic::ext2mime($suffix);
2167
+				}
1901 2168
 				$attachment['type'] = $sfxMimeType;
1902
-				if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD') $attachment['type'] = strtoupper($sfxMimeType);
2169
+				if (strtoupper($sfxMimeType) == 'TEXT/VCARD' || strtoupper($sfxMimeType) == 'TEXT/X-VCARD')
2170
+				{
2171
+					$attachment['type'] = strtoupper($sfxMimeType);
2172
+				}
1903 2173
 			}
1904 2174
 			//error_log(__METHOD__.print_r($attachment,true));
1905 2175
 			if (strtoupper($attachment['type']) == 'TEXT/CALENDAR' || strtoupper($attachment['type']) == 'TEXT/X-VCALENDAR')
@@ -1908,7 +2178,10 @@  discard block
 block discarded – undo
1908 2178
 				$calendar_ical = new calendar_ical();
1909 2179
 				$eventid = $calendar_ical->search($attachment['attachment'],-1);
1910 2180
 				//error_log(__METHOD__.array2string($eventid));
1911
-				if (!$eventid) $eventid = -1;
2181
+				if (!$eventid)
2182
+				{
2183
+					$eventid = -1;
2184
+				}
1912 2185
 				$event = $calendar_ical->importVCal($attachment['attachment'],(is_array($eventid)?$eventid[0]:$eventid),null,true);
1913 2186
 				//error_log(__METHOD__.$event);
1914 2187
 				if ((int)$event > 0)
@@ -1934,7 +2207,10 @@  discard block
 block discarded – undo
1934 2207
 					//error_log(__METHOD__.__LINE__.print_r($vcard,true));
1935 2208
 					$contact = $addressbook_vcal->find_contact($vcard,false);
1936 2209
 				}
1937
-				if (!$contact) $contact = null;
2210
+				if (!$contact)
2211
+				{
2212
+					$contact = null;
2213
+				}
1938 2214
 				// 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))
1939 2215
 				if ($contact || count($vcard)>2)
1940 2216
 				{
@@ -1965,7 +2241,8 @@  discard block
 block discarded – undo
1965 2241
 	 * @param string haystack
1966 2242
 	 * @return boolean
1967 2243
 	 */
1968
-	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack) {
2244
+	function testIfOneKeyInArrayDoesExistInString($arrayToTestAgainst,$haystack)
2245
+	{
1969 2246
 		foreach (array_keys($arrayToTestAgainst) as $k)
1970 2247
 		{
1971 2248
 			//error_log(__METHOD__.__LINE__.':'.$k.'<->'.$haystack);
@@ -2022,21 +2299,34 @@  discard block
 block discarded – undo
2022 2299
 		// thread-topic is a proprietary microsoft header and deprecated with the current version
2023 2300
 		// horde does not support the encoding of thread-topic, and probably will not no so in the future
2024 2301
 		//if ($headers['THREAD-TOPIC']) $this->sessionData['thread-topic'] = $headers['THREAD-TOPIC'];
2025
-		if ($headers['THREAD-INDEX']) $this->sessionData['thread-index'] = $headers['THREAD-INDEX'];
2026
-		if ($headers['LIST-ID']) $this->sessionData['list-id'] = $headers['LIST-ID'];
2302
+		if ($headers['THREAD-INDEX'])
2303
+		{
2304
+			$this->sessionData['thread-index'] = $headers['THREAD-INDEX'];
2305
+		}
2306
+		if ($headers['LIST-ID'])
2307
+		{
2308
+			$this->sessionData['list-id'] = $headers['LIST-ID'];
2309
+		}
2027 2310
 		//error_log(__METHOD__.__LINE__.' Mode:'.$_mode.':'.array2string($headers));
2028 2311
 		// check for Reply-To: header and use if available
2029
-		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM'])) {
2030
-			foreach($headers['REPLY-TO'] as $val) {
2031
-				if(!$foundAddresses[$val]) {
2312
+		if(!empty($headers['REPLY-TO']) && ($headers['REPLY-TO'] != $headers['FROM']))
2313
+		{
2314
+			foreach($headers['REPLY-TO'] as $val)
2315
+			{
2316
+				if(!$foundAddresses[$val])
2317
+				{
2032 2318
 					$oldTo[] = $val;
2033 2319
 					$foundAddresses[$val] = true;
2034 2320
 				}
2035 2321
 			}
2036 2322
 			$oldToAddress	= (is_array($headers['REPLY-TO'])?$headers['REPLY-TO'][0]:$headers['REPLY-TO']);
2037
-		} else {
2038
-			foreach($headers['FROM'] as $val) {
2039
-				if(!$foundAddresses[$val]) {
2323
+		}
2324
+		else
2325
+		{
2326
+			foreach($headers['FROM'] as $val)
2327
+			{
2328
+				if(!$foundAddresses[$val])
2329
+				{
2040 2330
 					$oldTo[] = $val;
2041 2331
 					$foundAddresses[$val] = true;
2042 2332
 				}
@@ -2044,18 +2334,23 @@  discard block
 block discarded – undo
2044 2334
 			$oldToAddress	= (is_array($headers['FROM'])?$headers['FROM'][0]:$headers['FROM']);
2045 2335
 		}
2046 2336
 		//error_log(__METHOD__.__LINE__.' OldToAddress:'.$oldToAddress.'#');
2047
-		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) ) {
2337
+		if($_mode != 'all' || ($_mode == 'all' && !empty($oldToAddress) && !$this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$oldToAddress)) )
2338
+		{
2048 2339
 			$this->sessionData['to'] = $oldTo;
2049 2340
 		}
2050 2341
 
2051
-		if($_mode == 'all') {
2342
+		if($_mode == 'all')
2343
+		{
2052 2344
 			// reply to any address which is cc, but not to my self
2053 2345
 			#if($headers->cc) {
2054
-				foreach($headers['CC'] as $val) {
2055
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2346
+				foreach($headers['CC'] as $val)
2347
+				{
2348
+					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val))
2349
+					{
2056 2350
 						continue;
2057 2351
 					}
2058
-					if(!$foundAddresses[$val]) {
2352
+					if(!$foundAddresses[$val])
2353
+					{
2059 2354
 						$this->sessionData['cc'][] = $val;
2060 2355
 						$foundAddresses[$val] = true;
2061 2356
 					}
@@ -2064,11 +2359,14 @@  discard block
 block discarded – undo
2064 2359
 
2065 2360
 			// reply to any address which is to, but not to my self
2066 2361
 			#if($headers->to) {
2067
-				foreach($headers['TO'] as $val) {
2068
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2362
+				foreach($headers['TO'] as $val)
2363
+				{
2364
+					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val))
2365
+					{
2069 2366
 						continue;
2070 2367
 					}
2071
-					if(!$foundAddresses[$val]) {
2368
+					if(!$foundAddresses[$val])
2369
+					{
2072 2370
 						$this->sessionData['to'][] = $val;
2073 2371
 						$foundAddresses[$val] = true;
2074 2372
 					}
@@ -2076,12 +2374,15 @@  discard block
 block discarded – undo
2076 2374
 			#}
2077 2375
 
2078 2376
 			#if($headers->from) {
2079
-				foreach($headers['FROM'] as $val) {
2080
-					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val)) {
2377
+				foreach($headers['FROM'] as $val)
2378
+				{
2379
+					if($this->testIfOneKeyInArrayDoesExistInString($userEMailAddresses,$val))
2380
+					{
2081 2381
 						continue;
2082 2382
 					}
2083 2383
 					//error_log(__METHOD__.__LINE__.' '.$val);
2084
-					if(!$foundAddresses[$val]) {
2384
+					if(!$foundAddresses[$val])
2385
+					{
2085 2386
 						$this->sessionData['to'][] = $val;
2086 2387
 						$foundAddresses[$val] = true;
2087 2388
 					}
@@ -2090,9 +2391,12 @@  discard block
 block discarded – undo
2090 2391
 		}
2091 2392
 
2092 2393
 		// check for Re: in subject header
2093
-		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:") {
2394
+		if(strtolower(substr(trim($mail_bo->decode_header($headers['SUBJECT'])), 0, 3)) == "re:")
2395
+		{
2094 2396
 			$this->sessionData['subject'] = $mail_bo->decode_header($headers['SUBJECT']);
2095
-		} else {
2397
+		}
2398
+		else
2399
+		{
2096 2400
 			$this->sessionData['subject'] = "Re: " . $mail_bo->decode_header($headers['SUBJECT']);
2097 2401
 		}
2098 2402
 
@@ -2106,7 +2410,8 @@  discard block
 block discarded – undo
2106 2410
 
2107 2411
 		$toAddressA = array();
2108 2412
 		$toAddress = '';
2109
-		foreach ($headers['TO'] as $mailheader) {
2413
+		foreach ($headers['TO'] as $mailheader)
2414
+		{
2110 2415
 			$toAddressA[] =  $mailheader;
2111 2416
 		}
2112 2417
 		if (count($toAddressA)>0)
@@ -2116,7 +2421,8 @@  discard block
 block discarded – undo
2116 2421
 		}
2117 2422
 		$ccAddressA = array();
2118 2423
 		$ccAddress = '';
2119
-		foreach ($headers['CC'] as $mailheader) {
2424
+		foreach ($headers['CC'] as $mailheader)
2425
+		{
2120 2426
 			$ccAddressA[] =  $mailheader;
2121 2427
 		}
2122 2428
 		if (count($ccAddressA)>0)
@@ -2124,25 +2430,35 @@  discard block
 block discarded – undo
2124 2430
 			$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA));
2125 2431
 			$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
2126 2432
 		}
2127
-		if($bodyParts['0']['mimeType'] == 'text/html') {
2433
+		if($bodyParts['0']['mimeType'] == 'text/html')
2434
+		{
2128 2435
 			$this->sessionData['body']	= /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
2129 2436
 				@htmlspecialchars(lang("from")).": ".$fromAddress."<br>".
2130 2437
 				$toAddress.$ccAddress.
2131 2438
 				@htmlspecialchars(lang("date").": ".$headers['DATE'],ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>".
2132 2439
 				'----------------------------------------------------------'."</div>";
2133 2440
 			$this->sessionData['mimeType'] 	= 'html';
2134
-			if (!empty($styles)) $this->sessionData['body'] .= $styles;
2441
+			if (!empty($styles))
2442
+			{
2443
+				$this->sessionData['body'] .= $styles;
2444
+			}
2135 2445
 			$this->sessionData['body']	.= '<blockquote type="cite">';
2136 2446
 
2137
-			for($i=0; $i<count($bodyParts); $i++) {
2138
-				if($i>0) {
2447
+			for($i=0; $i<count($bodyParts); $i++)
2448
+			{
2449
+				if($i>0)
2450
+				{
2139 2451
 					$this->sessionData['body'] .= '<hr>';
2140 2452
 				}
2141
-				if($bodyParts[$i]['mimeType'] == 'text/plain') {
2453
+				if($bodyParts[$i]['mimeType'] == 'text/plain')
2454
+				{
2142 2455
 					#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>";
2143 2456
 					$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>";
2144 2457
 				}
2145
-				if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2458
+				if ($bodyParts[$i]['charSet']===false)
2459
+				{
2460
+					$bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']);
2461
+				}
2146 2462
 
2147 2463
 				$_htmlConfig = Mail::$htmLawed_config;
2148 2464
 				Mail::$htmLawed_config['comment'] = 2;
@@ -2154,7 +2470,9 @@  discard block
 block discarded – undo
2154 2470
 
2155 2471
 			$this->sessionData['body']	.= '</blockquote><br>';
2156 2472
 			$this->sessionData['body'] =  mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
2157
-		} else {
2473
+		}
2474
+		else
2475
+		{
2158 2476
 			//$this->sessionData['body']	= @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n";
2159 2477
 			// 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)
2160 2478
             $this->sessionData['body']  = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n".
@@ -2164,8 +2482,10 @@  discard block
 block discarded – undo
2164 2482
                 '-------------------------------------------------'."\r\n \r\n ";
2165 2483
 			$this->sessionData['mimeType']	= 'plain';
2166 2484
 
2167
-			for($i=0; $i<count($bodyParts); $i++) {
2168
-				if($i>0) {
2485
+			for($i=0; $i<count($bodyParts); $i++)
2486
+			{
2487
+				if($i>0)
2488
+				{
2169 2489
 					$this->sessionData['body'] .= "<hr>";
2170 2490
 				}
2171 2491
 
@@ -2175,9 +2495,11 @@  discard block
 block discarded – undo
2175 2495
 				$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
2176 2496
 				$this->sessionData['body'] .= "\r\n";
2177 2497
 				// create body new, with good line breaks and indention
2178
-				foreach(explode("\n",$newBody) as $value) {
2498
+				foreach(explode("\n",$newBody) as $value)
2499
+				{
2179 2500
 					// the explode is removing the character
2180
-					if (trim($value) != '') {
2501
+					if (trim($value) != '')
2502
+					{
2181 2503
 						#if ($value != "\r") $value .= "\n";
2182 2504
 					}
2183 2505
 					$numberOfChars = strspn(trim($value), ">");
@@ -2185,9 +2507,12 @@  discard block
 block discarded – undo
2185 2507
 
2186 2508
 					$bodyAppend = $this->mail_bo->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
2187 2509
 
2188
-					if($bodyAppend[0] == '>') {
2510
+					if($bodyAppend[0] == '>')
2511
+					{
2189 2512
 						$bodyAppend = '>'. $bodyAppend;
2190
-					} else {
2513
+					}
2514
+					else
2515
+					{
2191 2516
 						$bodyAppend = '> '. $bodyAppend;
2192 2517
 					}
2193 2518
 
@@ -2236,9 +2561,12 @@  discard block
 block discarded – undo
2236 2561
 
2237 2562
 	static function _getHostName()
2238 2563
 	{
2239
-		if (isset($_SERVER['SERVER_NAME'])) {
2564
+		if (isset($_SERVER['SERVER_NAME']))
2565
+		{
2240 2566
 			$result = $_SERVER['SERVER_NAME'];
2241
-		} else {
2567
+		}
2568
+		else
2569
+		{
2242 2570
 			$result = 'localhost.localdomain';
2243 2571
 		}
2244 2572
 		return $result;
@@ -2276,11 +2604,16 @@  discard block
 block discarded – undo
2276 2604
 
2277 2605
 		$_mailObject->addHeader('X-Priority', $_formData['priority']);
2278 2606
 		$_mailObject->addHeader('X-Mailer', 'EGroupware-Mail');
2279
-		if(!empty($_formData['in-reply-to'])) {
2280
-			if (stripos($_formData['in-reply-to'],'<')===false) $_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2607
+		if(!empty($_formData['in-reply-to']))
2608
+		{
2609
+			if (stripos($_formData['in-reply-to'],'<')===false)
2610
+			{
2611
+				$_formData['in-reply-to']='<'.trim($_formData['in-reply-to']).'>';
2612
+			}
2281 2613
 			$_mailObject->addHeader('In-Reply-To', $_formData['in-reply-to']);
2282 2614
 		}
2283
-		if(!empty($_formData['references'])) {
2615
+		if(!empty($_formData['references']))
2616
+		{
2284 2617
 			if (stripos($_formData['references'],'<')===false)
2285 2618
 			{
2286 2619
 				$_formData['references']='<'.trim($_formData['references']).'>';
@@ -2288,28 +2621,38 @@  discard block
 block discarded – undo
2288 2621
 			$_mailObject->addHeader('References', $_formData['references']);
2289 2622
 		}
2290 2623
 
2291
-		if(!empty($_formData['thread-index'])) {
2624
+		if(!empty($_formData['thread-index']))
2625
+		{
2292 2626
 			$_mailObject->addHeader('Thread-Index', $_formData['thread-index']);
2293 2627
 		}
2294
-		if(!empty($_formData['list-id'])) {
2628
+		if(!empty($_formData['list-id']))
2629
+		{
2295 2630
 			$_mailObject->addHeader('List-Id', $_formData['list-id']);
2296 2631
 		}
2297
-		if($_formData['disposition']=='on') {
2632
+		if($_formData['disposition']=='on')
2633
+		{
2298 2634
 			$_mailObject->addHeader('Disposition-Notification-To', $_identity['ident_email']);
2299 2635
 		}
2300 2636
 
2301 2637
 		// Expand any mailing lists
2302 2638
 		foreach(array('to', 'cc', 'bcc', 'replyto')  as $field)
2303 2639
 		{
2304
-			if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2640
+			if ($field != 'replyto')
2641
+			{
2642
+				$_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
2643
+			}
2305 2644
 
2306
-			if ($_formData[$field]) $_mailObject->addAddress($_formData[$field], '', $field);
2645
+			if ($_formData[$field])
2646
+			{
2647
+				$_mailObject->addAddress($_formData[$field], '', $field);
2648
+			}
2307 2649
 		}
2308 2650
 
2309 2651
 		$_mailObject->addHeader('Subject', $_formData['subject']);
2310 2652
 
2311 2653
 		// this should never happen since we come from the edit dialog
2312
-		if (Mail::detect_qp($_formData['body'])) {
2654
+		if (Mail::detect_qp($_formData['body']))
2655
+		{
2313 2656
 			$_formData['body'] = preg_replace('/=\r\n/', '', $_formData['body']);
2314 2657
 			$_formData['body'] = quoted_printable_decode($_formData['body']);
2315 2658
 		}
@@ -2362,7 +2705,10 @@  discard block
 block discarded – undo
2362 2705
 				$_mailObject->setBody($this->convertHTMLToText($body, true, true));
2363 2706
 			}
2364 2707
 			// convert URL Images to inline images - if possible
2365
-			if (!$_autosaving) $inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2708
+			if (!$_autosaving)
2709
+			{
2710
+				$inline_images = Mail::processURL2InlineImages($_mailObject, $body, $mail_bo);
2711
+			}
2366 2712
 			if (strpos($body,"<!-- HTMLSIGBEGIN -->")!==false)
2367 2713
 			{
2368 2714
 				$body = str_replace(array('<!-- HTMLSIGBEGIN -->','<!-- HTMLSIGEND -->'),'',$body);
@@ -2377,10 +2723,14 @@  discard block
 block discarded – undo
2377 2723
 		{
2378 2724
 			$body = $this->convertHTMLToText($_formData['body'],false);
2379 2725
 
2380
-			if ($attachment_links) $body .= $attachment_links;
2726
+			if ($attachment_links)
2727
+			{
2728
+				$body .= $attachment_links;
2729
+			}
2381 2730
 
2382 2731
 			#$_mailObject->Body = $_formData['body'];
2383
-			if(!empty($signature)) {
2732
+			if(!empty($signature))
2733
+			{
2384 2734
 				$body .= ($disableRuler ?"\r\n":"\r\n-- \r\n").
2385 2735
 					$this->convertHTMLToText($signature,true,true);
2386 2736
 			}
@@ -2391,10 +2741,12 @@  discard block
 block discarded – undo
2391 2741
 		{
2392 2742
 			$connection_opened = false;
2393 2743
 			$tnfattachments = null;
2394
-			foreach((array)$_formData['attachments'] as $attachment) {
2744
+			foreach((array)$_formData['attachments'] as $attachment)
2745
+			{
2395 2746
 				if(is_array($attachment))
2396 2747
 				{
2397
-					if (!empty($attachment['uid']) && !empty($attachment['folder'])) {
2748
+					if (!empty($attachment['uid']) && !empty($attachment['folder']))
2749
+					{
2398 2750
 						/* Example:
2399 2751
 						Array([0] => Array(
2400 2752
 						[uid] => 21178
@@ -2410,14 +2762,18 @@  discard block
 block discarded – undo
2410 2762
 							$connection_opened = true;
2411 2763
 						}
2412 2764
 						$mail_bo->reopen($attachment['folder']);
2413
-						switch(strtoupper($attachment['type'])) {
2765
+						switch(strtoupper($attachment['type']))
2766
+						{
2414 2767
 							case 'MESSAGE/RFC':
2415 2768
 							case 'MESSAGE/RFC822':
2416 2769
 								$rawBody='';
2417
-								if (isset($attachment['partID'])) {
2770
+								if (isset($attachment['partID']))
2771
+								{
2418 2772
 									$eml = $mail_bo->getAttachment($attachment['uid'],$attachment['partID'],0,false,true,$attachment['folder']);
2419 2773
 									$rawBody=$eml['attachment'];
2420
-								} else {
2774
+								}
2775
+								else
2776
+								{
2421 2777
 									$rawBody        = $mail_bo->getMessageRawBody($attachment['uid'], $attachment['partID'],$attachment['folder']);
2422 2778
 								}
2423 2779
 								$_mailObject->addStringAttachment($rawBody, $attachment['name'], 'message/rfc822');
@@ -2426,7 +2782,10 @@  discard block
 block discarded – undo
2426 2782
 								$attachmentData	= $mail_bo->getAttachment($attachment['uid'], $attachment['partID'],0,false);
2427 2783
 								if ($attachmentData['type'] == 'APPLICATION/MS-TNEF')
2428 2784
 								{
2429
-									if (!is_array($tnfattachments)) $tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
2785
+									if (!is_array($tnfattachments))
2786
+									{
2787
+										$tnfattachments = $mail_bo->decode_winmail($attachment['uid'], $attachment['partID']);
2788
+									}
2430 2789
 									foreach ($tnfattachments as $k)
2431 2790
 									{
2432 2791
 										if ($k['name'] == $attachment['name'])
@@ -2461,7 +2820,10 @@  discard block
 block discarded – undo
2461 2820
 					}
2462 2821
 				}
2463 2822
 			}
2464
-			if ($connection_opened) $mail_bo->closeConnection();
2823
+			if ($connection_opened)
2824
+			{
2825
+				$mail_bo->closeConnection();
2826
+			}
2465 2827
 		}
2466 2828
 		return is_array($inline_images)?$inline_images:array();
2467 2829
 	}
@@ -2481,13 +2843,20 @@  discard block
 block discarded – undo
2481 2843
 	 */
2482 2844
 	protected function getAttachmentLinks(array $attachments, $filemode, $html, $recipients=array(), $expiration=null, $password=null)
2483 2845
 	{
2484
-		if ($filemode == Vfs\Sharing::ATTACH) return '';
2846
+		if ($filemode == Vfs\Sharing::ATTACH)
2847
+		{
2848
+			return '';
2849
+		}
2485 2850
 
2486 2851
 		$links = array();
2487 2852
 		foreach($attachments as $attachment)
2488 2853
 		{
2489 2854
 			$path = $attachment['file'];
2490
-			if (empty($path)) continue;	// we only care about file attachments, not forwarded messages or parts
2855
+			if (empty($path))
2856
+			{
2857
+				continue;
2858
+			}
2859
+			// we only care about file attachments, not forwarded messages or parts
2491 2860
 			if (parse_url($attachment['file'],PHP_URL_SCHEME) != 'vfs')
2492 2861
 			{
2493 2862
 				$path = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($path);
@@ -2590,13 +2959,19 @@  discard block
 block discarded – undo
2590 2959
 								$success = false;
2591 2960
 								error_log(__METHOD__.__LINE__.$msg);
2592 2961
 							}
2593
-						} else {
2962
+						}
2963
+						else
2964
+						{
2594 2965
 							error_log(__METHOD__.__LINE__.': original message ('.$pMuid.') has attachments and lastDrafted ID ('.$duid.') equals the former');
2595 2966
 						}
2596
-					} else {
2967
+					}
2968
+					else
2969
+					{
2597 2970
 						error_log(__METHOD__.__LINE__." No current draftID (".$draft_id."), or no lastDrafted Info (".$content['lastDrafted'].") or the former being equal:".array2string($content)."(, action=$action)");
2598 2971
 					}
2599
-				} else {
2972
+				}
2973
+				else
2974
+				{
2600 2975
 					error_log(__METHOD__.__LINE__.' No headerdata found for messageUID='.$messageUid.' in Folder:'.$folder.':'.array2string($content)."(, action=$action)");
2601 2976
 				}
2602 2977
 			}
@@ -2612,7 +2987,10 @@  discard block
 block discarded – undo
2612 2987
 			$success = false;
2613 2988
 		}
2614 2989
 
2615
-		if ($success) $msg = lang('Message saved successfully.');
2990
+		if ($success)
2991
+		{
2992
+			$msg = lang('Message saved successfully.');
2993
+		}
2616 2994
 
2617 2995
 		// Include new information to json respose, because we need them in client-side callback
2618 2996
 		$response->data(array(
@@ -2636,7 +3014,10 @@  discard block
 block discarded – undo
2636 3014
 		{
2637 3015
 			if(is_int($address))
2638 3016
 			{
2639
-				if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts();
3017
+				if (!isset($contacts_obs))
3018
+				{
3019
+					$contacts_obj = new Api\Contacts();
3020
+				}
2640 3021
 				// List was selected, expand to addresses
2641 3022
 				unset($_emailAddressList[$ak]);
2642 3023
 				$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));
@@ -2651,7 +3032,10 @@  discard block
 block discarded – undo
2651 3032
 		{
2652 3033
 			foreach ($addrFromList as $addr)
2653 3034
 			{
2654
-				if (!empty($addr)) $_emailAddressList[]=$addr;
3035
+				if (!empty($addr))
3036
+				{
3037
+					$_emailAddressList[]=$addr;
3038
+				}
2655 3039
 			}
2656 3040
 		}
2657 3041
 		return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList;
@@ -2705,7 +3089,10 @@  discard block
 block discarded – undo
2705 3089
 		// decide where to save the message (default to draft folder, if we find nothing else)
2706 3090
 		// if the current folder is in draft or template folder save it there
2707 3091
 		// if it is called from printview then save it with the draft folder
2708
-		if (empty($savingDestination)) $savingDestination = $mail_bo->getDraftFolder();
3092
+		if (empty($savingDestination))
3093
+		{
3094
+			$savingDestination = $mail_bo->getDraftFolder();
3095
+		}
2709 3096
 		if (empty($this->sessionData['messageFolder']) && !empty($this->sessionData['mailbox']))
2710 3097
 		{
2711 3098
 			$this->sessionData['messageFolder'] = $this->sessionData['mailbox'];
@@ -2716,13 +3103,17 @@  discard block
 block discarded – undo
2716 3103
 			$savingDestination = $this->sessionData['messageFolder'];
2717 3104
 			//error_log(__METHOD__.__LINE__.' SavingDestination:'.$savingDestination);
2718 3105
 		}
2719
-		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 ) $savingDestination = $mail_bo->getDraftFolder();
3106
+		if (  !empty($_formData['printit']) && $_formData['printit'] == 0 )
3107
+		{
3108
+			$savingDestination = $mail_bo->getDraftFolder();
3109
+		}
2720 3110
 
2721 3111
 		// normaly Bcc is only added to recipients, but not as header visible to all recipients
2722 3112
 		$mail->forceBccHeader();
2723 3113
 
2724 3114
 		$mail_bo->openConnection();
2725
-		if ($mail_bo->folderExists($savingDestination,true)) {
3115
+		if ($mail_bo->folderExists($savingDestination,true))
3116
+		{
2726 3117
 			try
2727 3118
 			{
2728 3119
 				$messageUid = $mail_bo->appendMessage($savingDestination, $mail->getRaw(), null, $flags);
@@ -2733,7 +3124,9 @@  discard block
 block discarded – undo
2733 3124
 				return false;
2734 3125
 			}
2735 3126
 
2736
-		} else {
3127
+		}
3128
+		else
3129
+		{
2737 3130
 			error_log(__METHOD__.__LINE__."->".lang("folder")." ". $savingDestination." ".lang("does not exist on IMAP Server."));
2738 3131
 			return false;
2739 3132
 		}
@@ -2781,7 +3174,10 @@  discard block
 block discarded – undo
2781 3174
 					$fhA = mail_ui::splitRowID($rowid);
2782 3175
 					$this->sessionData['uid'][] = $fhA['msgUID'];
2783 3176
 					$this->sessionData['forwardedUID'][] = $fhA['msgUID'];
2784
-					if (!empty($fhA['folder'])) $this->sessionData['sourceFolder'] = $fhA['folder'];
3177
+					if (!empty($fhA['folder']))
3178
+					{
3179
+						$this->sessionData['sourceFolder'] = $fhA['folder'];
3180
+					}
2785 3181
 				}
2786 3182
 			}
2787 3183
 			if ($_formData['mode']=='reply' && !empty($_formData['processedmail_id']))
@@ -2813,7 +3209,8 @@  discard block
 block discarded – undo
2813 3209
 			#error_log($this->sessionData['body']);
2814 3210
 		}
2815 3211
 		if(empty($this->sessionData['to']) && empty($this->sessionData['cc']) &&
2816
-		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder'])) {
3212
+		   empty($this->sessionData['bcc']) && empty($this->sessionData['folder']))
3213
+		{
2817 3214
 		   	$messageIsDraft = true;
2818 3215
 		}
2819 3216
 		try
@@ -2829,7 +3226,11 @@  discard block
 block discarded – undo
2829 3226
 		// create the messages and store inline images
2830 3227
 		$inline_images = $this->createMessage($mail, $_formData, $identity);
2831 3228
 		// remember the identity
2832
-		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
3229
+		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on')
3230
+		{
3231
+			$fromAddress = $mail->From;
3232
+		}
3233
+		//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
2833 3234
 		#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
2834 3235
 		#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";
2835 3236
 		#exit;
@@ -2842,7 +3243,10 @@  discard block
 block discarded – undo
2842 3243
 		{
2843 3244
 			$fval=$f;
2844 3245
 			$icServerID = $_formData['serverID'];//folders always assumed with serverID
2845
-			if (stripos($f,'::')!==false) list($icServerID,$fval) = explode('::',$f,2);
3246
+			if (stripos($f,'::')!==false)
3247
+			{
3248
+				list($icServerID,$fval) = explode('::',$f,2);
3249
+			}
2846 3250
 			if ($_formData['serverID']!=$_formData['mailaccount'])
2847 3251
 			{
2848 3252
 				if ($icServerID == $_formData['serverID'] )
@@ -2883,13 +3287,19 @@  discard block
 block discarded – undo
2883 3287
 			// sentFolder is account specific
2884 3288
 			$sentFolder = $this->mail_bo->getSentFolder();
2885 3289
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2886
-			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
3290
+			if ($sentFolder&& $sentFolder!= 'none' && !$this->mail_bo->folderExists($sentFolder, true))
3291
+			{
3292
+				$sentFolder=false;
3293
+			}
2887 3294
 		}
2888 3295
 		else
2889 3296
 		{
2890 3297
 			$sentFolder = $mail_bo->getSentFolder();
2891 3298
 			//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2892
-			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true)) $sentFolder=false;
3299
+			if ($sentFolder&& $sentFolder!= 'none' && !$mail_bo->folderExists($sentFolder, true))
3300
+			{
3301
+				$sentFolder=false;
3302
+			}
2893 3303
 		}
2894 3304
 		//error_log(__METHOD__.__LINE__.' SentFolder configured:'.$sentFolder.'#');
2895 3305
 
@@ -2925,19 +3335,30 @@  discard block
 block discarded – undo
2925 3335
 		{
2926 3336
 			if (((!isset($sentFolder)||$sentFolder==false) && $this->mailPreferences['sendOptions'] != 'send_only') ||
2927 3337
 				($this->mailPreferences['sendOptions'] != 'send_only' &&
2928
-				$sentFolder != 'none')) $this->errorInfo = lang("No Send Folder set in preferences");
3338
+				$sentFolder != 'none'))
3339
+			{
3340
+				$this->errorInfo = lang("No Send Folder set in preferences");
3341
+			}
2929 3342
 		}
2930 3343
 		// draftFolder is on Server we start from
2931
-		if($messageIsDraft == true) {
3344
+		if($messageIsDraft == true)
3345
+		{
2932 3346
 			$draftFolder = $mail_bo->getDraftFolder();
2933
-			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true)) {
3347
+			if(!empty($draftFolder) && $mail_bo->folderExists($draftFolder,true))
3348
+			{
2934 3349
 				$this->sessionData['folder'] = array($draftFolder);
2935 3350
 				$folderOnServerID[] = $draftFolder;
2936 3351
 				$folder[$draftFolder] = $draftFolder;
2937 3352
 			}
2938 3353
 		}
2939
-		if ($folderOnServerID) $folderOnServerID = array_unique($folderOnServerID);
2940
-		if ($folderOnMailAccount) $folderOnMailAccount = array_unique($folderOnMailAccount);
3354
+		if ($folderOnServerID)
3355
+		{
3356
+			$folderOnServerID = array_unique($folderOnServerID);
3357
+		}
3358
+		if ($folderOnMailAccount)
3359
+		{
3360
+			$folderOnMailAccount = array_unique($folderOnMailAccount);
3361
+		}
2941 3362
 		if (($this->mailPreferences['sendOptions'] != 'send_only' && $sentFolder != 'none') &&
2942 3363
 			!( count($folder) > 0) &&
2943 3364
 			!($_formData['to_infolog']=='on' || $_formData['to_tracker']=='on'))
@@ -2951,7 +3372,8 @@  discard block
 block discarded – undo
2951 3372
 		@set_time_limit(120);
2952 3373
 		//$mail->SMTPDebug = 10;
2953 3374
 		//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']));
2954
-		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
3375
+		if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0)
3376
+		{
2955 3377
 			try {
2956 3378
 				$mail->send();
2957 3379
 			}
@@ -2961,10 +3383,15 @@  discard block
 block discarded – undo
2961 3383
 				$this->errorInfo = $e->getMessage().($e->details?'<br/>'.$e->details:'');
2962 3384
 				return false;
2963 3385
 			}
2964
-		} else {
2965
-			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder'])) {
3386
+		}
3387
+		else
3388
+		{
3389
+			if (count(array($this->sessionData['folder']))>0 && !empty($this->sessionData['folder']))
3390
+			{
2966 3391
 				//error_log(__METHOD__.__LINE__."Folders:".print_r($this->sessionData['folder'],true));
2967
-			} else {
3392
+			}
3393
+			else
3394
+			{
2968 3395
 				$this->errorInfo = lang("Error: ").lang("No Address TO/CC/BCC supplied, and no folder to save message to provided.");
2969 3396
 				//error_log(__METHOD__.__LINE__.$this->errorInfo);
2970 3397
 				return false;
@@ -2974,14 +3401,16 @@  discard block
 block discarded – undo
2974 3401
 		//error_log(__METHOD__.__LINE__."Number of Folders to move copy the message to:".count($folder));
2975 3402
 		//error_log(__METHOD__.__LINE__.array2string($folder));
2976 3403
 		if ((count($folder) > 0) || (isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
2977
-            || (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3404
+            || (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder'])))
3405
+		{
2978 3406
 			$mail_bo = $this->mail_bo;
2979 3407
 			$mail_bo->openConnection();
2980 3408
 			//$mail_bo->reopen($this->sessionData['messageFolder']);
2981 3409
 			#error_log("(re)opened Connection");
2982 3410
 		}
2983 3411
 		// if copying mail to folder, or saving mail to infolog, we need to gather the needed information
2984
-		if (count($folder) > 0 || $_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') {
3412
+		if (count($folder) > 0 || $_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on')
3413
+		{
2985 3414
 			//error_log(__METHOD__.__LINE__.array2string($this->sessionData['bcc']));
2986 3415
 
2987 3416
 			// normaly Bcc is only added to recipients, but not as header visible to all recipients
@@ -2990,17 +3419,28 @@  discard block
 block discarded – undo
2990 3419
 		// copying mail to folder
2991 3420
 		if (count($folder) > 0)
2992 3421
 		{
2993
-			foreach($folderOnServerID as $folderName) {
2994
-				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3422
+			foreach($folderOnServerID as $folderName)
3423
+			{
3424
+				if (is_array($folderName))
3425
+				{
3426
+					$folderName = array_shift($folderName);
3427
+				}
3428
+				// should not happen at all
2995 3429
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
2996 3430
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
2997 3431
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
2998
-				if ($mail_bo->folderExists($folderName,true)) {
2999
-					if($mail_bo->isSentFolder($folderName)) {
3432
+				if ($mail_bo->folderExists($folderName,true))
3433
+				{
3434
+					if($mail_bo->isSentFolder($folderName))
3435
+					{
3000 3436
 						$flags = '\\Seen';
3001
-					} elseif($mail_bo->isDraftFolder($folderName)) {
3437
+					}
3438
+					elseif($mail_bo->isDraftFolder($folderName))
3439
+					{
3002 3440
 						$flags = '\\Draft';
3003
-					} else {
3441
+					}
3442
+					else
3443
+					{
3004 3444
 						$flags = '\\Seen';
3005 3445
 					}
3006 3446
 					#$mailHeader=explode('From:',$mail->getMessageHeader());
@@ -3023,18 +3463,32 @@  discard block
 block discarded – undo
3023 3463
 				}
3024 3464
 			}
3025 3465
 			// if we choose to send from a differing profile
3026
-			if ($folderOnMailAccount)  $this->changeProfile($_formData['mailaccount']);
3027
-			foreach($folderOnMailAccount as $folderName) {
3028
-				if (is_array($folderName)) $folderName = array_shift($folderName); // should not happen at all
3466
+			if ($folderOnMailAccount)
3467
+			{
3468
+				$this->changeProfile($_formData['mailaccount']);
3469
+			}
3470
+			foreach($folderOnMailAccount as $folderName)
3471
+			{
3472
+				if (is_array($folderName))
3473
+				{
3474
+					$folderName = array_shift($folderName);
3475
+				}
3476
+				// should not happen at all
3029 3477
 				//error_log(__METHOD__.__LINE__." attempt to save message to:".array2string($folderName));
3030 3478
 				// if $_formData['serverID']!=$_formData['mailaccount'] skip copying to sentfolder on serverID
3031 3479
 				// if($_formData['serverID']!=$_formData['mailaccount'] && $folderName==$sentFolder && $changeProfileOnSentFolderNeeded) continue;
3032
-				if ($this->mail_bo->folderExists($folderName,true)) {
3033
-					if($this->mail_bo->isSentFolder($folderName)) {
3480
+				if ($this->mail_bo->folderExists($folderName,true))
3481
+				{
3482
+					if($this->mail_bo->isSentFolder($folderName))
3483
+					{
3034 3484
 						$flags = '\\Seen';
3035
-					} elseif($this->mail_bo->isDraftFolder($folderName)) {
3485
+					}
3486
+					elseif($this->mail_bo->isDraftFolder($folderName))
3487
+					{
3036 3488
 						$flags = '\\Draft';
3037
-					} else {
3489
+					}
3490
+					else
3491
+					{
3038 3492
 						$flags = '\\Seen';
3039 3493
 					}
3040 3494
 					#$mailHeader=explode('From:',$mail->getMessageHeader());
@@ -3056,7 +3510,10 @@  discard block
 block discarded – undo
3056 3510
 					error_log(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$this->sessionData['subject'],$folderName));
3057 3511
 				}
3058 3512
 			}
3059
-			if ($folderOnMailAccount)  $this->changeProfile($_formData['serverID']);
3513
+			if ($folderOnMailAccount)
3514
+			{
3515
+				$this->changeProfile($_formData['serverID']);
3516
+			}
3060 3517
 
3061 3518
 			//$mail_bo->closeConnection();
3062 3519
 		}
@@ -3068,10 +3525,16 @@  discard block
 block discarded – undo
3068 3525
 			$dhA = mail_ui::splitRowID($this->sessionData['lastDrafted']);
3069 3526
 			$lastDrafted['uid'] = $dhA['msgUID'];
3070 3527
 			$lastDrafted['folder'] = $dhA['folder'];
3071
-			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid'])) $lastDrafted['uid']=trim($lastDrafted['uid']);
3528
+			if (isset($lastDrafted['uid']) && !empty($lastDrafted['uid']))
3529
+			{
3530
+				$lastDrafted['uid']=trim($lastDrafted['uid']);
3531
+			}
3072 3532
 			// manually drafted, do not delete
3073 3533
 			// will be handled later on IF mode was $_formData['mode']=='composefromdraft'
3074
-			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid'])) $lastDrafted=false;
3534
+			if (isset($lastDrafted['uid']) && (empty($lastDrafted['uid']) || $lastDrafted['uid'] == $this->sessionData['uid']))
3535
+			{
3536
+				$lastDrafted=false;
3537
+			}
3075 3538
 			//error_log(__METHOD__.__LINE__.array2string($lastDrafted));
3076 3539
 		}
3077 3540
 		if ($lastDrafted && is_array($lastDrafted) && $mail_bo->isDraftFolder($lastDrafted['folder']))
@@ -3097,7 +3560,8 @@  discard block
 block discarded – undo
3097 3560
 
3098 3561
 		//error_log("handling draft messages, flagging and such");
3099 3562
 		if((isset($this->sessionData['uid']) && isset($this->sessionData['messageFolder']))
3100
-			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder']))) {
3563
+			|| (isset($this->sessionData['forwardFlag']) && isset($this->sessionData['sourceFolder'])))
3564
+		{
3101 3565
 			// mark message as answered
3102 3566
 			$mail_bo->openConnection();
3103 3567
 			$mail_bo->reopen(($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
@@ -3119,7 +3583,9 @@  discard block
 block discarded – undo
3119 3583
 					//error_log(__METHOD__.__LINE__." ". str_replace('"',"'",$e->getMessage()));
3120 3584
 					unset($e);
3121 3585
 				}
3122
-			} else {
3586
+			}
3587
+			else
3588
+			{
3123 3589
 				$mail_bo->flagMessages("answered", $this->sessionData['uid'],($this->sessionData['messageFolder']?$this->sessionData['messageFolder']:$this->sessionData['sourceFolder']));
3124 3590
 				//error_log(__METHOD__.__LINE__.array2string(array_keys($this->sessionData)).':'.array2string($this->sessionData['forwardedUID']).' F:'.$this->sessionData['sourceFolder']);
3125 3591
 				if (array_key_exists('forwardFlag',$this->sessionData) && $this->sessionData['forwardFlag']=='forwarded')
@@ -3138,7 +3604,10 @@  discard block
 block discarded – undo
3138 3604
 			}
3139 3605
 			//$mail_bo->closeConnection();
3140 3606
 		}
3141
-		if ($mail_bo) $mail_bo->closeConnection();
3607
+		if ($mail_bo)
3608
+		{
3609
+			$mail_bo->closeConnection();
3610
+		}
3142 3611
 		//error_log("performing Infolog Stuff");
3143 3612
 		//error_log(print_r($this->sessionData['to'],true));
3144 3613
 		//error_log(print_r($this->sessionData['cc'],true));
@@ -3151,9 +3620,18 @@  discard block
 block discarded – undo
3151 3620
 		{
3152 3621
 			$mailaddresses = array();
3153 3622
 		}
3154
-		if (is_array($this->sessionData['cc'])) $mailaddresses['cc'] = $this->sessionData['cc'];
3155
-		if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc'];
3156
-		if (!empty($mailaddresses)) $mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3623
+		if (is_array($this->sessionData['cc']))
3624
+		{
3625
+			$mailaddresses['cc'] = $this->sessionData['cc'];
3626
+		}
3627
+		if (is_array($this->sessionData['bcc']))
3628
+		{
3629
+			$mailaddresses['bcc'] = $this->sessionData['bcc'];
3630
+		}
3631
+		if (!empty($mailaddresses))
3632
+		{
3633
+			$mailaddresses['from'] = Mail\Html::decodeMailHeader($fromAddress);
3634
+		}
3157 3635
 
3158 3636
 		if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )
3159 3637
 		{
@@ -3185,7 +3663,10 @@  discard block
 block discarded – undo
3185 3663
 							$_formData['serverID']),true),
3186 3664
 						'app' => $app_name
3187 3665
 					);
3188
-					if ($entryid) $target['entry_id'] = $entryid;
3666
+					if ($entryid)
3667
+					{
3668
+						$target['entry_id'] = $entryid;
3669
+					}
3189 3670
 					// Open the app called for integration in a popup
3190 3671
 					// and store the mail raw data as egw_data, in order to
3191 3672
 					// be stored from registered app method later
@@ -3196,8 +3677,11 @@  discard block
 block discarded – undo
3196 3677
 		// only clean up temp-files, if we dont need them for mail_integration::integrate
3197 3678
 		elseif(is_array($this->sessionData['attachments']))
3198 3679
 		{
3199
-			foreach($this->sessionData['attachments'] as $value) {
3200
-				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs') {	// happens when forwarding mails
3680
+			foreach($this->sessionData['attachments'] as $value)
3681
+			{
3682
+				if (!empty($value['file']) && parse_url($value['file'],PHP_URL_SCHEME) != 'vfs')
3683
+				{
3684
+// happens when forwarding mails
3201 3685
 					unlink($GLOBALS['egw_info']['server']['temp_dir'].'/'.$value['file']);
3202 3686
 				}
3203 3687
 			}
@@ -3234,7 +3718,10 @@  discard block
 block discarded – undo
3234 3718
 				$default_identity = null;
3235 3719
 				foreach(Mail\Account::identities($this->mail_bo->profileID, true, 'params') as $identity)
3236 3720
 				{
3237
-					if (!isset($default_identity)) $default_identity = $identity['ident_id'];
3721
+					if (!isset($default_identity))
3722
+					{
3723
+						$default_identity = $identity['ident_id'];
3724
+					}
3238 3725
 					if (!empty($identity['ident_signature']))
3239 3726
 					{
3240 3727
 						$content['mailidentity'] = $identity['ident_id'];
@@ -3242,12 +3729,18 @@  discard block
 block discarded – undo
3242 3729
 					}
3243 3730
 				}
3244 3731
 			}
3245
-			if (empty($content['mailidentity'])) $content['mailidentity'] = $default_identity;
3732
+			if (empty($content['mailidentity']))
3733
+			{
3734
+				$content['mailidentity'] = $default_identity;
3735
+			}
3246 3736
 		}
3247 3737
 		if (!isset($content['mimeType']) || empty($content['mimeType']))
3248 3738
 		{
3249 3739
 			$content['mimeType'] = 'html';
3250
-			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text") $content['mimeType']  = 'plain';
3740
+			if (!empty($this->mailPreferences['composeOptions']) && $this->mailPreferences['composeOptions']=="text")
3741
+			{
3742
+				$content['mimeType']  = 'plain';
3743
+			}
3251 3744
 		}
3252 3745
 		return $content;
3253 3746
 
@@ -3255,9 +3748,12 @@  discard block
 block discarded – undo
3255 3748
 
3256 3749
 	function stripSlashes($_string)
3257 3750
 	{
3258
-		if (get_magic_quotes_gpc()) {
3751
+		if (get_magic_quotes_gpc())
3752
+		{
3259 3753
 			return stripslashes($_string);
3260
-		} else {
3754
+		}
3755
+		else
3756
+		{
3261 3757
 			return $_string;
3262 3758
 		}
3263 3759
 	}
@@ -3270,15 +3766,25 @@  discard block
 block discarded – undo
3270 3766
 	 * @param boolean $_noPrefixId = false, if set to true folders name does not get prefixed by account id
3271 3767
 	 * @return type
3272 3768
 	 */
3273
-	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false) {
3769
+	function ajax_searchFolder($_searchStringLength=2, $_returnList=false, $_mailaccountToSearch=null, $_noPrefixId=false)
3770
+	{
3274 3771
 		//error_log(__METHOD__.__LINE__.':'.array2string($_REQUEST));
3275 3772
 		static $useCacheIfPossible = null;
3276
-		if (is_null($useCacheIfPossible)) $useCacheIfPossible = true;
3773
+		if (is_null($useCacheIfPossible))
3774
+		{
3775
+			$useCacheIfPossible = true;
3776
+		}
3277 3777
 		$_searchString = trim($_REQUEST['query']);
3278 3778
 		$results = array();
3279 3779
 		$rememberServerID = $this->mail_bo->icServer->ImapServerId;
3280
-		if (is_null($_mailaccountToSearch) && !empty($_REQUEST['mailaccount'])) $_mailaccountToSearch = $_REQUEST['mailaccount'];
3281
-		if (empty($_mailaccountToSearch)) $_mailaccountToSearch = $this->mail_bo->icServer->ImapServerId;
3780
+		if (is_null($_mailaccountToSearch) && !empty($_REQUEST['mailaccount']))
3781
+		{
3782
+			$_mailaccountToSearch = $_REQUEST['mailaccount'];
3783
+		}
3784
+		if (empty($_mailaccountToSearch))
3785
+		{
3786
+			$_mailaccountToSearch = $this->mail_bo->icServer->ImapServerId;
3787
+		}
3282 3788
 		if ($this->mail_bo->icServer && $_mailaccountToSearch && $this->mail_bo->icServer->ImapServerId != $_mailaccountToSearch)
3283 3789
 		{
3284 3790
 			$this->changeProfile($_mailaccountToSearch);
@@ -3289,7 +3795,8 @@  discard block
 block discarded – undo
3289 3795
 			$this->mail_bo->openConnection($this->mail_bo->icServer->ImapServerId);
3290 3796
 			//error_log(__METHOD__.__LINE__.array2string($_searchString).'<->'.$searchString);
3291 3797
 			$folderObjects = $this->mail_bo->getFolderObjects(true,false,true,$useCacheIfPossible);
3292
-			if (count($folderObjects)<=1) {
3798
+			if (count($folderObjects)<=1)
3799
+			{
3293 3800
 				$useCacheIfPossible = false;
3294 3801
 			}
3295 3802
 			else
@@ -3340,7 +3847,8 @@  discard block
 block discarded – undo
3340 3847
 		exit();
3341 3848
 	}
3342 3849
 
3343
-	public static function ajax_searchAddress($_searchStringLength=2) {
3850
+	public static function ajax_searchAddress($_searchStringLength=2)
3851
+	{
3344 3852
 		//error_log(__METHOD__. "request from seachAddress " . $_REQUEST['query']);
3345 3853
 		$_searchString = trim($_REQUEST['query']);
3346 3854
 		$include_lists = (boolean)$_REQUEST['include_lists'];
@@ -3353,7 +3861,8 @@  discard block
 block discarded – undo
3353 3861
 		{
3354 3862
 			$lists = array_filter(
3355 3863
 				$contacts_obj->get_lists(Acl::READ),
3356
-				function($element) use($_searchString) {
3864
+				function($element) use($_searchString)
3865
+				{
3357 3866
 					return (stripos($element, $_searchString) !== false);
3358 3867
 				}
3359 3868
 			);
@@ -3368,7 +3877,10 @@  discard block
 block discarded – undo
3368 3877
 					'title' => lang('Mailinglist'),
3369 3878
 					'data'	=> $key
3370 3879
 				);
3371
-				if($list_count++ > 5) break;
3880
+				if($list_count++ > 5)
3881
+				{
3882
+					break;
3883
+				}
3372 3884
 			}
3373 3885
 		}
3374 3886
 
@@ -3379,7 +3891,10 @@  discard block
 block discarded – undo
3379 3891
 			$search = explode(' ', $_searchString);
3380 3892
 			foreach ($search as $k => $v)
3381 3893
 			{
3382
-				if (mb_strlen($v) < 3) unset($search[$k]);
3894
+				if (mb_strlen($v) < 3)
3895
+				{
3896
+					unset($search[$k]);
3897
+				}
3383 3898
 			}
3384 3899
 			$search_str = implode(' +', $search);	// tell contacts/so_sql to AND search patterns
3385 3900
 			//error_log(__METHOD__.__LINE__.$_searchString);
@@ -3409,9 +3924,12 @@  discard block
 block discarded – undo
3409 3924
 			}
3410 3925
 		}
3411 3926
 		
3412
-		if(is_array($contacts)) {
3413
-			foreach($contacts as $contact) {
3414
-				foreach(array($contact['email'],$contact['email_home']) as $email) {
3927
+		if(is_array($contacts))
3928
+		{
3929
+			foreach($contacts as $contact)
3930
+			{
3931
+				foreach(array($contact['email'],$contact['email_home']) as $email)
3932
+				{
3415 3933
 					// avoid wrong addresses, if an rfc822 encoded address is in addressbook
3416 3934
 					//$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email);
3417 3935
 					$rfcAddr = Mail::parseAddressList($email);
@@ -3425,10 +3943,22 @@  discard block
 block discarded – undo
3425 3943
 					if (method_exists($contacts_obj,'search'))
3426 3944
 					{
3427 3945
 						$contact['n_fn']='';
3428
-						if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix'];
3429
-						if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3430
-						if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3431
-						if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3946
+						if (!empty($contact['n_prefix']))
3947
+						{
3948
+							$contact['n_fn'] = $contact['n_prefix'];
3949
+						}
3950
+						if (!empty($contact['n_given']))
3951
+						{
3952
+							$contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given'];
3953
+						}
3954
+						if (!empty($contact['n_family']))
3955
+						{
3956
+							$contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family'];
3957
+						}
3958
+						if (!empty($contact['org_name']))
3959
+						{
3960
+							$contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')';
3961
+						}
3432 3962
 						$contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']);
3433 3963
 					}
3434 3964
 					else
@@ -3438,7 +3968,8 @@  discard block
 block discarded – undo
3438 3968
 					$args = explode('@', trim($email));
3439 3969
 					$args[] = trim($contact['n_fn'] ? $contact['n_fn'] : $contact['fn']);
3440 3970
 					$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
3441
-					if(!empty($email) && in_array($completeMailString ,$results) === false) {
3971
+					if(!empty($email) && in_array($completeMailString ,$results) === false)
3972
+					{
3442 3973
 						$results[] = array(
3443 3974
 							'id'=>$completeMailString,
3444 3975
 							'label' => $completeMailString,
@@ -3457,7 +3988,10 @@  discard block
 block discarded – undo
3457 3988
 		foreach($groups as $g_id => $name)
3458 3989
 		{
3459 3990
 			$group = $GLOBALS['egw']->accounts->read($g_id);
3460
-			if(!$group['account_email']) continue;
3991
+			if(!$group['account_email'])
3992
+			{
3993
+				continue;
3994
+			}
3461 3995
 			$args = explode('@', trim($group['account_email']));
3462 3996
 			$args[] = $name;
3463 3997
 			$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
Please login to merge, or discard this patch.