Completed
Push — master ( f987ca...00ce22 )
by Klaus
25:05
created
mail/inc/class.mail_zpush.inc.php 1 patch
Braces   +605 added lines, -177 removed lines patch added patch discarded remove patch
@@ -84,29 +84,47 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function __construct(activesync_backend $backend)
86 86
 	{
87
-		if ($GLOBALS['egw_setup']) return;
87
+		if ($GLOBALS['egw_setup'])
88
+		{
89
+			return;
90
+		}
88 91
 
89 92
 		//$this->debugLevel=2;
90 93
 		$this->backend = $backend;
91 94
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
92 95
 		{
93
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
96
+			if ($this->debugLevel>1)
97
+			{
98
+				error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
99
+			}
94 100
 			// globals preferences add appname varname value
95 101
 			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
96 102
 			// save prefs
97 103
 			$GLOBALS['egw']->preferences->save_repository(true);
98 104
 		}
99
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
105
+		if ($this->debugLevel>1)
106
+		{
107
+			error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
108
+		}
100 109
 
101 110
 		if (is_null(self::$profileID))
102 111
 		{
103
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
112
+			if ($this->debugLevel>1)
113
+			{
114
+				error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
115
+			}
104 116
 			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
105
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
117
+			if ($this->debugLevel>1)
118
+			{
119
+				error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
120
+			}
106 121
 		}
107 122
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
108 123
 		{
109
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
124
+			if ($this->debugLevel>1)
125
+			{
126
+				error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
127
+			}
110 128
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
111 129
 			{
112 130
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -116,7 +134,10 @@  discard block
 block discarded – undo
116 134
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
117 135
 			}
118 136
 		}
119
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
137
+		if ($this->debugLevel>1)
138
+		{
139
+			error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
140
+		}
120 141
 
121 142
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
122 143
 		if (!isset($GLOBALS['egw_setup']))
@@ -129,7 +150,10 @@  discard block
 block discarded – undo
129 150
 				self::$profileID = Mail\Account::get_default_acc_id();
130 151
 			}
131 152
 		}
132
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
153
+		if ($this->debugLevel>0)
154
+		{
155
+			error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
156
+		}
133 157
 		//$this->debugLevel=0;
134 158
 	}
135 159
 
@@ -245,8 +269,14 @@  discard block
 block discarded – undo
245 269
 				$this->_connect(0,true);
246 270
 				$this->_disconnect();
247 271
 
248
-				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
249
-				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
272
+				if (!$this->_wasteID)
273
+				{
274
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
275
+				}
276
+				if (!$this->_sentID)
277
+				{
278
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
279
+				}
250 280
 			}
251 281
 			catch(Exception $e) {
252 282
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
@@ -268,8 +298,14 @@  discard block
 block discarded – undo
268 298
 	 */
269 299
 	private function _connect($account=0)
270 300
 	{
271
-		if (!$account) $account = self::$profileID ? self::$profileID : 0;
272
-		if ($this->mail && $this->account != $account) $this->_disconnect();
301
+		if (!$account)
302
+		{
303
+			$account = self::$profileID ? self::$profileID : 0;
304
+		}
305
+		if ($this->mail && $this->account != $account)
306
+		{
307
+			$this->_disconnect();
308
+		}
273 309
 
274 310
 		$this->_wasteID = false;
275 311
 		$this->_sentID = false;
@@ -280,12 +316,18 @@  discard block
 block discarded – undo
280 316
 			// todo: tell mail which account to use
281 317
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
282 318
 			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
283
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
319
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
320
+			{
321
+				self::$profileID = $this->mail->icServer->ImapServerId;
322
+			}
284 323
 		}
285 324
 		else
286 325
 		{
287 326
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
288
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
327
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
328
+			{
329
+				self::$profileID = $this->mail->icServer->ImapServerId;
330
+			}
289 331
 		}
290 332
 		$this->mail->openConnection(self::$profileID,false);
291 333
 
@@ -302,8 +344,14 @@  discard block
 block discarded – undo
302 344
 	 */
303 345
 	private function _disconnect()
304 346
 	{
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
306
-		if ($this->mail) $this->mail->closeConnection();
347
+		if ($this->debugLevel>0)
348
+		{
349
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
350
+		}
351
+		if ($this->mail)
352
+		{
353
+			$this->mail->closeConnection();
354
+		}
307 355
 
308 356
 		unset($this->mail);
309 357
 		unset($this->account);
@@ -318,24 +366,43 @@  discard block
 block discarded – undo
318 366
 	public function GetFolderList()
319 367
 	{
320 368
 		$folderlist = array();
321
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
369
+		if ($this->debugLevel>0)
370
+		{
371
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
372
+		}
322 373
 		/*foreach($available_accounts as $account)*/ $account = 0;
323 374
 		{
324 375
 			$this->_connect($account);
325
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
326
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
376
+			if (!isset($this->folders))
377
+			{
378
+				$this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
379
+			}
380
+			if ($this->debugLevel>1)
381
+			{
382
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
383
+			}
327 384
 
328
-			foreach ($this->folders as $folder => $folderObj) {
329
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
385
+			foreach ($this->folders as $folder => $folderObj)
386
+			{
387
+				if ($this->debugLevel>1)
388
+				{
389
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
390
+				}
330 391
 				$folderlist[] = $f = array(
331 392
 					'id'     => $this->createID($account,$folder),
332 393
 					'mod'    => $folderObj->shortDisplayName,
333 394
 					'parent' => $this->getParentID($account,$folder),
334 395
 				);
335
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
396
+				if ($this->debugLevel>1)
397
+				{
398
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
399
+				}
336 400
 			}
337 401
 		}
338
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
402
+		if ($this->debugLevel>0)
403
+		{
404
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
405
+		}
339 406
 
340 407
 		return $folderlist;
341 408
 	}
@@ -396,11 +463,17 @@  discard block
 block discarded – undo
396 463
 		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
397 464
 
398 465
    		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
399
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
466
+		if ($this->debugLevel>0)
467
+		{
468
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
469
+		}
400 470
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
401 471
 
402 472
 		// initialize our Mail
403
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
473
+		if (!isset($this->mail))
474
+		{
475
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
476
+		}
404 477
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
405 478
 		// use the standardIdentity
406 479
 		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
@@ -428,12 +501,18 @@  discard block
 block discarded – undo
428 501
 		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
429 502
 		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
430 503
 		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
431
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
504
+		if ($this->debugLevel>0)
505
+		{
506
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
507
+		}
432 508
 		$sigTextHtml = $beforeHtml.$sigText;
433 509
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
434 510
 
435 511
 		$force8bit=false;
436
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
512
+		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii')
513
+		{
514
+			$force8bit=true;
515
+		}
437 516
 		// initialize the new Api\Mailer object for sending
438 517
 		$mailObject = new Api\Mailer(self::$profileID);
439 518
 
@@ -447,22 +526,34 @@  discard block
 block discarded – undo
447 526
 		// prepare addressee list; moved the adding of addresses to the mailobject down
448 527
 		// to
449 528
 
450
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
451
-			if (!$addressObject->valid) continue;
529
+		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject)
530
+		{
531
+			if (!$addressObject->valid)
532
+			{
533
+				continue;
534
+			}
452 535
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
453 536
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
454 537
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
455 538
 		}
456 539
 		// CC
457
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
458
-			if (!$addressObject->valid) continue;
540
+		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject)
541
+		{
542
+			if (!$addressObject->valid)
543
+			{
544
+				continue;
545
+			}
459 546
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
460 547
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
461 548
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
462 549
 		}
463 550
 		// BCC
464
-		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
465
-			if (!$addressObject->valid) continue;
551
+		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject)
552
+		{
553
+			if (!$addressObject->valid)
554
+			{
555
+				continue;
556
+			}
466 557
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
467 558
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
468 559
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
@@ -475,12 +566,14 @@  discard block
 block discarded – undo
475 566
 		$ContentType =$mailObject->getHeader('Content-Type');
476 567
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
477 568
 		// if the message is a multipart message, then we should use the sent body
478
-		if (preg_match("/multipart/i", $ContentType)) {
569
+		if (preg_match("/multipart/i", $ContentType))
570
+		{
479 571
 			$use_orgbody = true;
480 572
 		}
481 573
 
482 574
 		// save the original content-type header for the body part when forwarding
483
-		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
575
+		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody)
576
+		{
484 577
 			//continue; // ignore
485 578
 		}
486 579
 		// horde/egw_ mailer does everything as utf-8, the following should not be needed
@@ -489,7 +582,8 @@  discard block
 block discarded – undo
489 582
 		// if the message is a multipart message, then we should use the sent body
490 583
 		if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
491 584
 			((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
492
-			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
585
+			$k == "Content-Type" && preg_match("/multipart/i", $ContentType)))
586
+		{
493 587
 			$use_orgbody = true;
494 588
 		}
495 589
 		$Body =  $AltBody = "";
@@ -522,12 +616,19 @@  discard block
 block discarded – undo
522 616
 			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
523 617
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
524 618
 		}
