Completed
Push — 16.1 ( da3266...d5e8cd )
by Klaus
19:17
created
mail/inc/class.mail_zpush.inc.php 1 patch
Braces   +593 added lines, -174 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
 
@@ -229,8 +253,14 @@  discard block
 block discarded – undo
229 253
 				$this->_connect(0,true);
230 254
 				$this->_disconnect();
231 255
 
232
-				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
233
-				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
256
+				if (!$this->_wasteID)
257
+				{
258
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
259
+				}
260
+				if (!$this->_sentID)
261
+				{
262
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
263
+				}
234 264
 			}
235 265
 			catch(Exception $e) {
236 266
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
@@ -252,8 +282,14 @@  discard block
 block discarded – undo
252 282
 	 */
253 283
 	private function _connect($account=0)
254 284
 	{
255
-		if (!$account) $account = self::$profileID ? self::$profileID : 0;
256
-		if ($this->mail && $this->account != $account) $this->_disconnect();
285
+		if (!$account)
286
+		{
287
+			$account = self::$profileID ? self::$profileID : 0;
288
+		}
289
+		if ($this->mail && $this->account != $account)
290
+		{
291
+			$this->_disconnect();
292
+		}
257 293
 
258 294
 		$this->_wasteID = false;
259 295
 		$this->_sentID = false;
@@ -264,12 +300,18 @@  discard block
 block discarded – undo
264 300
 			// todo: tell mail which account to use
265 301
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
266 302
 			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
267
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
303
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
304
+			{
305
+				self::$profileID = $this->mail->icServer->ImapServerId;
306
+			}
268 307
 		}
269 308
 		else
270 309
 		{
271 310
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
272
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
311
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
312
+			{
313
+				self::$profileID = $this->mail->icServer->ImapServerId;
314
+			}
273 315
 		}
274 316
 		$this->mail->openConnection(self::$profileID,false);
275 317
 
@@ -286,8 +328,14 @@  discard block
 block discarded – undo
286 328
 	 */
287 329
 	private function _disconnect()
288 330
 	{
289
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
290
-		if ($this->mail) $this->mail->closeConnection();
331
+		if ($this->debugLevel>0)
332
+		{
333
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
334
+		}
335
+		if ($this->mail)
336
+		{
337
+			$this->mail->closeConnection();
338
+		}
291 339
 
292 340
 		unset($this->mail);
293 341
 		unset($this->account);
@@ -302,24 +350,43 @@  discard block
 block discarded – undo
302 350
 	public function GetFolderList()
303 351
 	{
304 352
 		$folderlist = array();
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
353
+		if ($this->debugLevel>0)
354
+		{
355
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
356
+		}
306 357
 		/*foreach($available_accounts as $account)*/ $account = 0;
307 358
 		{
308 359
 			$this->_connect($account);
309
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
310
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
360
+			if (!isset($this->folders))
361
+			{
362
+				$this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
363
+			}
364
+			if ($this->debugLevel>1)
365
+			{
366
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
367
+			}
311 368
 
312
-			foreach ($this->folders as $folder => $folderObj) {
313
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
369
+			foreach ($this->folders as $folder => $folderObj)
370
+			{
371
+				if ($this->debugLevel>1)
372
+				{
373
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
374
+				}
314 375
 				$folderlist[] = $f = array(
315 376
 					'id'     => $this->createID($account,$folder),
316 377
 					'mod'    => $folderObj->shortDisplayName,
317 378
 					'parent' => $this->getParentID($account,$folder),
318 379
 				);
319
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
380
+				if ($this->debugLevel>1)
381
+				{
382
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
383
+				}
320 384
 			}
321 385
 		}
322
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
386
+		if ($this->debugLevel>0)
387
+		{
388
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
389
+		}
323 390
 
324 391
 		return $folderlist;
325 392
 	}
@@ -380,11 +447,17 @@  discard block
 block discarded – undo
380 447
 		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
381 448
 
382 449
    		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 : ""));
383
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
450
+		if ($this->debugLevel>0)
451
+		{
452
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
453
+		}
384 454
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
385 455
 
386 456
 		// initialize our Mail
387
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
457
+		if (!isset($this->mail))
458
+		{
459
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
460
+		}
388 461
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
389 462
 		// use the standardIdentity
390 463
 		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
@@ -412,12 +485,18 @@  discard block
 block discarded – undo
412 485
 		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
413 486
 		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
414 487
 		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
415
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
488
+		if ($this->debugLevel>0)
489
+		{
490
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
491
+		}
416 492
 		$sigTextHtml = $beforeHtml.$sigText;
417 493
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
418 494
 
419 495
 		$force8bit=false;
420
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
496
+		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii')
497
+		{
498
+			$force8bit=true;
499
+		}
421 500
 		// initialize the new Api\Mailer object for sending
422 501
 		$mailObject = new Api\Mailer(self::$profileID);
423 502
 		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
@@ -428,22 +507,34 @@  discard block
 block discarded – undo
428 507
 
429 508
 		// prepare addressee list; moved the adding of addresses to the mailobject down
430 509
 		// to
431
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
432
-			if (!$addressObject->valid) continue;
510
+		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject)
511
+		{
512
+			if (!$addressObject->valid)
513
+			{
514
+				continue;
515
+			}
433 516
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
434 517
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
435 518
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
436 519
 		}
437 520
 		// CC
438
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
439
-			if (!$addressObject->valid) continue;
521
+		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject)
522
+		{
523
+			if (!$addressObject->valid)
524
+			{
525
+				continue;
526
+			}
440 527
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
441 528
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
442 529
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
443 530
 		}