525
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
526
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
619
+		if ($this->debugLevel>1 && $Body)
620
+		{
621
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
622
+		}
623
+		if ($this->debugLevel>1 && $AltBody)
624
+		{
625
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
626
+		}
527 627
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
528 628
 		// if this is a multipart message with a boundary, we must use the original body
529 629
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
530
-        if ($use_orgbody) {
630
+        if ($use_orgbody)
631
+        {
531 632
     	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
532 633
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
533 634
 			if (($cal_body = $mailObject->findBody('calendar')) &&
@@ -537,15 +638,20 @@  discard block
 block discarded – undo
537 638
 				{
538 639
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
539 640
 				}
540
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
641
+				if ($this->debugLevel)
642
+				{
643
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
644
+				}
541 645
 				$ClientSideMeetingRequest = true;
542 646
 			}
543 647
         }
544 648
 		// now handle the addressee list
545 649
 		$toCount = 0;
546 650
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
547
-		foreach((array)$toMailAddr as $address) {
548
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
651
+		foreach((array)$toMailAddr as $address)
652
+		{
653
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
654
+			{
549 655
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
550 656
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
551 657
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
@@ -559,19 +665,29 @@  discard block
 block discarded – undo
559 665
 			}
560 666
 		}
561 667
 		$ccCount = 0;
562
-		foreach((array)$ccMailAddr as $address) {
563
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
668
+		foreach((array)$ccMailAddr as $address)
669
+		{
670
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
671
+			{
564 672
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
565
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
673
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
674
+				{
675
+					continue;
676
+				}
566 677
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
567 678
 				$ccCount++;
568 679
 			}
569 680
 		}
570 681
 		$bccCount = 0;
571
-		foreach((array)$bccMailAddr as $address) {
572
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
682
+		foreach((array)$bccMailAddr as $address)
683
+		{
684
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
685
+			{
573 686
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
574
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
687
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
688
+				{
689
+					continue;
690
+				}
575 691
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
576 692
 				$bccCount++;
577 693
 			}
@@ -581,7 +697,10 @@  discard block
 block discarded – undo
581 697
 		{
582 698
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
583 699
 		}
584
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
700
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false)
701
+		{
702
+			return true;
703
+		}
585 704
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
586 705
 /*
587 706
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -604,10 +723,17 @@  discard block
 block discarded – undo
604 723
 			$this->mail->reopen($folder);
605 724
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
606 725
 			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
607
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
608
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
726
+			if ($this->debugLevel>3)
727
+			{
728
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
729
+			}
730
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
731
+		    {
609 732
 				// may be html
610
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
733
+				if ($this->debugLevel>0)
734
+				{
735
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
736
+				}
611 737
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
612 738
 				$isreply = true;
613 739
 			}
@@ -616,8 +742,12 @@  discard block
 block discarded – undo
616 742
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
617 743
 			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
618 744
 			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
619
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
620
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
745
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
746
+			{
747
+				if ($this->debugLevel>0)
748
+				{
749
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
750
+				}
621 751
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
622 752
 				$isreply = true;
623 753
 			}
@@ -625,7 +755,10 @@  discard block
 block discarded – undo
625 755
 			{
626 756
 				$isreply = true;
627 757
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
628
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
758
+				if ($this->debugLevel>0)
759
+				{
760
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
761
+				}
629 762
 			}
630 763
 		}
631 764
 
@@ -639,11 +772,17 @@  discard block
 block discarded – undo
639 772
 			(isset($smartdata->replacemime) && $smartdata->replacemime == false)))
640 773
 		{
641 774
 			//force the default for the forwarding -> asmail
642
-			if (is_array($preferencesArray)) {
775
+			if (is_array($preferencesArray))
776
+			{
643 777
 				if (!array_key_exists('message_forwarding',$preferencesArray)
644 778
 					|| !isset($preferencesArray['message_forwarding'])
645
-					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
646
-			} else {
779
+					|| empty($preferencesArray['message_forwarding']))
780
+				{
781
+					$preferencesArray['message_forwarding'] = 'asmail';
782
+				}
783
+			}
784
+			else
785
+			{
647 786
 				$preferencesArray['message_forwarding'] = 'asmail';
648 787
 			}
649 788
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
@@ -675,27 +814,44 @@  discard block
 block discarded – undo
675 814
 				$this->mail->reopen($folder);
676 815
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
677 816
 				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
678
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
679
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
817
+				if ($this->debugLevel>0)
818
+				{
819
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
820
+				}
821
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
822
+				{
680 823
 					// may be html
681
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
824
+					if ($this->debugLevel>0)
825
+					{
826
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
827
+					}
682 828
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
683 829
 					$isforward = true;
684 830
 				}
685 831
 				// plain text Message part
686
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
832
+				if ($this->debugLevel>0)
833
+				{
834
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
835
+				}
687 836
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
688 837
 				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
689 838
 				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
690
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
691
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
839
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
840
+				{
841
+					if ($this->debugLevel>0)
842
+					{
843
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
844
+					}
692 845
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
693 846
 					$isforward = true;
694 847
 				}
695 848
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
696 849
 				{
697 850
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
698
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
851
+					if ($this->debugLevel>0)
852
+					{
853
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
854
+					}
699 855
 					$isforward = true;
700 856
 				}
701 857
 				// get all the attachments and add them too.
@@ -708,7 +864,10 @@  discard block
 block discarded – undo
708 864
 					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
709 865
 					foreach((array)$attachments as $key => $attachment)
710 866
 					{
711
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
867
+						if ($this->debugLevel>0)
868
+						{
869
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
870
+						}
712 871
 						$attachmentNames .= $attachment['name']."\n";
713 872
 						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
714 873
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
@@ -727,20 +886,29 @@  discard block
 block discarded – undo
727 886
 		// now set the body
728 887
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
729 888
 		{
730
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
889
+			if ($this->debugLevel>1)
890
+			{
891
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
892
+			}
731 893
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
732 894
 			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
733 895
 		}
734 896
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
735 897
 		{
736
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
898
+			if ($this->debugLevel>1)
899
+			{
900
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
901
+			}
737 902
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
738 903
 			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
739 904
 		}
740 905
 		//advanced debugging
741 906
 		// Horde SMTP Class uses utf-8 by default.
742 907
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
743
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
908
+		if ($this->debugLevel>2)
909
+		{
910
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
911
+		}
744 912
 
745 913
 		// set a higher timeout for big messages
746 914
 		@set_time_limit(120);
@@ -767,7 +935,9 @@  discard block
 block discarded – undo
767 935
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
768 936
 			{
769 937
 				$this->mail->deleteMessages(array($uid),$folder);
770
-			} else {
938
+			}
939
+			else
940
+			{
771 941
 				$this->mail->flagMessages("answered", array($uid),$folder);
772 942
 				if ($smartdata_task== "forward")
773 943
 				{
@@ -781,7 +951,8 @@  discard block
 block discarded – undo
781 951
 		{
782 952
 			$asf = false;
783 953
 			$sentFolder = $this->mail->getSentFolder();
784
-			if ($this->_sentID) {
954
+			if ($this->_sentID)
955
+			{
785 956
 				$folderArray[] = $this->_sentID;
786 957
 			}
787 958
 			else if(isset($sentFolder) && $sentFolder != 'none')
@@ -795,27 +966,40 @@  discard block
 block discarded – undo
795 966
 				// we dont try guessing
796 967
 				$asf = true;
797 968
 			}
798
-			if (count($folderArray) > 0) {
799
-				foreach((array)$bccMailAddr as $address) {
800
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
969
+			if (count($folderArray) > 0)
970
+			{
971
+				foreach((array)$bccMailAddr as $address)
972
+				{
973
+					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
974
+					{
801 975
 						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
802 976
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
803 977
 					}
804 978
 				}
805 979
 				$BCCmail='';
806
-				if (count($mailAddr)>0) $BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
807
-				foreach($folderArray as $folderName) {
808
-					if($this->mail->isSentFolder($folderName)) {
980
+				if (count($mailAddr)>0)
981
+				{
982
+					$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
983
+				}
984
+				foreach($folderArray as $folderName)
985
+				{
986
+					if($this->mail->isSentFolder($folderName))
987
+					{
809 988
 						$flags = '\\Seen';
810
-					} elseif($this->mail->isDraftFolder($folderName)) {
989
+					}
990
+					elseif($this->mail->isDraftFolder($folderName))
991
+					{
811 992
 						$flags = '\\Draft';
812
-					} else {
993
+					}
994
+					else
995
+					{
813 996
 						$flags = '';
814 997
 					}
815 998
 					$asf = true;
816 999
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
817 1000
 					$this->mail->openConnection(self::$profileID,false);
818
-					if ($this->mail->folderExists($folderName)) {
1001
+					if ($this->mail->folderExists($folderName))
1002
+					{
819 1003
 						try
820 1004
 						{
821 1005
 							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
@@ -873,17 +1057,26 @@  discard block
 block discarded – undo
873 1057
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
874 1058
 
875 1059
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
876
-		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
1060
+		if (!$mimesupport && ($key = array_search('4', $bodypreference)))
1061
+		{
1062
+			unset($bodypreference[$key]);
1063
+		}
877 1064
 
878 1065
 		//$this->debugLevel=4;
879
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1066
+		if (!isset($this->mail))
1067
+		{
1068
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1069
+		}
880 1070
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
881 1071
 		$account = $_folderName = $xid = null;
882 1072
 		$this->splitID($folderid,$account,$_folderName,$xid);
883 1073
 		$this->mail->reopen($_folderName);
884 1074
 		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
885 1075
 		$headers = $messages[$id];
886
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1076
+		if ($this->debugLevel>3)
1077
+		{
1078
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1079
+		}
887 1080
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
888 1081
 		if ($headers)
889 1082
 		{
@@ -893,16 +1086,25 @@  discard block
 block discarded – undo
893 1086
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
894 1087
 			// simple style
895 1088
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
896
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1089
+			if ($this->debugLevel>0)
1090
+			{
1091
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1092
+			}
897 1093
 
898
-			if ($bodypreference === false) {
1094
+			if ($bodypreference === false)
1095
+			{
899 1096
 				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
900 1097
 				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
901 1098
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
902
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
1099
+				if (stripos($raw_body,'<style')!==false)
1100
+				{
1101
+					$body = preg_replace("/<style.*?<\/style>/is", "", $raw_body);
1102
+				}
1103
+				// in case there is only a html part
903 1104
 				// remove all other html
904 1105
 				$body = strip_tags($raw_body);
905
-				if(strlen($body) > $truncsize) {
1106
+				if(strlen($body) > $truncsize)
1107
+				{
906 1108
 					$body = Utils::Utf8_truncate($body, $truncsize);
907 1109
 					$output->bodytruncated = 1;
908 1110
 				}
@@ -917,7 +1119,8 @@  discard block
 block discarded – undo
917 1119
 			{
918 1120
 				//Select body type preference
919 1121
 				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
920
-				if ($bodypreference !== false) {
1122
+				if ($bodypreference !== false)
1123
+				{
921 1124
 					// bodypreference can occur multiple times
922 1125
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
923 1126
 					$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -951,25 +1154,49 @@  discard block
 block discarded – undo
951 1154
 					// fetch the body (try to gather data only once)
952 1155
 					$css ='';
953 1156
 					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
954
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1157
+					if ($this->debugLevel>2)
1158
+					{
1159
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1160
+					}
955 1161
 					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
956
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
957
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
1162
+					if ($this->debugLevel>3)
1163
+					{
1164
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
1165
+					}
1166
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
1167
+					{
958 1168
 						// may be html
959
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1169
+						if ($this->debugLevel>0)
1170
+						{
1171
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1172
+						}
960 1173
 						$css = $this->mail->getStyles($bodyStruct);
961 1174
 						$output->nativebodytype=2;
962
-					} else {
1175
+					}
1176
+					else
1177
+					{
963 1178
 						// plain text Message
964
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1179
+						if ($this->debugLevel>0)
1180
+						{
1181
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1182
+						}
965 1183
 						$output->nativebodytype=1;
966 1184
 						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
967
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1185
+						if ($this->debugLevel>3)
1186
+						{
1187
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1188
+						}
968 1189
 						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
969
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1190
+						if ($this->debugLevel>3)
1191
+						{
1192
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1193
+						}
970 1194
 					}
971 1195
 					// whatever format decode (using the correct encoding)
972
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1196
+					if ($this->debugLevel>3)
1197
+					{
1198
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1199
+					}
973 1200
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
974 1201
 					// prepare plaintextbody
975 1202
 					$plainBody='';
@@ -990,12 +1217,18 @@  discard block
 block discarded – undo
990 1217
 					// remove all other html
991 1218
 					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
992 1219
 					$plainBody = strip_tags($plainBody);
993
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1220
+					if ($this->debugLevel>3 && $output->nativebodytype==1)
1221
+					{
1222
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1223
+					}
994 1224
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
995 1225
 
996
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
1226
+					if ($bpReturnType==2)
1227
+					{
1228
+						//SYNC_BODYPREFERENCE_HTML
997 1229
 					{
998 1230
 						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
1231
+					}
999 1232
 						// Send HTML if requested and native type was html
1000 1233
 						$output->asbody->type = 2;
1001 1234
 						$htmlbody = '<html>'.
@@ -1007,7 +1240,10 @@  discard block
 block discarded – undo
1007 1240
 							'<body>';
1008 1241
 						if ($output->nativebodytype==2)
1009 1242
 						{
1010
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
1243
+							if ($css)
1244
+							{
1245
+								Api\Mail\Html::replaceTagsCompletley($body,'style');
1246
+							}
1011 1247
 							// as we fetch html, and body is HTML, we may not need to handle this
1012 1248
 							$htmlbody .= $body;
1013 1249
 						}
@@ -1032,7 +1268,10 @@  discard block
 block discarded – undo
1032 1268
 					else
1033 1269
 					{
1034 1270
 						// Send Plaintext as Fallback or if original body is plainttext
1035
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1271
+						if ($this->debugLevel>0)
1272
+						{
1273
+							ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1274
+						}
1036 1275
 						/* we use plainBody (set above) instead
1037 1276
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1038 1277
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1069,7 +1308,9 @@  discard block
 block discarded – undo
1069 1308
 			{
1070 1309
 				$output->flag->flagstatus = 2;
1071 1310
 				//$output->flag->flagtype = "Flag for Follow up";
1072
-			} else {
1311
+			}
1312
+			else
1313
+			{
1073 1314
 				$output->flag->flagstatus = 0;
1074 1315
 			}
1075 1316
 			if ($headers['answered'])
@@ -1085,10 +1326,20 @@  discard block
 block discarded – undo
1085 1326
 				($headers['priority'] < 3 ? 2 : 1) ;
1086 1327
 			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1087 1328
 			$output->to = $headers['to_address'];
1088
-			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1329
+			if ($headers['to'])
1330
+			{
1331
+				$output->displayto = $headers['to_address'];
1332
+			}
1333
+			//$headers['FETCHED_HEADER']['to_name']
1089 1334
 			$output->from = $headers['sender_address'];
1090
-			if (isset($headers['cc_addresses']) && $headers['cc_addresses']) $output->cc = $headers['cc_addresses'];
1091
-			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1335
+			if (isset($headers['cc_addresses']) && $headers['cc_addresses'])
1336
+			{
1337
+				$output->cc = $headers['cc_addresses'];
1338
+			}
1339
+			if (isset($headers['reply_to_address']) && $headers['reply_to_address'])
1340
+			{
1341
+				$output->reply_to = $headers['reply_to_address'];
1342
+			}
1092 1343
 
1093 1344
 			$output->messageclass = "IPM.Note";
1094 1345
 			if (stripos($headers['mimetype'],'multipart')!== false &&
@@ -1096,7 +1347,8 @@  discard block
 block discarded – undo
1096 1347
 			{
1097 1348
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1098 1349
 			}
1099
-			if (Request::GetProtocolVersion() >= 12.0) {
1350
+			if (Request::GetProtocolVersion() >= 12.0)
1351
+			{
1100 1352
 				$output->contentclass = "urn:content-classes:message";
1101 1353
 			}
1102 1354
 
@@ -1109,7 +1361,10 @@  discard block
 block discarded – undo
1109 1361
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1110 1362
 				foreach ($attachments as $key => $attach)
1111 1363
 				{
1112
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1364
+					if ($this->debugLevel>0)
1365
+					{
1366
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1367
+					}
1113 1368
 
1114 1369
 					// pass meeting requests to calendar plugin
1115 1370
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
@@ -1126,17 +1381,24 @@  discard block
 block discarded – undo
1126 1381
 						unset($attachment);
1127 1382
 						continue;	// do NOT add attachment as attachment
1128 1383
 					}
1129
-					if (Request::GetProtocolVersion() >= 12.0) {
1384
+					if (Request::GetProtocolVersion() >= 12.0)
1385
+					{
1130 1386
 						$attachment = new SyncBaseAttachment();
1131 1387
 						if (!isset($output->asattachments) || !is_array($output->asattachments))
1132
-							$output->asattachments = array();
1388
+						{
1389
+													$output->asattachments = array();
1390
+						}
1133 1391
 						$attachment->estimatedDataSize = $attach['size'];
1134 1392
 						$attachment->method = 1;
1135 1393
 						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1136
-					} else {
1394
+					}
1395
+					else
1396
+					{
1137 1397
 						$attachment = new SyncAttachment();
1138 1398
 						if (!isset($output->attachments) || !is_array($output->attachments))
1139
-							$output->attachments = array();
1399
+						{
1400
+													$output->attachments = array();
1401
+						}
1140 1402
 						$attachment->attsize = $attach['size'];
1141 1403
 						$attachment->attmethod = 1;
1142 1404
 						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
@@ -1153,10 +1415,13 @@  discard block
 block discarded – undo
1153 1415
 						{
1154 1416
 							$attachment->isinline = true;
1155 1417
 						}
1156
-						if (Request::GetProtocolVersion() >= 12.0) {
1418
+						if (Request::GetProtocolVersion() >= 12.0)
1419
+						{
1157 1420
 							$attachment->method=1;
1158 1421
 							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1159
-						} else {
1422
+						}
1423
+						else
1424
+						{
1160 1425
 							$attachment->attmethod=6;
1161 1426
 							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1162 1427
 						}
@@ -1164,9 +1429,12 @@  discard block
 block discarded – undo
1164 1429
 						$attachment->contenttype = trim($attach['mimeType']);
1165 1430
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."'  ".$attachment->contentid);
1166 1431
 					}
1167
-					if (Request::GetProtocolVersion() >= 12.0) {
1432
+					if (Request::GetProtocolVersion() >= 12.0)
1433
+					{
1168 1434
 						array_push($output->asattachments, $attachment);
1169
-					} else {
1435
+					}
1436
+					else
1437
+					{
1170 1438
 						array_push($output->attachments, $attachment);
1171 1439
 					}
1172 1440
 					unset($attachment);
@@ -1179,8 +1447,11 @@  discard block
 block discarded – undo
1179 1447
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1180 1448
             $output->internetcpid = INTERNET_CPID_UTF8;
1181 1449
 
1182
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1183
-//$this->debugLevel=0;
1450
+			if ($this->debugLevel>3)
1451
+			{
1452
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1453
+			}
1454
+			//$this->debugLevel=0;
1184 1455
 			return $output;
1185 1456
 		}
1186 1457
 //$this->debugLevel=0;
@@ -1239,7 +1510,8 @@  discard block
 block discarded – undo
1239 1510
      * @param string $attname - should contain (folder)id
1240 1511
 	 * @return SyncItemOperationsAttachment-object
1241 1512
 	 */
1242
-	function GetAttachmentData($fid,$attname) {
1513
+	function GetAttachmentData($fid,$attname)
1514
+	{
1243 1515
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1244 1516
 		return $this->_GetAttachmentData($fid,$attname);
1245 1517
 	}
@@ -1254,7 +1526,8 @@  discard block
 block discarded – undo
1254 1526
      * @param string $attname - should contain (folder)id
1255 1527
 	 * @return SyncItemOperationsAttachment-object
1256 1528
 	 */
1257
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1529
+	function ItemOperationsGetAttachmentData($fid,$attname)
1530
+	{
1258 1531
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1259 1532
 		return $this->_GetAttachmentData($fid,$attname);
1260 1533
 	}
@@ -1276,7 +1549,10 @@  discard block
 block discarded – undo
1276 1549
 
1277 1550
 		$this->splitID($folderid, $account, $folder);
1278 1551
 
1279
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1552
+		if (!isset($this->mail))
1553
+		{
1554
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1555
+		}
1280 1556
 
1281 1557
 		$this->mail->reopen($folder);
1282 1558
 		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
@@ -1285,7 +1561,9 @@  discard block
 block discarded – undo
1285 1561
 		$SIOattachment->data = $attachment['attachment'];
1286 1562
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1287 1563
 		if (isset($attachment['type']) )
1288
-			$SIOattachment->contenttype = $attachment['type'];
1564
+		{
1565
+					$SIOattachment->contenttype = $attachment['type'];
1566
+		}
1289 1567
 
1290 1568
 		unset($attachment);
1291 1569
 
@@ -1331,11 +1609,15 @@  discard block
 block discarded – undo
1331 1609
 		//unset($folderid, $id, $message, $contentParameters);
1332 1610
 		$account = $folder = null;
1333 1611
 		$this->splitID($folderid, $account, $folder);
1334
-		if (isset($message->flag)) {
1335
-			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1612
+		if (isset($message->flag))
1613
+		{
1614
+			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2)
1615
+			{
1336 1616
 				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1337 1617
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1338
-			} else {
1618
+			}
1619
+			else
1620
+			{
1339 1621
 				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1340 1622
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1341 1623
 			}
@@ -1365,7 +1647,10 @@  discard block
 block discarded – undo
1365 1647
 		$this->splitID($folderid, $account, $srcFolder);
1366 1648
 		$this->splitID($newfolderid, $account, $destFolder);
1367 1649
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1368
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1650
+		if (!isset($this->mail))
1651
+		{
1652
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1653
+		}
1369 1654
 		$this->mail->reopen($destFolder);
1370 1655
 		$status = $this->mail->getFolderStatus($destFolder);
1371 1656
 		$uidNext = $status['uidnext'];
@@ -1397,7 +1682,10 @@  discard block
 block discarded – undo
1397 1682
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1398 1683
 			}
1399 1684
 			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1400
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1685
+			if (is_numeric($maximumSyncRangeInDays))
1686
+			{
1687
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1688
+			}
1401 1689
 		}
1402 1690
 		return $this->fetchMessages($folderid, $cutoffdate);
1403 1691
 	}
@@ -1419,7 +1707,10 @@  discard block
 block discarded – undo
1419 1707
 	{
1420 1708
 		static $headers = array();
1421 1709
 
1422
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1710
+		if ($this->debugLevel>1)
1711
+		{
1712
+			$gstarttime = microtime (true);
1713
+		}
1423 1714
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1424 1715
 		$rv_messages = array();
1425 1716
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1432,7 +1723,10 @@  discard block
 block discarded – undo
1432 1723
 		{
1433 1724
 			$headers = array();	// clear cache to not use too much memory
1434 1725
 
1435
-			if ($this->debugLevel>1) $starttime = microtime (true);
1726
+			if ($this->debugLevel>1)
1727
+			{
1728
+				$starttime = microtime (true);
1729
+			}
1436 1730
 			$this->_connect($this->account);
1437 1731
 			if ($this->debugLevel>1)
1438 1732
 			{
@@ -1441,8 +1735,14 @@  discard block
 block discarded – undo
1441 1735
 			}
1442 1736
 			$messagelist = $_filter = array();
1443 1737
 			// if not connected, any further action must fail
1444
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1445
-			if ($this->debugLevel>1) $starttime = microtime (true);
1738
+			if (!empty($cutoffdate))
1739
+			{
1740
+				$_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1741
+			}
1742
+			if ($this->debugLevel>1)
1743
+			{
1744
+				$starttime = microtime (true);
1745
+			}
1446 1746
 			$account = $_folderName = $id = null;
1447 1747
 			$this->splitID($folderid,$account,$_folderName,$id);
1448 1748
 			if ($this->debugLevel>1)
@@ -1450,8 +1750,14 @@  discard block
 block discarded – undo
1450 1750
 				$endtime = microtime(true) - $starttime;
1451 1751
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1452 1752
 			}
1453
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1454
-			if ($this->debugLevel>1) $starttime = microtime (true);
1753
+			if ($this->debugLevel>1)
1754
+			{
1755
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1756
+			}
1757
+			if ($this->debugLevel>1)
1758
+			{
1759
+				$starttime = microtime (true);
1760
+			}
1455 1761
 			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1456 1762
 			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1457 1763
 			if ($this->debugLevel>1)
@@ -1460,27 +1766,56 @@  discard block
 block discarded – undo
1460 1766
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1461 1767
 			}
1462 1768
 		}
1463
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1769
+		if ($_id == NULL && $this->debugLevel>1)
1770
+		{
1771
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1772
+		}
1464 1773
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1465 1774
 		$messagelist = array();
1466
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1775
+		if (!isset($rv_messages['header'])||empty($rv_messages['header']))
1776
+		{
1777
+			return $messagelist;
1778
+		}
1467 1779
 		//if ($_returnModHash) $messageFolderHash = array();
1468 1780
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1469 1781
 		{
1470
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1782
+			if ($this->debugLevel>3)
1783
+			{
1784
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1785
+			}
1471 1786
 			$headers[$vars['uid']] = $vars;
1472
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1473
-			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1474
-			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1475
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1787
+			if ($this->debugLevel>3)
1788
+			{
1789
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1790
+			}
1791
+			if (!empty($vars['deleted']))
1792
+			{
1793
+				continue;
1794
+			}
1795
+			// cut of deleted messages
1796
+			if ($cutoffdate && $vars['date'] < $cutoffdate)
1797
+			{
1798
+				continue;
1799
+			}
1800
+			// message is out of range for cutoffdate, ignore it
1801
+			if ($this->debugLevel>0)
1802
+			{
1803
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1804
+			}
1476 1805
 			$mess = $return_all_headers ? $vars : array();
1477 1806
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1478 1807
 			$mess["id"] = $vars['uid'];
1479 1808
 			// 'seen' aka 'read' is the only flag we want to know about
1480 1809
 			$mess["flags"] = 0;
1481 1810
 			// outlook supports additional flags, set them to 0
1482
-			if($vars["seen"]) $mess["flags"] = 1;
1483
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1811
+			if($vars["seen"])
1812
+			{
1813
+				$mess["flags"] = 1;
1814
+			}
1815
+			if ($this->debugLevel>3)
1816
+			{
1817
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1818
+			}
1484 1819
 			$messagelist[$vars['uid']] = $mess;
1485 1820
 			unset($mess);
1486 1821
 		}
@@ -1505,9 +1840,18 @@  discard block
 block discarded – undo
1505 1840
 	static function doFlagsMod($headerFlags)
1506 1841
 	{
1507 1842
 		$flags = 'nnn';
1508
-		if ($headerFlags['flagged']) $flags[0] = 'f';
1509
-		if ($headerFlags['answered']) $flags[1] = 'a';
1510
-		if ($headerFlags['forwarded']) $flags[2] = 'f';
1843
+		if ($headerFlags['flagged'])
1844
+		{
1845
+			$flags[0] = 'f';
1846
+		}
1847
+		if ($headerFlags['answered'])
1848
+		{
1849
+			$flags[1] = 'a';
1850
+		}
1851
+		if ($headerFlags['forwarded'])
1852
+		{
1853
+			$flags[2] = 'f';
1854
+		}
1511 1855
 		//ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags));
1512 1856
 		return $flags;
1513 1857
 	}
@@ -1539,31 +1883,55 @@  discard block
 block discarded – undo
1539 1883
 	{
1540 1884
 		//$this->debugLevel=1;
1541 1885
 		$searchquery=$_searchquery->GetDataArray();
1542
-		if (!is_array($searchquery)) return array();
1543
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1886
+		if (!is_array($searchquery))
1887
+		{
1888
+			return array();
1889
+		}
1890
+		if ($this->debugLevel>0)
1891
+		{
1892
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1893
+		}
1544 1894
 
1545
-		if (isset($searchquery['searchrebuildresults'])) {
1895
+		if (isset($searchquery['searchrebuildresults']))
1896
+		{
1546 1897
 			$rebuildresults = $searchquery['searchrebuildresults'];
1547
-		} else {
1898
+		}
1899
+		else
1900
+		{
1548 1901
 			$rebuildresults = false;
1549 1902
 		}
1550
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1903
+		if ($this->debugLevel>0)
1904
+		{
1905
+			ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1906
+		}
1551 1907
 
1552
-		if (isset($searchquery['deeptraversal'])) {
1908
+		if (isset($searchquery['deeptraversal']))
1909
+		{
1553 1910
 			$deeptraversal = $searchquery['deeptraversal'];
1554
-		} else {
1911
+		}
1912
+		else
1913
+		{
1555 1914
 			$deeptraversal = false;
1556 1915
 		}
1557
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1916
+		if ($this->debugLevel>0)
1917
+		{
1918
+			ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1919
+		}
1558 1920
 
1559
-		if (isset($searchquery['searchrange'])) {
1921
+		if (isset($searchquery['searchrange']))
1922
+		{
1560 1923
 			$range = explode("-",$_searchquery->GetSearchRange());
1561 1924
 			$start =$range[0] + 1;
1562 1925
 			$limit = $range[1] - $range[0] + 1;
1563
-		} else {
1926
+		}
1927
+		else
1928
+		{
1564 1929
 			$range = false;
1565 1930
 		}
1566
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1931
+		if ($this->debugLevel>0)
1932
+		{
1933
+			ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1934
+		}
1567 1935
 
1568 1936
 		//foreach($searchquery['query'] as $k => $value) {
1569 1937
 		//	$query = $value;
@@ -1615,7 +1983,10 @@  discard block
 block discarded – undo
1615 1983
 			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1616 1984
 		}
1617 1985
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1618
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1986
+		if ($this->debugLevel>1)
1987
+		{
1988
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1989
+		}
1619 1990
 		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1620 1991
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1621 1992
 		$list=array();
@@ -1647,17 +2018,26 @@  discard block
 block discarded – undo
1647 2018
 	private function getParentID($account,$folder)
1648 2019
 	{
1649 2020
 		$this->_connect($account);
1650
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2021
+		if (!isset($this->folders))
2022
+		{
2023
+			$this->folders = $this->mail->getFolderObjects(true,false);
2024
+		}
1651 2025
 
1652 2026
 		$mailFolder = $this->folders[$folder];
1653
-		if (!isset($mailFolder)) return false;
2027
+		if (!isset($mailFolder))
2028
+		{
2029
+			return false;
2030
+		}
1654 2031
 		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1655 2032
 		$parent = explode($delimiter,$folder);
1656 2033
 		array_pop($parent);
1657 2034
 		$parent = implode($delimiter,$parent);
1658 2035
 
1659 2036
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1660
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2037
+		if ($this->debugLevel>1)
2038
+		{
2039
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2040
+		}
1661 2041
 		return $id;
1662 2042
 	}
1663 2043
 
@@ -1671,7 +2051,10 @@  discard block
 block discarded – undo
1671 2051
 	{
1672 2052
 		static $last_id = null;
1673 2053
 		static $folderObj = null;
1674
-		if (isset($last_id) && $last_id === $id) return $folderObj;
2054
+		if (isset($last_id) && $last_id === $id)
2055
+		{
2056
+			return $folderObj;
2057
+		}
1675 2058
 
1676 2059
 		try {
1677 2060
 			$account = $folder = null;
@@ -1682,18 +2065,30 @@  discard block
 block discarded – undo
1682 2065
 			return $folderObj=false;
1683 2066
 		}
1684 2067
 		$this->_connect($account);
1685
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2068
+		if (!isset($this->folders))
2069
+		{
2070
+			$this->folders = $this->mail->getFolderObjects(true,false);
2071
+		}
1686 2072
 
1687 2073
 		$mailFolder = $this->folders[$folder];
1688
-		if (!isset($mailFolder)) return $folderObj=false;
2074
+		if (!isset($mailFolder))
2075
+		{
2076
+			return $folderObj=false;
2077
+		}
1689 2078
 
1690 2079
 		$folderObj = new SyncFolder();
1691 2080
 		$folderObj->serverid = $id;
1692 2081
 		$folderObj->parentid = $this->getParentID($account,$folder);
1693 2082
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1694
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2083
+		if ($this->debugLevel>1)
2084
+		{
2085
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2086
+		}
1695 2087
 		// get folder-type
1696
-		foreach($this->folders as $inbox => $mailFolder) break;
2088
+		foreach($this->folders as $inbox => $mailFolder)
2089
+		{
2090
+			break;
2091
+		}
1697 2092
 		if ($folder == $inbox)
1698 2093
 		{
1699 2094
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
@@ -1730,7 +2125,10 @@  discard block
 block discarded – undo
1730 2125
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1731 2126
 		}
1732 2127
 
1733
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2128
+		if ($this->debugLevel>1)
2129
+		{
2130
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2131
+		}
1734 2132
 		return $folderObj;
1735 2133
 	}
1736 2134
 
@@ -1774,11 +2172,20 @@  discard block
 block discarded – undo
1774 2172
 	{
1775 2173
 		$account = $folder = null;
1776 2174
 		$this->splitID($folderid, $account, $folder);
1777
-		if (is_numeric($account)) $type = 'mail';
2175
+		if (is_numeric($account))
2176
+		{
2177
+			$type = 'mail';
2178
+		}
1778 2179
 
1779
-		if ($type != 'mail') return false;
2180
+		if ($type != 'mail')
2181
+		{
2182
+			return false;
2183
+		}
1780 2184
 
1781
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2185
+		if (!isset($this->mail))
2186
+		{
2187
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2188
+		}
1782 2189
 
1783 2190
         $this->mail->reopen($folder);
1784 2191
 
@@ -1823,7 +2230,7 @@  discard block
 block discarded – undo
1823 2230
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1824 2231
      */
1825 2232
     public function DeleteMessage($folderid, $id, $contentParameters)
1826
-	{
2233
+    {
1827 2234
 		unset($contentParameters);	// not used, but required by function signature
1828 2235
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1829 2236
 		/*
@@ -1849,7 +2256,10 @@  discard block
 block discarded – undo
1849 2256
 			$error = $e->getMessage();
1850 2257
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1851 2258
 			// if the server thinks the message does not exist report deletion as success
1852
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
2259
+			if (stripos($error,'[NONEXISTENT]')!==false)
2260
+			{
2261
+				return true;
2262
+			}
1853 2263
 			return false;
1854 2264
 		}
1855 2265
 
@@ -1882,7 +2292,7 @@  discard block
 block discarded – undo
1882 2292
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1883 2293
      */
1884 2294
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1885
-	{
2295
+    {
1886 2296
 		unset($contentParameters);	// not used, but required by function signature
1887 2297
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1888 2298
 		$account = $folder = null;
@@ -1966,10 +2376,16 @@  discard block
 block discarded – undo
1966 2376
 		$account = $parent_id = $app = null;
1967 2377
 		$this->splitID($id, $account, $folder, $app);
1968 2378
 		$old_hash = $this->folder2hash($account, $folder);
1969
-		if ($parentid) $this->splitID($parentid, $account, $parentfolder, $app);
2379
+		if ($parentid)
2380
+		{
2381
+			$this->splitID($parentid, $account, $parentfolder, $app);
2382
+		}
1970 2383
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."( '$id (-> $folder)','$parentid ".($parentid?'(->'.$parentfolder.')':'')."') called!");
1971 2384
 		$ret = $this->mail->deleteFolder($folder);
1972
-		if ($ret) $newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##");
2385
+		if ($ret)
2386
+		{
2387
+			$newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##");
2388
+		}
1973 2389
 		return $ret;
1974 2390
 	}
1975 2391
 
@@ -2014,7 +2430,10 @@  discard block
 block discarded – undo
2014 2430
 
2015 2431
 		$str = $this->backend->createID($account, $folder, $id);
2016 2432
 
2017
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2433
+		if ($this->debugLevel>1)
2434
+		{
2435
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2436
+		}
2018 2437
 
2019 2438
 		return $str;
2020 2439
 	}
@@ -2035,7 +2454,10 @@  discard block
 block discarded – undo
2035 2454
 		// convert numeric folder-id back to folder name
2036 2455
 		$folder = $this->hash2folder($account,$f=$folder);
2037 2456
 
2038
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)");
2457
+		if ($this->debugLevel>1)
2458
+		{
2459
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)");
2460
+		}
2039 2461
 	}
2040 2462
 
2041 2463
 	/**
@@ -2054,7 +2476,10 @@  discard block
 block discarded – undo
2054 2476
 	 */
2055 2477
 	private function folder2hash($account,$folder)
2056 2478
 	{
2057
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2479
+		if(!isset($this->folderHashes))
2480
+		{
2481
+			$this->readFolderHashes();
2482
+		}
2058 2483
 
2059 2484
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2060 2485
 		{
@@ -2077,7 +2502,10 @@  discard block
 block discarded – undo
2077 2502
 	 */
2078 2503
 	private function hash2folder($account,$index)
2079 2504
 	{
2080
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2505
+		if(!isset($this->folderHashes))
2506
+		{
2507
+			$this->readFolderHashes();
2508
+		}
2081 2509
 
2082 2510
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2083 2511
 	}
Please login to merge, or discard this patch.