444 531
 		// BCC
445
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
446
-			if (!$addressObject->valid) continue;
532
+		foreach($mailObject->getAddresses('bcc') as $addressObject)
533
+		{
534
+			if (!$addressObject->valid)
535
+			{
536
+				continue;
537
+			}
447 538
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
448 539
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
449 540
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
@@ -456,12 +547,14 @@  discard block
 block discarded – undo
456 547
 		$ContentType =$mailObject->getHeader('Content-Type');
457 548
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
458 549
 		// if the message is a multipart message, then we should use the sent body
459
-		if (preg_match("/multipart/i", $ContentType)) {
550
+		if (preg_match("/multipart/i", $ContentType))
551
+		{
460 552
 			$use_orgbody = true;
461 553
 		}
462 554
 
463 555
 		// save the original content-type header for the body part when forwarding
464
-		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
556
+		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody)
557
+		{
465 558
 			//continue; // ignore
466 559
 		}
467 560
 		// horde/egw_ mailer does everything as utf-8, the following should not be needed
@@ -470,7 +563,8 @@  discard block
 block discarded – undo
470 563
 		// if the message is a multipart message, then we should use the sent body
471 564
 		if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
472 565
 			((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
473
-			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
566
+			$k == "Content-Type" && preg_match("/multipart/i", $ContentType)))
567
+		{
474 568
 			$use_orgbody = true;
475 569
 		}
476 570
 		$Body =  $AltBody = "";
@@ -503,12 +597,19 @@  discard block
 block discarded – undo
503 597
 			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
504 598
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
505 599
 		}
506
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
507
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
600
+		if ($this->debugLevel>1 && $Body)
601
+		{
602
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
603
+		}
604
+		if ($this->debugLevel>1 && $AltBody)
605
+		{
606
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
607
+		}
508 608
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
509 609
 		// if this is a multipart message with a boundary, we must use the original body
510 610
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
511
-        if ($use_orgbody) {
611
+        if ($use_orgbody)
612
+        {
512 613
     	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
513 614
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
514 615
 			if (($cal_body = $mailObject->findBody('calendar')) &&
@@ -518,15 +619,20 @@  discard block
 block discarded – undo
518 619
 				{
519 620
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
520 621
 				}
521
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
622
+				if ($this->debugLevel)
623
+				{
624
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
625
+				}
522 626
 				$ClientSideMeetingRequest = true;
523 627
 			}
524 628
         }
525 629
 		// now handle the addressee list
526 630
 		$toCount = 0;
527 631
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
528
-		foreach((array)$toMailAddr as $address) {
529
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
632
+		foreach((array)$toMailAddr as $address)
633
+		{
634
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
635
+			{
530 636
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
531 637
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
532 638
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
@@ -540,19 +646,29 @@  discard block
 block discarded – undo
540 646
 			}
541 647
 		}
542 648
 		$ccCount = 0;
543
-		foreach((array)$ccMailAddr as $address) {
544
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
649
+		foreach((array)$ccMailAddr as $address)
650
+		{
651
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
652
+			{
545 653
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
546
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
654
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
655
+				{
656
+					continue;
657
+				}
547 658
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
548 659
 				$ccCount++;
549 660
 			}
550 661
 		}
551 662
 		$bccCount = 0;
552
-		foreach((array)$bccMailAddr as $address) {
553
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
663
+		foreach((array)$bccMailAddr as $address)
664
+		{
665
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
666
+			{
554 667
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
555
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
668
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
669
+				{
670
+					continue;
671
+				}
556 672
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
557 673
 				$bccCount++;
558 674
 			}
@@ -562,7 +678,10 @@  discard block
 block discarded – undo
562 678
 		{
563 679
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
564 680
 		}
565
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
681
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false)
682
+		{
683
+			return true;
684
+		}
566 685
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
567 686
 /*
568 687
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -585,10 +704,17 @@  discard block
 block discarded – undo
585 704
 			$this->mail->reopen($folder);
586 705
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
587 706
 			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
588
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
589
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
707
+			if ($this->debugLevel>3)
708
+			{
709
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
710
+			}
711
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
712
+		    {
590 713
 				// may be html
591
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
714
+				if ($this->debugLevel>0)
715
+				{
716
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
717
+				}
592 718
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
593 719
 				$isreply = true;
594 720
 			}
@@ -597,8 +723,12 @@  discard block
 block discarded – undo
597 723
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
598 724
 			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
599 725
 			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
600
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
601
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
726
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
727
+			{
728
+				if ($this->debugLevel>0)
729
+				{
730
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
731
+				}
602 732
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
603 733
 				$isreply = true;
604 734
 			}
@@ -606,7 +736,10 @@  discard block
 block discarded – undo
606 736
 			{
607 737
 				$isreply = true;
608 738
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
609
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
739
+				if ($this->debugLevel>0)
740
+				{
741
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
742
+				}
610 743
 			}
611 744
 		}
612 745
 
@@ -620,11 +753,17 @@  discard block
 block discarded – undo
620 753
 			(isset($smartdata->replacemime) && $smartdata->replacemime == false)))
621 754
 		{
622 755
 			//force the default for the forwarding -> asmail
623
-			if (is_array($preferencesArray)) {
756
+			if (is_array($preferencesArray))
757
+			{
624 758
 				if (!array_key_exists('message_forwarding',$preferencesArray)
625 759
 					|| !isset($preferencesArray['message_forwarding'])
626
-					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
627
-			} else {
760
+					|| empty($preferencesArray['message_forwarding']))
761
+				{
762
+					$preferencesArray['message_forwarding'] = 'asmail';
763
+				}
764
+			}
765
+			else
766
+			{
628 767
 				$preferencesArray['message_forwarding'] = 'asmail';
629 768
 			}
630 769
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
@@ -656,27 +795,44 @@  discard block
 block discarded – undo
656 795
 				$this->mail->reopen($folder);
657 796
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
658 797
 				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
659
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
660
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
798
+				if ($this->debugLevel>0)
799
+				{
800
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
801
+				}
802
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
803
+				{
661 804
 					// may be html
662
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
805
+					if ($this->debugLevel>0)
806
+					{
807
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
808
+					}
663 809
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
664 810
 					$isforward = true;
665 811
 				}
666 812
 				// plain text Message part
667
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
813
+				if ($this->debugLevel>0)
814
+				{
815
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
816
+				}
668 817
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
669 818
 				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
670 819
 				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
671
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
672
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
820
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
821
+				{
822
+					if ($this->debugLevel>0)
823
+					{
824
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
825
+					}
673 826
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
674 827
 					$isforward = true;
675 828
 				}
676 829
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
677 830
 				{
678 831
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
679
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
832
+					if ($this->debugLevel>0)
833
+					{
834
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
835
+					}
680 836
 					$isforward = true;
681 837
 				}
682 838
 				// get all the attachments and add them too.
@@ -689,7 +845,10 @@  discard block
 block discarded – undo
689 845
 					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
690 846
 					foreach((array)$attachments as $key => $attachment)
691 847
 					{
692
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
848
+						if ($this->debugLevel>0)
849
+						{
850
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
851
+						}
693 852
 						$attachmentNames .= $attachment['name']."\n";
694 853
 						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
695 854
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
@@ -708,20 +867,29 @@  discard block
 block discarded – undo
708 867
 		// now set the body
709 868
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
710 869
 		{
711
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
870
+			if ($this->debugLevel>1)
871
+			{
872
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
873
+			}
712 874
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
713 875
 			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
714 876
 		}
715 877
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
716 878
 		{
717
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
879
+			if ($this->debugLevel>1)
880
+			{
881
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
882
+			}
718 883
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
719 884
 			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
720 885
 		}
721 886
 		//advanced debugging
722 887
 		// Horde SMTP Class uses utf-8 by default.
723 888
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
724
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
889
+		if ($this->debugLevel>2)
890
+		{
891
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
892
+		}
725 893
 
726 894
 		// set a higher timeout for big messages
727 895
 		@set_time_limit(120);
@@ -748,7 +916,9 @@  discard block
 block discarded – undo
748 916
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
749 917
 			{
750 918
 				$this->mail->deleteMessages(array($uid),$folder);
751
-			} else {
919
+			}
920
+			else
921
+			{
752 922
 				$this->mail->flagMessages("answered", array($uid),$folder);
753 923
 				if ($smartdata_task== "forward")
754 924
 				{
@@ -762,7 +932,8 @@  discard block
 block discarded – undo
762 932
 		{
763 933
 			$asf = false;
764 934
 			$sentFolder = $this->mail->getSentFolder();
765
-			if ($this->_sentID) {
935
+			if ($this->_sentID)
936
+			{
766 937
 				$folderArray[] = $this->_sentID;
767 938
 			}
768 939
 			else if(isset($sentFolder) && $sentFolder != 'none')
@@ -776,28 +947,41 @@  discard block
 block discarded – undo
776 947
 				// we dont try guessing
777 948
 				$asf = true;
778 949
 			}
779
-			if (count($folderArray) > 0) {
780
-				foreach((array)$bccMailAddr as $address) {
781
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
950
+			if (count($folderArray) > 0)
951
+			{
952
+				foreach((array)$bccMailAddr as $address)
953
+				{
954
+					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
955
+					{
782 956
 						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
783 957
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
784 958
 					}
785 959
 				}
786 960
 				//$BCCmail='';
787
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
961
+				if (count($mailAddr)>0)
962
+				{
963
+					$mailObject->forceBccHeader();
964
+				}
788 965
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
789
-				foreach($folderArray as $folderName) {
790
-					if($this->mail->isSentFolder($folderName)) {
966
+				foreach($folderArray as $folderName)
967
+				{
968
+					if($this->mail->isSentFolder($folderName))
969
+					{
791 970
 						$flags = '\\Seen';
792
-					} elseif($this->mail->isDraftFolder($folderName)) {
971
+					}
972
+					elseif($this->mail->isDraftFolder($folderName))
973
+					{
793 974
 						$flags = '\\Draft';
794
-					} else {
975
+					}
976
+					else
977
+					{
795 978
 						$flags = '';
796 979
 					}
797 980
 					$asf = true;
798 981
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
799 982
 					$this->mail->openConnection(self::$profileID,false);
800
-					if ($this->mail->folderExists($folderName)) {
983
+					if ($this->mail->folderExists($folderName))
984
+					{
801 985
 						try
802 986
 						{
803 987
 							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
@@ -855,17 +1039,26 @@  discard block
 block discarded – undo
855 1039
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
856 1040
 
857 1041
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
858
-		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
1042
+		if (!$mimesupport && ($key = array_search('4', $bodypreference)))
1043
+		{
1044
+			unset($bodypreference[$key]);
1045
+		}
859 1046
 
860 1047
 		//$this->debugLevel=4;
861
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1048
+		if (!isset($this->mail))
1049
+		{
1050
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1051
+		}
862 1052
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
863 1053
 		$account = $_folderName = $xid = null;
864 1054
 		$this->splitID($folderid,$account,$_folderName,$xid);
865 1055
 		$this->mail->reopen($_folderName);
866 1056
 		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
867 1057
 		$headers = $messages[$id];
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1058
+		if ($this->debugLevel>3)
1059
+		{
1060
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1061
+		}
869 1062
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 1063
 		if ($headers)
871 1064
 		{
@@ -875,16 +1068,25 @@  discard block
 block discarded – undo
875 1068
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
876 1069
 			// simple style
877 1070
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
878
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1071
+			if ($this->debugLevel>0)
1072
+			{
1073
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1074
+			}
879 1075
 
880
-			if ($bodypreference === false) {
1076
+			if ($bodypreference === false)
1077
+			{
881 1078
 				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
882 1079
 				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
883 1080
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
884
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
1081
+				if (stripos($raw_body,'<style')!==false)
1082
+				{
1083
+					$body = preg_replace("/<style.*?<\/style>/is", "", $raw_body);
1084
+				}
1085
+				// in case there is only a html part
885 1086
 				// remove all other html
886 1087
 				$body = strip_tags($raw_body);
887
-				if(strlen($body) > $truncsize) {
1088
+				if(strlen($body) > $truncsize)
1089
+				{
888 1090
 					$body = Utils::Utf8_truncate($body, $truncsize);
889 1091
 					$output->bodytruncated = 1;
890 1092
 				}
@@ -899,7 +1101,8 @@  discard block
 block discarded – undo
899 1101
 			{
900 1102
 				//Select body type preference
901 1103
 				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
902
-				if ($bodypreference !== false) {
1104
+				if ($bodypreference !== false)
1105
+				{
903 1106
 					// bodypreference can occur multiple times
904 1107
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
905 1108
 					$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -933,25 +1136,49 @@  discard block
 block discarded – undo
933 1136
 					// fetch the body (try to gather data only once)
934 1137
 					$css ='';
935 1138
 					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
936
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1139
+					if ($this->debugLevel>2)
1140
+					{
1141
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1142
+					}
937 1143
 					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
938
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
939
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
1144
+					if ($this->debugLevel>3)
1145
+					{
1146
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
1147
+					}
1148
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
1149
+					{
940 1150
 						// may be html
941
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1151
+						if ($this->debugLevel>0)
1152
+						{
1153
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1154
+						}
942 1155
 						$css = $this->mail->getStyles($bodyStruct);
943 1156
 						$output->nativebodytype=2;
944
-					} else {
1157
+					}
1158
+					else
1159
+					{
945 1160
 						// plain text Message
946
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1161
+						if ($this->debugLevel>0)
1162
+						{
1163
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1164
+						}
947 1165
 						$output->nativebodytype=1;
948 1166
 						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
949
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1167
+						if ($this->debugLevel>3)
1168
+						{
1169
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1170
+						}
950 1171
 						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
951
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1172
+						if ($this->debugLevel>3)
1173
+						{
1174
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1175
+						}
952 1176
 					}
953 1177
 					// whatever format decode (using the correct encoding)
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1178
+					if ($this->debugLevel>3)
1179
+					{
1180
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1181
+					}
955 1182
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
956 1183
 					// prepare plaintextbody
957 1184
 					$plainBody='';
@@ -972,12 +1199,18 @@  discard block
 block discarded – undo
972 1199
 					// remove all other html
973 1200
 					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
974 1201
 					$plainBody = strip_tags($plainBody);
975
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1202
+					if ($this->debugLevel>3 && $output->nativebodytype==1)
1203
+					{
1204
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1205
+					}
976 1206
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
977 1207
 
978
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
1208
+					if ($bpReturnType==2)
1209
+					{
1210
+						//SYNC_BODYPREFERENCE_HTML
979 1211
 					{
980 1212
 						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
1213
+					}
981 1214
 						// Send HTML if requested and native type was html
982 1215
 						$output->asbody->type = 2;
983 1216
 						$htmlbody = '<html>'.
@@ -1013,7 +1246,10 @@  discard block
 block discarded – undo
1013 1246
 					else
1014 1247
 					{
1015 1248
 						// Send Plaintext as Fallback or if original body is plainttext
1016
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1249
+						if ($this->debugLevel>0)
1250
+						{
1251
+							ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1252
+						}
1017 1253
 						/* we use plainBody (set above) instead
1018 1254
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1019 1255
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1050,7 +1286,9 @@  discard block
 block discarded – undo
1050 1286
 			{
1051 1287
 				$output->flag->flagstatus = 2;
1052 1288
 				//$output->flag->flagtype = "Flag for Follow up";
1053
-			} else {
1289
+			}
1290
+			else
1291
+			{
1054 1292
 				$output->flag->flagstatus = 0;
1055 1293
 			}
1056 1294
 			if ($headers['answered'])
@@ -1066,10 +1304,20 @@  discard block
 block discarded – undo
1066 1304
 				($headers['priority'] < 3 ? 2 : 1) ;
1067 1305
 			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1068 1306
 			$output->to = $headers['to_address'];
1069
-			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1307
+			if ($headers['to'])
1308
+			{
1309
+				$output->displayto = $headers['to_address'];
1310
+			}
1311
+			//$headers['FETCHED_HEADER']['to_name']
1070 1312
 			$output->from = $headers['sender_address'];
1071
-			if (isset($headers['cc_addresses']) && $headers['cc_addresses']) $output->cc = $headers['cc_addresses'];
1072
-			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1313
+			if (isset($headers['cc_addresses']) && $headers['cc_addresses'])
1314
+			{
1315
+				$output->cc = $headers['cc_addresses'];
1316
+			}
1317
+			if (isset($headers['reply_to_address']) && $headers['reply_to_address'])
1318
+			{
1319
+				$output->reply_to = $headers['reply_to_address'];
1320
+			}
1073 1321
 
1074 1322
 			$output->messageclass = "IPM.Note";
1075 1323
 			if (stripos($headers['mimetype'],'multipart')!== false &&
@@ -1077,7 +1325,8 @@  discard block
 block discarded – undo
1077 1325
 			{
1078 1326
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1079 1327
 			}
1080
-			if (Request::GetProtocolVersion() >= 12.0) {
1328
+			if (Request::GetProtocolVersion() >= 12.0)
1329
+			{
1081 1330
 				$output->contentclass = "urn:content-classes:message";
1082 1331
 			}
1083 1332
 
@@ -1090,7 +1339,10 @@  discard block
 block discarded – undo
1090 1339
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1091 1340
 				foreach ($attachments as $key => $attach)
1092 1341
 				{
1093
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1342
+					if ($this->debugLevel>0)
1343
+					{
1344
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1345
+					}
1094 1346
 
1095 1347
 					// pass meeting requests to calendar plugin
1096 1348
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
@@ -1107,17 +1359,24 @@  discard block
 block discarded – undo
1107 1359
 						unset($attachment);
1108 1360
 						continue;	// do NOT add attachment as attachment
1109 1361
 					}
1110
-					if (Request::GetProtocolVersion() >= 12.0) {
1362
+					if (Request::GetProtocolVersion() >= 12.0)
1363
+					{
1111 1364
 						$attachment = new SyncBaseAttachment();
1112 1365
 						if (!isset($output->asattachments) || !is_array($output->asattachments))
1113
-							$output->asattachments = array();
1366
+						{
1367
+													$output->asattachments = array();
1368
+						}
1114 1369
 						$attachment->estimatedDataSize = $attach['size'];
1115 1370
 						$attachment->method = 1;
1116 1371
 						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1117
-					} else {
1372
+					}
1373
+					else
1374
+					{
1118 1375
 						$attachment = new SyncAttachment();
1119 1376
 						if (!isset($output->attachments) || !is_array($output->attachments))
1120
-							$output->attachments = array();
1377
+						{
1378
+													$output->attachments = array();
1379
+						}
1121 1380
 						$attachment->attsize = $attach['size'];
1122 1381
 						$attachment->attmethod = 1;
1123 1382
 						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
@@ -1134,10 +1393,13 @@  discard block
 block discarded – undo
1134 1393
 						{
1135 1394
 							$attachment->isinline = true;
1136 1395
 						}
1137
-						if (Request::GetProtocolVersion() >= 12.0) {
1396
+						if (Request::GetProtocolVersion() >= 12.0)
1397
+						{
1138 1398
 							$attachment->method=1;
1139 1399
 							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1140
-						} else {
1400
+						}
1401
+						else
1402
+						{
1141 1403
 							$attachment->attmethod=6;
1142 1404
 							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1143 1405
 						}
@@ -1145,9 +1407,12 @@  discard block
 block discarded – undo
1145 1407
 						$attachment->contenttype = trim($attach['mimeType']);
1146 1408
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."'  ".$attachment->contentid);
1147 1409
 					}
1148
-					if (Request::GetProtocolVersion() >= 12.0) {
1410
+					if (Request::GetProtocolVersion() >= 12.0)
1411
+					{
1149 1412
 						array_push($output->asattachments, $attachment);
1150
-					} else {
1413
+					}
1414
+					else
1415
+					{
1151 1416
 						array_push($output->attachments, $attachment);
1152 1417
 					}
1153 1418
 					unset($attachment);
@@ -1160,8 +1425,11 @@  discard block
 block discarded – undo
1160 1425
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1161 1426
             $output->internetcpid = INTERNET_CPID_UTF8;
1162 1427
 
1163
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1164
-//$this->debugLevel=0;
1428
+			if ($this->debugLevel>3)
1429
+			{
1430
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1431
+			}
1432
+			//$this->debugLevel=0;
1165 1433
 			return $output;
1166 1434
 		}
1167 1435
 //$this->debugLevel=0;
@@ -1220,7 +1488,8 @@  discard block
 block discarded – undo
1220 1488
      * @param string $attname - should contain (folder)id
1221 1489
 	 * @return SyncItemOperationsAttachment-object
1222 1490
 	 */
1223
-	function GetAttachmentData($fid,$attname) {
1491
+	function GetAttachmentData($fid,$attname)
1492
+	{
1224 1493
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1225 1494
 		return $this->_GetAttachmentData($fid,$attname);
1226 1495
 	}
@@ -1235,7 +1504,8 @@  discard block
 block discarded – undo
1235 1504
      * @param string $attname - should contain (folder)id
1236 1505
 	 * @return SyncItemOperationsAttachment-object
1237 1506
 	 */
1238
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1507
+	function ItemOperationsGetAttachmentData($fid,$attname)
1508
+	{
1239 1509
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1240 1510
 		return $this->_GetAttachmentData($fid,$attname);
1241 1511
 	}
@@ -1257,7 +1527,10 @@  discard block
 block discarded – undo
1257 1527
 
1258 1528
 		$this->splitID($folderid, $account, $folder);
1259 1529
 
1260
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1530
+		if (!isset($this->mail))
1531
+		{
1532
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1533
+		}
1261 1534
 
1262 1535
 		$this->mail->reopen($folder);
1263 1536
 		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
@@ -1266,7 +1539,9 @@  discard block
 block discarded – undo
1266 1539
 		$SIOattachment->data = $attachment['attachment'];
1267 1540
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1268 1541
 		if (isset($attachment['type']) )
1269
-			$SIOattachment->contenttype = $attachment['type'];
1542
+		{
1543
+					$SIOattachment->contenttype = $attachment['type'];
1544
+		}
1270 1545
 
1271 1546
 		unset($attachment);
1272 1547
 
@@ -1312,11 +1587,15 @@  discard block
 block discarded – undo
1312 1587
 		//unset($folderid, $id, $message, $contentParameters);
1313 1588
 		$account = $folder = null;
1314 1589
 		$this->splitID($folderid, $account, $folder);
1315
-		if (isset($message->flag)) {
1316
-			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1590
+		if (isset($message->flag))
1591
+		{
1592
+			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2)
1593
+			{
1317 1594
 				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1318 1595
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1319
-			} else {
1596
+			}
1597
+			else
1598
+			{
1320 1599
 				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1321 1600
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1322 1601
 			}
@@ -1346,7 +1625,10 @@  discard block
 block discarded – undo
1346 1625
 		$this->splitID($folderid, $account, $srcFolder);
1347 1626
 		$this->splitID($newfolderid, $account, $destFolder);
1348 1627
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1349
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1628
+		if (!isset($this->mail))
1629
+		{
1630
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1631
+		}
1350 1632
 		$this->mail->reopen($destFolder);
1351 1633
 		$status = $this->mail->getFolderStatus($destFolder);
1352 1634
 		$uidNext = $status['uidnext'];
@@ -1378,7 +1660,10 @@  discard block
 block discarded – undo
1378 1660
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1379 1661
 			}
1380 1662
 			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1381
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1663
+			if (is_numeric($maximumSyncRangeInDays))
1664
+			{
1665
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1666
+			}
1382 1667
 		}
1383 1668
 		return $this->fetchMessages($folderid, $cutoffdate);
1384 1669
 	}
@@ -1400,7 +1685,10 @@  discard block
 block discarded – undo
1400 1685
 	{
1401 1686
 		static $headers = array();
1402 1687
 
1403
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1688
+		if ($this->debugLevel>1)
1689
+		{
1690
+			$gstarttime = microtime (true);
1691
+		}
1404 1692
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1405 1693
 		$rv_messages = array();
1406 1694
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1413,7 +1701,10 @@  discard block
 block discarded – undo
1413 1701
 		{
1414 1702
 			$headers = array();	// clear cache to not use too much memory
1415 1703
 
1416
-			if ($this->debugLevel>1) $starttime = microtime (true);
1704
+			if ($this->debugLevel>1)
1705
+			{
1706
+				$starttime = microtime (true);
1707
+			}
1417 1708
 			$this->_connect($this->account);
1418 1709
 			if ($this->debugLevel>1)
1419 1710
 			{
@@ -1422,8 +1713,14 @@  discard block
 block discarded – undo
1422 1713
 			}
1423 1714
 			$messagelist = $_filter = array();
1424 1715
 			// if not connected, any further action must fail
1425
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1426
-			if ($this->debugLevel>1) $starttime = microtime (true);
1716
+			if (!empty($cutoffdate))
1717
+			{
1718
+				$_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1719
+			}
1720
+			if ($this->debugLevel>1)
1721
+			{
1722
+				$starttime = microtime (true);
1723
+			}
1427 1724
 			$account = $_folderName = $id = null;
1428 1725
 			$this->splitID($folderid,$account,$_folderName,$id);
1429 1726
 			if ($this->debugLevel>1)
@@ -1431,8 +1728,14 @@  discard block
 block discarded – undo
1431 1728
 				$endtime = microtime(true) - $starttime;
1432 1729
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1433 1730
 			}
1434
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1435
-			if ($this->debugLevel>1) $starttime = microtime (true);
1731
+			if ($this->debugLevel>1)
1732
+			{
1733
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1734
+			}
1735
+			if ($this->debugLevel>1)
1736
+			{
1737
+				$starttime = microtime (true);
1738
+			}
1436 1739
 			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1437 1740
 			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1438 1741
 			if ($this->debugLevel>1)
@@ -1441,27 +1744,56 @@  discard block
 block discarded – undo
1441 1744
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1442 1745
 			}
1443 1746
 		}
1444
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1747
+		if ($_id == NULL && $this->debugLevel>1)
1748
+		{
1749
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1750
+		}
1445 1751
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1446 1752
 		$messagelist = array();
1447
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1753
+		if (!isset($rv_messages['header'])||empty($rv_messages['header']))
1754
+		{
1755
+			return $messagelist;
1756
+		}
1448 1757
 		//if ($_returnModHash) $messageFolderHash = array();
1449 1758
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1450 1759
 		{
1451
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1760
+			if ($this->debugLevel>3)
1761
+			{
1762
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1763
+			}
1452 1764
 			$headers[$vars['uid']] = $vars;
1453
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1454
-			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1455
-			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1456
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1765
+			if ($this->debugLevel>3)
1766
+			{
1767
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1768
+			}
1769
+			if (!empty($vars['deleted']))
1770
+			{
1771
+				continue;
1772
+			}
1773
+			// cut of deleted messages
1774
+			if ($cutoffdate && $vars['date'] < $cutoffdate)
1775
+			{
1776
+				continue;
1777
+			}
1778
+			// message is out of range for cutoffdate, ignore it
1779
+			if ($this->debugLevel>0)
1780
+			{
1781
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1782
+			}
1457 1783
 			$mess = $return_all_headers ? $vars : array();
1458 1784
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1459 1785
 			$mess["id"] = $vars['uid'];
1460 1786
 			// 'seen' aka 'read' is the only flag we want to know about
1461 1787
 			$mess["flags"] = 0;
1462 1788
 			// outlook supports additional flags, set them to 0
1463
-			if($vars["seen"]) $mess["flags"] = 1;
1464
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1789
+			if($vars["seen"])
1790
+			{
1791
+				$mess["flags"] = 1;
1792
+			}
1793
+			if ($this->debugLevel>3)
1794
+			{
1795
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1796
+			}
1465 1797
 			$messagelist[$vars['uid']] = $mess;
1466 1798
 			unset($mess);
1467 1799
 		}
@@ -1486,9 +1818,18 @@  discard block
 block discarded – undo
1486 1818
 	static function doFlagsMod($headerFlags)
1487 1819
 	{
1488 1820
 		$flags = 'nnn';
1489
-		if ($headerFlags['flagged']) $flags[0] = 'f';
1490
-		if ($headerFlags['answered']) $flags[1] = 'a';
1491
-		if ($headerFlags['forwarded']) $flags[2] = 'f';
1821
+		if ($headerFlags['flagged'])
1822
+		{
1823
+			$flags[0] = 'f';
1824
+		}
1825
+		if ($headerFlags['answered'])
1826
+		{
1827
+			$flags[1] = 'a';
1828
+		}
1829
+		if ($headerFlags['forwarded'])
1830
+		{
1831
+			$flags[2] = 'f';
1832
+		}
1492 1833
 		//ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags));
1493 1834
 		return $flags;
1494 1835
 	}
@@ -1520,31 +1861,55 @@  discard block
 block discarded – undo
1520 1861
 	{
1521 1862
 		//$this->debugLevel=1;
1522 1863
 		$searchquery=$_searchquery->GetDataArray();
1523
-		if (!is_array($searchquery)) return array();
1524
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1864
+		if (!is_array($searchquery))
1865
+		{
1866
+			return array();
1867
+		}
1868
+		if ($this->debugLevel>0)
1869
+		{
1870
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1871
+		}
1525 1872
 
1526
-		if (isset($searchquery['searchrebuildresults'])) {
1873
+		if (isset($searchquery['searchrebuildresults']))
1874
+		{
1527 1875
 			$rebuildresults = $searchquery['searchrebuildresults'];
1528
-		} else {
1876
+		}
1877
+		else
1878
+		{
1529 1879
 			$rebuildresults = false;
1530 1880
 		}
1531
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1881
+		if ($this->debugLevel>0)
1882
+		{
1883
+			ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1884
+		}
1532 1885
 
1533
-		if (isset($searchquery['deeptraversal'])) {
1886
+		if (isset($searchquery['deeptraversal']))
1887
+		{
1534 1888
 			$deeptraversal = $searchquery['deeptraversal'];
1535
-		} else {
1889
+		}
1890
+		else
1891
+		{
1536 1892
 			$deeptraversal = false;
1537 1893
 		}
1538
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1894
+		if ($this->debugLevel>0)
1895
+		{
1896
+			ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1897
+		}
1539 1898
 
1540
-		if (isset($searchquery['searchrange'])) {
1899
+		if (isset($searchquery['searchrange']))
1900
+		{
1541 1901
 			$range = explode("-",$_searchquery->GetSearchRange());
1542 1902
 			$start =$range[0] + 1;
1543 1903
 			$limit = $range[1] - $range[0] + 1;
1544
-		} else {
1904
+		}
1905
+		else
1906
+		{
1545 1907
 			$range = false;
1546 1908
 		}
1547
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1909
+		if ($this->debugLevel>0)
1910
+		{
1911
+			ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1912
+		}
1548 1913
 
1549 1914
 		//foreach($searchquery['query'] as $k => $value) {
1550 1915
 		//	$query = $value;
@@ -1596,7 +1961,10 @@  discard block
 block discarded – undo
1596 1961
 			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1597 1962
 		}
1598 1963
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1599
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1964
+		if ($this->debugLevel>1)
1965
+		{
1966
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1967
+		}
1600 1968
 		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1601 1969
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1602 1970
 		$list=array();
@@ -1628,17 +1996,26 @@  discard block
 block discarded – undo
1628 1996
 	private function getParentID($account,$folder)
1629 1997
 	{
1630 1998
 		$this->_connect($account);
1631
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1999
+		if (!isset($this->folders))
2000
+		{
2001
+			$this->folders = $this->mail->getFolderObjects(true,false);
2002
+		}
1632 2003
 
1633 2004
 		$mailFolder = $this->folders[$folder];
1634
-		if (!isset($mailFolder)) return false;
2005
+		if (!isset($mailFolder))
2006
+		{
2007
+			return false;
2008
+		}
1635 2009
 		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1636 2010
 		$parent = explode($delimiter,$folder);
1637 2011
 		array_pop($parent);
1638 2012
 		$parent = implode($delimiter,$parent);
1639 2013
 
1640 2014
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1641
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2015
+		if ($this->debugLevel>1)
2016
+		{
2017
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2018
+		}
1642 2019
 		return $id;
1643 2020
 	}
1644 2021
 
@@ -1652,7 +2029,10 @@  discard block
 block discarded – undo
1652 2029
 	{
1653 2030
 		static $last_id = null;
1654 2031
 		static $folderObj = null;
1655
-		if (isset($last_id) && $last_id === $id) return $folderObj;
2032
+		if (isset($last_id) && $last_id === $id)
2033
+		{
2034
+			return $folderObj;
2035
+		}
1656 2036
 
1657 2037
 		try {
1658 2038
 			$account = $folder = null;
@@ -1663,18 +2043,30 @@  discard block
 block discarded – undo
1663 2043
 			return $folderObj=false;
1664 2044
 		}
1665 2045
 		$this->_connect($account);
1666
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2046
+		if (!isset($this->folders))
2047
+		{
2048
+			$this->folders = $this->mail->getFolderObjects(true,false);
2049
+		}
1667 2050
 
1668 2051
 		$mailFolder = $this->folders[$folder];
1669
-		if (!isset($mailFolder)) return $folderObj=false;
2052
+		if (!isset($mailFolder))
2053
+		{
2054
+			return $folderObj=false;
2055
+		}
1670 2056
 
1671 2057
 		$folderObj = new SyncFolder();
1672 2058
 		$folderObj->serverid = $id;
1673 2059
 		$folderObj->parentid = $this->getParentID($account,$folder);
1674 2060
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1675
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2061
+		if ($this->debugLevel>1)
2062
+		{
2063
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2064
+		}
1676 2065
 		// get folder-type
1677
-		foreach($this->folders as $inbox => $mailFolder) break;
2066
+		foreach($this->folders as $inbox => $mailFolder)
2067
+		{
2068
+			break;
2069
+		}
1678 2070
 		if ($folder == $inbox)
1679 2071
 		{
1680 2072
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
@@ -1711,7 +2103,10 @@  discard block
 block discarded – undo
1711 2103
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1712 2104
 		}
1713 2105
 
1714
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2106
+		if ($this->debugLevel>1)
2107
+		{
2108
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2109
+		}
1715 2110
 		return $folderObj;
1716 2111
 	}
1717 2112
 
@@ -1755,11 +2150,20 @@  discard block
 block discarded – undo
1755 2150
 	{
1756 2151
 		$account = $folder = null;
1757 2152
 		$this->splitID($folderid, $account, $folder);
1758
-		if (is_numeric($account)) $type = 'mail';
2153
+		if (is_numeric($account))
2154
+		{
2155
+			$type = 'mail';
2156
+		}
1759 2157
 
1760
-		if ($type != 'mail') return false;
2158
+		if ($type != 'mail')
2159
+		{
2160
+			return false;
2161
+		}
1761 2162
 
1762
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2163
+		if (!isset($this->mail))
2164
+		{
2165
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2166
+		}
1763 2167
 
1764 2168
         $this->mail->reopen($folder);
1765 2169
 
@@ -1804,7 +2208,7 @@  discard block
 block discarded – undo
1804 2208
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1805 2209
      */
1806 2210
     public function DeleteMessage($folderid, $id, $contentParameters)
1807
-	{
2211
+    {
1808 2212
 		unset($contentParameters);	// not used, but required by function signature
1809 2213
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1810 2214
 		/*
@@ -1830,7 +2234,10 @@  discard block
 block discarded – undo
1830 2234
 			$error = $e->getMessage();
1831 2235
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1832 2236
 			// if the server thinks the message does not exist report deletion as success
1833
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
2237
+			if (stripos($error,'[NONEXISTENT]')!==false)
2238
+			{
2239
+				return true;
2240
+			}
1834 2241
 			return false;
1835 2242
 		}
1836 2243
 
@@ -1863,7 +2270,7 @@  discard block
 block discarded – undo
1863 2270
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1864 2271
      */
1865 2272
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1866
-	{
2273
+    {
1867 2274
 		unset($contentParameters);	// not used, but required by function signature
1868 2275
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1869 2276
 		$account = $folder = null;
@@ -1949,7 +2356,10 @@  discard block
 block discarded – undo
1949 2356
 
1950 2357
 		$str = $this->backend->createID($account, $folder, $id);
1951 2358
 
1952
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2359
+		if ($this->debugLevel>1)
2360
+		{
2361
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2362
+		}
1953 2363
 
1954 2364
 		return $str;
1955 2365
 	}
@@ -1970,7 +2380,10 @@  discard block
 block discarded – undo
1970 2380
 		// convert numeric folder-id back to folder name
1971 2381
 		$folder = $this->hash2folder($account,$f=$folder);
1972 2382
 
1973
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2383
+		if ($this->debugLevel>1)
2384
+		{
2385
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2386
+		}
1974 2387
 	}
1975 2388
 
1976 2389
 	/**
@@ -1989,7 +2402,10 @@  discard block
 block discarded – undo
1989 2402
 	 */
1990 2403
 	private function folder2hash($account,$folder)
1991 2404
 	{
1992
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2405
+		if(!isset($this->folderHashes))
2406
+		{
2407
+			$this->readFolderHashes();
2408
+		}
1993 2409
 
1994 2410
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
1995 2411
 		{
@@ -2012,7 +2428,10 @@  discard block
 block discarded – undo
2012 2428
 	 */
2013 2429
 	private function hash2folder($account,$index)
2014 2430
 	{
2015
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2431
+		if(!isset($this->folderHashes))
2432
+		{
2433
+			$this->readFolderHashes();
2434
+		}
2016 2435
 
2017 2436
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2018 2437
 	}
Please login to merge, or discard this patch.