Completed
Push — master ( 36005d...5f7e13 )
by Klaus
19:11 queued 25s
created
mail/inc/class.mail_zpush.inc.php 2 patches
Spacing   +348 added lines, -349 removed lines patch added patch discarded remove patch
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 		$this->backend = $backend;
88 88
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
89 89
 		{
90
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
90
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
91 91
 			// globals preferences add appname varname value
92
-			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
92
+			$GLOBALS['egw']->preferences->add('activesync', 'mail-ActiveSyncProfileID', 0, 'user');
93 93
 			// save prefs
94 94
 			$GLOBALS['egw']->preferences->save_repository(true);
95 95
 		}
96
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
96
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
97 97
 
98 98
 		if (is_null(self::$profileID))
99 99
 		{
100
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
101
-			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
102
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
100
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
101
+			self::$profileID = & Api\Cache::getSession('mail', 'activeSyncProfileID');
102
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
103 103
 		}
104 104
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
105 105
 		{
106
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
106
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
107 107
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
108 108
 			{
109 109
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
114 114
 			}
115 115
 		}
116
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
116
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
117 117
 
118 118
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
119 119
 		if (!isset($GLOBALS['egw_setup']))
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 			try {
122 122
 				Mail\Account::read(self::$profileID);
123 123
 			}
124
-			catch(Exception $e) {
124
+			catch (Exception $e) {
125 125
 				unset($e);
126 126
 				self::$profileID = Mail\Account::get_default_acc_id();
127 127
 			}
128 128
 		}
129
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
129
+		if ($this->debugLevel > 0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
130 130
 		//$this->debugLevel=0;
131 131
 	}
132 132
 
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
 			$this->__construct($this->backend);
231 231
 
232 232
 			try {
233
-				$this->_connect(0,true);
233
+				$this->_connect(0, true);
234 234
 				$this->_disconnect();
235 235
 
236 236
 				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
237 237
 				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
238 238
 			}
239
-			catch(Exception $e) {
239
+			catch (Exception $e) {
240 240
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
241 241
 			}
242 242
 			if ($errors)
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 * @param int $account integer id of account to use
255 255
 	 * @todo support different accounts
256 256
 	 */
257
-	private function _connect($account=0)
257
+	private function _connect($account = 0)
258 258
 	{
259 259
 		if (!$account) $account = self::$profileID ? self::$profileID : 0;
260 260
 		if ($this->mail && $this->account != $account) $this->_disconnect();
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 			$this->account = $account;
268 268
 			// todo: tell mail which account to use
269 269
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
270
-			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
270
+			$this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
271 271
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
272 272
 		}
273 273
 		else
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
276 276
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
277 277
 		}
278
-		$this->mail->openConnection(self::$profileID,false);
278
+		$this->mail->openConnection(self::$profileID, false);
279 279
 
280 280
 		$this->_wasteID = $this->mail->getTrashFolder(false);
281 281
 		//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 */
291 291
 	private function _disconnect()
292 292
 	{
293
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
293
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__);
294 294
 		if ($this->mail) $this->mail->closeConnection();
295 295
 
296 296
 		unset($this->mail);
@@ -306,24 +306,24 @@  discard block
 block discarded – undo
306 306
 	public function GetFolderList()
307 307
 	{
308 308
 		$folderlist = array();
309
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
309
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__);
310 310
 		/*foreach($available_accounts as $account)*/ $account = 0;
311 311
 		{
312 312
 			$this->_connect($account);
313
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
314
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
313
+			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false, $_alwaysGetDefaultFolders = true);
314
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($this->folders));
315 315
 
316 316
 			foreach ($this->folders as $folder => $folderObj) {
317
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
317
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' folder='.$folder);
318 318
 				$folderlist[] = $f = array(
319
-					'id'     => $this->createID($account,$folder),
319
+					'id'     => $this->createID($account, $folder),
320 320
 					'mod'    => $folderObj->shortDisplayName,
321
-					'parent' => $this->getParentID($account,$folder),
321
+					'parent' => $this->getParentID($account, $folder),
322 322
 				);
323
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
323
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($f));
324 324
 			}
325 325
 		}
326
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
326
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($folderlist));
327 327
 
328 328
 		return $folderlist;
329 329
 	}
@@ -372,59 +372,59 @@  discard block
 block discarded – undo
372 372
 		$ClientSideMeetingRequest = false;
373 373
 		$allowSendingInvitations = 'sendifnocalnotif';
374 374
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
375
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']=='nosend')
375
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] == 'nosend')
376 376
 		{
377 377
 			$allowSendingInvitations = false;
378 378
 		}
379 379
 		elseif (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
380
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']!='nosend')
380
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] != 'nosend')
381 381
 		{
382 382
 			$allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'];
383 383
 		}
384
-		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
384
+		$smartdata_task = ($smartdata->replyflag ? 'reply' : ($smartdata->forwardflag ? 'forward' : 'new'));
385 385
 
386
-   		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 : ""));
387
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
386
+   		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 : ""));
387
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
388 388
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
389 389
 
390 390
 		// initialize our Mail
391
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
391
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
392 392
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
393 393
 		// use the standardIdentity
394
-		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
394
+		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles, self::$profileID);
395 395
 
396
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
396
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
397 397
 
398 398
 		// initialize the new Api\Mailer object for sending
399 399
 		$mailObject = new Api\Mailer(self::$profileID);
400
-		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime);
400
+		$this->mail->parseRawMessageIntoMailObject($mailObject, $smartdata->mime);
401 401
 		// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
402
-		$mailObject->Sender  = $activeMailProfile['ident_email'];
403
-		$mailObject->From 	= $activeMailProfile['ident_email'];
404
-		$mailObject->FromName = Mail::generateIdentityString($activeMailProfile,false);
402
+		$mailObject->Sender = $activeMailProfile['ident_email'];
403
+		$mailObject->From = $activeMailProfile['ident_email'];
404
+		$mailObject->FromName = Mail::generateIdentityString($activeMailProfile, false);
405 405
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
406 406
 
407 407
 
408 408
 		// prepare addressee list; moved the adding of addresses to the mailobject down
409 409
 		// to
410 410
 
411
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
411
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
412 412
 			if (!$addressObject->valid) continue;
413
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
413
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
414 414
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
415 415
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
416 416
 		}
417 417
 		// CC
418
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
418
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
419 419
 			if (!$addressObject->valid) continue;
420
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
420
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
421 421
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
422 422
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
423 423
 		}
424 424
 		// BCC
425
-		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
425
+		foreach (Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
426 426
 			if (!$addressObject->valid) continue;
427
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
427
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
428 428
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
429 429
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
430 430
 		}
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 		$use_orgbody = false;
434 434
 
435 435
 		$k = 'Content-Type';
436
-		$ContentType =$mailObject->getHeader('Content-Type');
436
+		$ContentType = $mailObject->getHeader('Content-Type');
437 437
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
438 438
 		// if the message is a multipart message, then we should use the sent body
439 439
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -453,43 +453,43 @@  discard block
 block discarded – undo
453 453
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
454 454
 			$use_orgbody = true;
455 455
 		}
456
-		$Body =  $AltBody = "";
456
+		$Body = $AltBody = "";
457 457
 		// get body of the transmitted message
458 458
 		// if this is a simple message, no structure at all
459 459
 		if (preg_match("/text/i", $ContentType))
460 460
 		{
461
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
461
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
462 462
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
463
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
464
-			if  ($simpleBodyType == "text/plain")
463
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
464
+			if ($simpleBodyType == "text/plain")
465 465
 			{
466 466
 				$Body = $body;
467 467
 				$AltBody = "<pre>".nl2br($body)."</pre>";
468
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
468
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
469 469
 			}
470 470
 			else
471 471
 			{
472 472
 				$AltBody = $body;
473
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
474
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
473
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
474
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
475 475
 			}
476 476
 		}
477 477
 		else
478 478
 		{
479 479
 			// if this is a structured message
480 480
 			// prefer plain over html
481
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
481
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
482 482
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
483
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
483
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
484 484
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
485 485
 		}
486
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
487
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
486
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
487
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
488 488
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
489 489
 		// if this is a multipart message with a boundary, we must use the original body
490 490
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
491 491
         if ($use_orgbody) {
492
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
492
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
493 493
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
494 494
 			if (($cal_body = $mailObject->findBody('calendar')) &&
495 495
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
 				{
499 499
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
500 500
 				}
501
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
501
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
502 502
 				$ClientSideMeetingRequest = true;
503 503
 			}
504 504
         }
505 505
 		// now handle the addressee list
506 506
 		$toCount = 0;
507 507
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
508
-		foreach((array)$toMailAddr as $address) {
509
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
510
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
508
+		foreach ((array)$toMailAddr as $address) {
509
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
510
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
511 511
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
512 512
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
513 513
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
514 514
 				{
515
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
515
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
516 516
 					continue;
517 517
 				}
518 518
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -520,29 +520,29 @@  discard block
 block discarded – undo
520 520
 			}
521 521
 		}
522 522
 		$ccCount = 0;
523
-		foreach((array)$ccMailAddr as $address) {
524
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
525
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
523
+		foreach ((array)$ccMailAddr as $address) {
524
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
525
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
526 526
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
527 527
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
528 528
 				$ccCount++;
529 529
 			}
530 530
 		}
531 531
 		$bccCount = 0;
532
-		foreach((array)$bccMailAddr as $address) {
533
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
534
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
532
+		foreach ((array)$bccMailAddr as $address) {
533
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
534
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
535 535
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
536 536
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
537 537
 				$bccCount++;
538 538
 			}
539 539
 		}
540 540
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
541
-		if ($toCount+$ccCount+$bccCount == 0)
541
+		if ($toCount + $ccCount + $bccCount == 0)
542 542
 		{
543 543
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
544 544
 		}
545
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
545
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
546 546
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
547 547
 /*
548 548
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -550,29 +550,29 @@  discard block
 block discarded – undo
550 550
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body (modified):'.$body);
551 551
 */
552 552
 		// add signature!! -----------------------------------------------------------------
553
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
553
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
554 554
 		try
555 555
 		{
556 556
 			$acc = Mail\Account::read($this->mail->icServer->ImapServerId);
557 557
 			//error_log(__METHOD__.__LINE__.array2string($acc));
558
-			$_signature = Mail\Account::read_identity($acc['ident_id'],true);
558
+			$_signature = Mail\Account::read_identity($acc['ident_id'], true);
559 559
 		}
560 560
 		catch (Exception $e)
561 561
 		{
562
-			$_signature=array();
562
+			$_signature = array();
563 563
 		}
564 564
 		$signature = $_signature['ident_signature'];
565 565
 		if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
566 566
 			$preferencesArray['disableRulerForSignatureSeparation']) ||
567
-			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) =='')
567
+			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) == '')
568 568
 		{
569 569
 			$disableRuler = true;
570 570
 		}
571 571
 		$beforePlain = $beforeHtml = "";
572
-		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
573
-		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
574
-		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
575
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
572
+		$beforeHtml = ($disableRuler ? '&nbsp;<br>' : '&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
573
+		$beforePlain = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
574
+		$sigText = Mail::merge($signature, array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
575
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Signature to use:'.$sigText);
576 576
 		$sigTextHtml = $beforeHtml.$sigText;
577 577
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
578 578
 		$isreply = $isforward = false;
@@ -584,26 +584,26 @@  discard block
 block discarded – undo
584 584
 		{
585 585
 			// now get on, and fetch the original mail
586 586
 			$uid = $smartdata->source->itemid;
587
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
587
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
588 588
 			$this->splitID($smartdata->source->folderid, $account, $folder);
589 589
 
590 590
 			$this->mail->reopen($folder);
591 591
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
592
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
593
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
594
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
592
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
593
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
594
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
595 595
 				// may be html
596
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
596
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
597 597
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
598 598
 				$isreply = true;
599 599
 			}
600 600
 			// plain text Message part
601
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
601
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
602 602
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
603
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
604
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
605
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
606
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
603
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
604
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
605
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
606
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
607 607
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
608 608
 				$isreply = true;
609 609
 			}
@@ -611,12 +611,12 @@  discard block
 block discarded – undo
611 611
 			{
612 612
 				$isreply = true;
613 613
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
614
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
614
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
615 615
 			}
616 616
 		}
617 617
 
618 618
 		// how to forward and other prefs
619
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
619
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
620 620
 
621 621
 		// forward -------------------------------------------------------------------------
622 622
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 		{
627 627
 			//force the default for the forwarding -> asmail
628 628
 			if (is_array($preferencesArray)) {
629
-				if (!array_key_exists('message_forwarding',$preferencesArray)
629
+				if (!array_key_exists('message_forwarding', $preferencesArray)
630 630
 					|| !isset($preferencesArray['message_forwarding'])
631 631
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
632 632
 			} else {
@@ -634,18 +634,18 @@  discard block
 block discarded – undo
634 634
 			}
635 635
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
636 636
 			$uid = $smartdata->source->itemid;
637
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
637
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
638 638
 			$this->splitID($smartdata->source->folderid, $account, $folder);
639 639
 
640 640
 			$this->mail->reopen($folder);
641 641
             // receive entire mail (header + body)
642 642
 			// get message headers for specified message
643
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
643
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
644 644
 			// build a new mime message, forward entire old mail as file
645 645
 			if ($preferencesArray['message_forwarding'] == 'asmail')
646 646
 			{
647
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
648
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
647
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
648
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
649 649
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
650 650
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
651 651
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -655,50 +655,50 @@  discard block
 block discarded – undo
655 655
 			{
656 656
 				// now get on, and fetch the original mail
657 657
 				$uid = $smartdata->source->itemid;
658
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
658
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
659 659
 				$this->splitID($smartdata->source->folderid, $account, $folder);
660 660
 
661 661
 				$this->mail->reopen($folder);
662 662
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
663
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
664
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
665
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
663
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
664
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
665
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
666 666
 					// may be html
667
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
667
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
668 668
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
669 669
 					$isforward = true;
670 670
 				}
671 671
 				// plain text Message part
672
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
672
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
673 673
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
674
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
675
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
676
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
677
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
674
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
675
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
676
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
677
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
678 678
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
679 679
 					$isforward = true;
680 680
 				}
681 681
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
682 682
 				{
683 683
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
684
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
684
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
685 685
 					$isforward = true;
686 686
 				}
687 687
 				// get all the attachments and add them too.
688 688
 				// start handle Attachments
689 689
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
690
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
690
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
691 691
 				$attachmentNames = false;
692
-				if (is_array($attachments) && count($attachments)>0)
692
+				if (is_array($attachments) && count($attachments) > 0)
693 693
 				{
694
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
695
-					foreach((array)$attachments as $key => $attachment)
694
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
695
+					foreach ((array)$attachments as $key => $attachment)
696 696
 					{
697
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
697
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
698 698
 						$attachmentNames .= $attachment['name']."\n";
699
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
699
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
700 700
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
701
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
701
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
702 702
 					}
703 703
 				}
704 704
 			}
@@ -712,36 +712,36 @@  discard block
 block discarded – undo
712 712
 		// now set the body
713 713
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
714 714
 		{
715
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
716
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
715
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
716
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
717 717
 		}
718 718
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
719 719
 		{
720
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
721
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
720
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
721
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
722 722
 		}
723 723
 		//advanced debugging
724 724
 		// Horde SMTP Class uses utf-8 by default.
725 725
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
726
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
726
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
727 727
 
728 728
 		// set a higher timeout for big messages
729 729
 		@set_time_limit(120);
730
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
730
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
731 731
 		// send
732 732
 		$send = true;
733 733
 		try {
734 734
 			$mailObject->Send();
735 735
 		}
736
-		catch(Exception $e) {
737
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
736
+		catch (Exception $e) {
737
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
738 738
 			$send = false;
739 739
 		}
740 740
 
741
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
741
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
742 742
 		{
743 743
 			$uid = $smartdata->source->itemid;
744
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
744
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
745 745
 			$this->splitID($smartdata->source->folderid, $account, $folder);
746 746
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
747 747
 			$this->mail->reopen($folder);
@@ -749,89 +749,89 @@  discard block
 block discarded – undo
749 749
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
750 750
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
751 751
 			{
752
-				$this->mail->deleteMessages(array($uid),$folder);
752
+				$this->mail->deleteMessages(array($uid), $folder);
753 753
 			} else {
754
-				$this->mail->flagMessages("answered", array($uid),$folder);
755
-				if ($smartdata_task== "forward")
754
+				$this->mail->flagMessages("answered", array($uid), $folder);
755
+				if ($smartdata_task == "forward")
756 756
 				{
757
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
757
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
758 758
 				}
759 759
 			}
760 760
 		}
761 761
 
762
-		$asf = ($send ? true:false); // initalize accordingly
763
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
762
+		$asf = ($send ? true : false); // initalize accordingly
763
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
764 764
 		{
765 765
 			$asf = false;
766 766
 			$sentFolder = $this->mail->getSentFolder();
767 767
 			if ($this->_sentID) {
768 768
 				$folderArray[] = $this->_sentID;
769 769
 			}
770
-			else if(isset($sentFolder) && $sentFolder != 'none')
770
+			else if (isset($sentFolder) && $sentFolder != 'none')
771 771
 			{
772 772
 				$folderArray[] = $sentFolder;
773 773
 			}
774 774
 			// No Sent folder set, try defaults
775 775
 			else
776 776
 			{
777
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
777
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
778 778
 				// we dont try guessing
779 779
 				$asf = true;
780 780
 			}
781 781
 			if (count($folderArray) > 0) {
782
-				foreach((array)$bccMailAddr as $address) {
783
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
784
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
782
+				foreach ((array)$bccMailAddr as $address) {
783
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
784
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
785 785
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
786 786
 					}
787 787
 				}
788
-				$BCCmail='';
789
-				if (count($mailAddr)>0) $BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
790
-				foreach($folderArray as $folderName) {
791
-					if($this->mail->isSentFolder($folderName)) {
788
+				$BCCmail = '';
789
+				if (count($mailAddr) > 0) $BCCmail = $mailObject->AddrAppend("Bcc", $mailAddr);
790
+				foreach ($folderArray as $folderName) {
791
+					if ($this->mail->isSentFolder($folderName)) {
792 792
 						$flags = '\\Seen';
793
-					} elseif($this->mail->isDraftFolder($folderName)) {
793
+					} elseif ($this->mail->isDraftFolder($folderName)) {
794 794
 						$flags = '\\Draft';
795 795
 					} else {
796 796
 						$flags = '';
797 797
 					}
798 798
 					$asf = true;
799 799
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
800
-					$this->mail->openConnection(self::$profileID,false);
800
+					$this->mail->openConnection(self::$profileID, false);
801 801
 					if ($this->mail->folderExists($folderName)) {
802 802
 						try
803 803
 						{
804
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
804
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
805 805
 									$flags);
806 806
 						}
807 807
 						catch (Api\Exception\WrongUserinput $e)
808 808
 						{
809 809
 							//$asf = false;
810
-							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$mailObject->getHeader('Subject'),$folderName,$e->getMessage()));
810
+							ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $mailObject->getHeader('Subject'), $folderName, $e->getMessage()));
811 811
 						}
812 812
 					}
813 813
 					else
814 814
 					{
815 815
 						//$asf = false;
816
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
816
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
817 817
 					}
818
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
818
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
819 819
 				}
820 820
 				//$this->mail->closeConnection();
821 821
 			}
822 822
 		}
823 823
 
824
-		$this->debugLevel=0;
824
+		$this->debugLevel = 0;
825 825
 
826 826
 		if ($send && $asf)
827 827
 		{
828
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
828
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
829 829
 			return true;
830 830
 		}
831 831
 		else
832 832
 		{
833
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
834
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
833
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
834
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
835 835
 		}
836 836
 	}
837 837
 
@@ -849,48 +849,48 @@  discard block
 block discarded – undo
849 849
 	public function GetMessage($folderid, $id, $contentparameters)
850 850
 	{
851 851
 		//$this->debugLevel=4;
852
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
852
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
853 853
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
854 854
 		$mimesupport = $contentparameters->GetMimeSupport();
855
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
855
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
856 856
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
857 857
 
858 858
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
859 859
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
860 860
 
861 861
 		//$this->debugLevel=4;
862
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
863
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
862
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
863
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
864 864
 		$account = $_folderName = $xid = null;
865
-		$this->splitID($folderid,$account,$_folderName,$xid);
865
+		$this->splitID($folderid, $account, $_folderName, $xid);
866 866
 		$this->mail->reopen($_folderName);
867 867
 		$stat = $this->StatMessage($folderid, $id);
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($stat));
868
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($stat));
869 869
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 870
 		if ($stat)
871 871
 		{
872
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($stat));
872
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($stat));
873 873
 			// initialize the object
874 874
 			$output = new SyncMail();
875
-			$headers = $this->mail->getMessageHeader($id,'',true,true,$_folderName);
875
+			$headers = $this->mail->getMessageHeader($id, '', true, true, $_folderName);
876 876
 			if (empty($headers))
877 877
 			{
878 878
 				error_log(__METHOD__.__LINE__.' Retrieval of Headers Failed! for .'.$this->account.'/'.$GLOBALS['egw_info']['user']['account_lid'].' ServerID:'.self::$profileID.'FolderID:'.$folderid.'/'.$_folderName.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference).' Stat was:'.array2string($stat));
879
-				return $output;//empty object
879
+				return $output; //empty object
880 880
 			}
881 881
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
882 882
 			// simple style
883 883
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
884
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
884
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
885 885
 
886 886
 			if ($bodypreference === false) {
887
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
888
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
887
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
888
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
889 889
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
890
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
890
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
891 891
 				// remove all other html
892 892
 				$body = strip_tags($raw_body);
893
-				if(strlen($body) > $truncsize) {
893
+				if (strlen($body) > $truncsize) {
894 894
 					$body = Utils::Utf8_truncate($body, $truncsize);
895 895
 					$output->bodytruncated = 1;
896 896
 				}
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 			else // style with bodypreferences
905 905
 			{
906 906
 				//Select body type preference
907
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
907
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
908 908
 				if ($bodypreference !== false) {
909 909
 					// bodypreference can occur multiple times
910 910
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -918,12 +918,12 @@  discard block
 block discarded – undo
918 918
 					}
919 919
 */
920 920
 				}
921
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
921
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
922 922
 				// set the protocoll class
923 923
 				$output->asbody = new SyncBaseBody();
924 924
 
925 925
 				// return full mime-message without any (charset) conversation directly as stream
926
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
926
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)
927 927
 				{
928 928
 					//SYNC_BODYPREFERENCE_MIME
929 929
 					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
@@ -932,58 +932,58 @@  discard block
 block discarded – undo
932 932
 					fseek($stream, 0, SEEK_SET);
933 933
 					$output->asbody->data = $stream;
934 934
 					$output->asbody->estimatedDataSize = $fstat['size'];
935
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
935
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
936 936
 				}
937 937
 				else
938 938
 				{
939 939
 					// fetch the body (try to gather data only once)
940
-					$css ='';
941
-					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
942
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
943
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
944
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
945
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
940
+					$css = '';
941
+					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
942
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
943
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
944
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
945
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
946 946
 						// may be html
947
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
947
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
948 948
 						$css = $this->mail->getStyles($bodyStruct);
949
-						$output->nativebodytype=2;
949
+						$output->nativebodytype = 2;
950 950
 					} else {
951 951
 						// plain text Message
952
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
953
-						$output->nativebodytype=1;
954
-						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
955
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
956
-						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
957
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
952
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
953
+						$output->nativebodytype = 1;
954
+						$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
955
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
956
+						$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
957
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
958 958
 					}
959 959
 					// whatever format decode (using the correct encoding)
960
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
960
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
961 961
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
962 962
 					// prepare plaintextbody
963
-					$plainBody='';
963
+					$plainBody = '';
964 964
 					if ($output->nativebodytype == 2)
965 965
 					{
966
-						$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
967
-						if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
966
+						$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
967
+						if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
968 968
 						{
969 969
 							$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
970 970
 						}
971 971
 						else
972 972
 						{
973
-							$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
973
+							$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
974 974
 						}
975 975
 					}
976 976
 					//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
977
-					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
977
+					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
978 978
 					// remove all other html
979
-					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
979
+					$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
980 980
 					$plainBody = strip_tags($plainBody);
981
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
981
+					if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
982 982
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
983 983
 
984
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
984
+					if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
985 985
 					{
986
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
986
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
987 987
 						// Send HTML if requested and native type was html
988 988
 						$output->asbody->type = 2;
989 989
 						$htmlbody = '<html>'.
@@ -993,23 +993,23 @@  discard block
 block discarded – undo
993 993
 							$css.
994 994
 							'</head>'.
995 995
 							'<body>';
996
-						if ($output->nativebodytype==2)
996
+						if ($output->nativebodytype == 2)
997 997
 						{
998
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
998
+							if ($css) Api\Mail\Html::replaceTagsCompletley($body, 'style');
999 999
 							// as we fetch html, and body is HTML, we may not need to handle this
1000 1000
 							$htmlbody .= $body;
1001 1001
 						}
1002 1002
 						else
1003 1003
 						{
1004 1004
 							// html requested but got only plaintext, so fake html
1005
-							$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
1005
+							$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
1006 1006
 						}
1007 1007
 						$htmlbody .= '</body>'.
1008 1008
 								'</html>';
1009 1009
 
1010
-						if(isset($truncsize) && strlen($htmlbody) > $truncsize)
1010
+						if (isset($truncsize) && strlen($htmlbody) > $truncsize)
1011 1011
 						{
1012
-							$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
1012
+							$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
1013 1013
 							$output->asbody->truncated = 1;
1014 1014
 						}
1015 1015
 						// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 					else
1021 1021
 					{
1022 1022
 						// Send Plaintext as Fallback or if original body is plainttext
1023
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1023
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1024 1024
 						/* we use plainBody (set above) instead
1025 1025
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1026 1026
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 						*/
1031 1031
 						$output->asbody->type = 1;
1032 1032
 						$output->nativebodytype = 1;
1033
-						if(isset($truncsize) &&
1033
+						if (isset($truncsize) &&
1034 1034
 							strlen($plainBody) > $truncsize)
1035 1035
 						{
1036 1036
 							$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 				}
1050 1050
 			}
1051 1051
 			// end AS12 Stuff
1052
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
1052
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
1053 1053
 			$output->read = $stat["flags"];
1054 1054
 
1055 1055
 			$output->flag = new SyncMailFlags();
@@ -1069,20 +1069,19 @@  discard block
 block discarded – undo
1069 1069
 				$output->lastverexecuted = AS_FORWARD;
1070 1070
 			}
1071 1071
 			$output->subject = $stat['subject'];
1072
-			$output->importance = $stat['priority'] > 3 ? 0 :
1073
-				($stat['priority'] < 3 ? 2 : 1) ;
1074
-			$output->datereceived = $this->mail->_strtotime($headers['DATE'],'ts',true);
1072
+			$output->importance = $stat['priority'] > 3 ? 0 : ($stat['priority'] < 3 ? 2 : 1);
1073
+			$output->datereceived = $this->mail->_strtotime($headers['DATE'], 'ts', true);
1075 1074
 //error_log(__METHOD__.__LINE__.' To:'.$headers['TO']);
1076 1075
 			$output->to = $headers['TO'];
1077
-			if ($headers['TO']) $output->displayto = ($headers['TO'] ? $headers['TO']:null); //$stat['FETCHED_HEADER']['to_name']
1076
+			if ($headers['TO']) $output->displayto = ($headers['TO'] ? $headers['TO'] : null); //$stat['FETCHED_HEADER']['to_name']
1078 1077
 //error_log(__METHOD__.__LINE__.' From:'.$headers['FROM']);
1079 1078
 			$output->from = $headers['FROM'];
1080
-			if (isset($headers['CC']) && $headers['CC']) $output->cc = ($headers['CC'] ? $headers['CC']:null);
1081
-			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO']) $output->reply_to = ($headers['REPLY_TO']?$headers['REPLY_TO']:null);
1079
+			if (isset($headers['CC']) && $headers['CC']) $output->cc = ($headers['CC'] ? $headers['CC'] : null);
1080
+			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO']) $output->reply_to = ($headers['REPLY_TO'] ? $headers['REPLY_TO'] : null);
1082 1081
 
1083 1082
 			$output->messageclass = "IPM.Note";
1084
-			if (stripos($stat['mimetype'],'multipart')!== false &&
1085
-				stripos($stat['mimetype'],'signed')!== false)
1083
+			if (stripos($stat['mimetype'], 'multipart') !== false &&
1084
+				stripos($stat['mimetype'], 'signed') !== false)
1086 1085
 			{
1087 1086
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1088 1087
 			}
@@ -1091,20 +1090,20 @@  discard block
 block discarded – undo
1091 1090
 			}
1092 1091
 
1093 1092
 			// start handle Attachments (include text/calendar multipart alternative)
1094
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1093
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1095 1094
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1096
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1095
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1097 1096
 			{
1098
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1097
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1099 1098
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1100 1099
 				foreach ($attachments as $key => $attach)
1101 1100
 				{
1102
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1101
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1103 1102
 
1104 1103
 					// pass meeting requests to calendar plugin
1105 1104
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1106 1105
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1107
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1106
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1108 1107
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1109 1108
 					{
1110 1109
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1114,7 +1113,7 @@  discard block
 block discarded – undo
1114 1113
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1115 1114
 						//$output->messageclass = "IPM.Schedule.Meeting";
1116 1115
 						unset($attachment);
1117
-						continue;	// do NOT add attachment as attachment
1116
+						continue; // do NOT add attachment as attachment
1118 1117
 					}
1119 1118
 					if (Request::GetProtocolVersion() >= 12.0) {
1120 1119
 						$attachment = new SyncBaseAttachment();
@@ -1122,33 +1121,33 @@  discard block
 block discarded – undo
1122 1121
 							$output->asattachments = array();
1123 1122
 						$attachment->estimatedDataSize = $attach['size'];
1124 1123
 						$attachment->method = 1;
1125
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1124
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1126 1125
 					} else {
1127 1126
 						$attachment = new SyncAttachment();
1128 1127
 						if (!isset($output->attachments) || !is_array($output->attachments))
1129 1128
 							$output->attachments = array();
1130 1129
 						$attachment->attsize = $attach['size'];
1131 1130
 						$attachment->attmethod = 1;
1132
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1131
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1133 1132
 					}
1134 1133
 
1135 1134
 					$attachment->displayname = $attach['name'];
1136 1135
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1137 1136
 
1138
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1137
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1139 1138
 					//$attachment->isinline=0; // if not inline, do not use isinline
1140
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1139
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1141 1140
 					{
1142 1141
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1143 1142
 						{
1144 1143
 							$attachment->isinline = true;
1145 1144
 						}
1146 1145
 						if (Request::GetProtocolVersion() >= 12.0) {
1147
-							$attachment->method=1;
1148
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1146
+							$attachment->method = 1;
1147
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1149 1148
 						} else {
1150
-							$attachment->attmethod=6;
1151
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1149
+							$attachment->attmethod = 6;
1150
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1152 1151
 						}
1153 1152
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1154 1153
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1169,7 +1168,7 @@  discard block
 block discarded – undo
1169 1168
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1170 1169
             $output->internetcpid = INTERNET_CPID_UTF8;
1171 1170
 
1172
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1171
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1173 1172
 //$this->debugLevel=0;
1174 1173
 			return $output;
1175 1174
 		}
@@ -1192,30 +1191,30 @@  discard block
 block discarded – undo
1192 1191
 	{
1193 1192
 		if (!class_exists('calendar_zpush'))
1194 1193
 		{
1195
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1194
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1196 1195
 			return null;
1197 1196
 		}
1198 1197
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1199 1198
 		{
1200
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1199
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1201 1200
 			return false;
1202 1201
 		}
1203 1202
 		$ret = false;
1204
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1203
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1205 1204
 		{
1206 1205
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1207
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1206
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1208 1207
 			{
1209
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1208
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1210 1209
 
1211 1210
 				// calling backend again with iCal attachment, to let calendar add the event
1212 1211
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1213
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1212
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1214 1213
 					$response);
1215 1214
 				break;
1216 1215
 			}
1217 1216
 		}
1218
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1217
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1219 1218
 		return $ret;
1220 1219
 	}
1221 1220
 
@@ -1229,9 +1228,9 @@  discard block
 block discarded – undo
1229 1228
      * @param string $attname - should contain (folder)id
1230 1229
 	 * @return SyncItemOperationsAttachment-object
1231 1230
 	 */
1232
-	function GetAttachmentData($fid,$attname) {
1233
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1234
-		return $this->_GetAttachmentData($fid,$attname);
1231
+	function GetAttachmentData($fid, $attname) {
1232
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1233
+		return $this->_GetAttachmentData($fid, $attname);
1235 1234
 	}
1236 1235
 
1237 1236
 	/**
@@ -1244,9 +1243,9 @@  discard block
 block discarded – undo
1244 1243
      * @param string $attname - should contain (folder)id
1245 1244
 	 * @return SyncItemOperationsAttachment-object
1246 1245
 	 */
1247
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1248
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1249
-		return $this->_GetAttachmentData($fid,$attname);
1246
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1247
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1248
+		return $this->_GetAttachmentData($fid, $attname);
1250 1249
 	}
1251 1250
 
1252 1251
 	/**
@@ -1258,23 +1257,23 @@  discard block
 block discarded – undo
1258 1257
      * @param string $attname - should contain (folder)id
1259 1258
 	 * @return SyncItemOperationsAttachment-object
1260 1259
 	 */
1261
-	private function _GetAttachmentData($fid,$attname)
1260
+	private function _GetAttachmentData($fid, $attname)
1262 1261
 	{
1263
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1262
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1264 1263
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1265 1264
 		list($folderid, $id, $part) = explode(":", $attname);
1266 1265
 
1267 1266
 		$this->splitID($folderid, $account, $folder);
1268 1267
 
1269
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1268
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1270 1269
 
1271 1270
 		$this->mail->reopen($folder);
1272
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1271
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1273 1272
 		$SIOattachment = new SyncItemOperationsAttachment();
1274
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1273
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1275 1274
 		$SIOattachment->data = $attachment['attachment'];
1276 1275
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1277
-		if (isset($attachment['type']) )
1276
+		if (isset($attachment['type']))
1278 1277
 			$SIOattachment->contenttype = $attachment['type'];
1279 1278
 
1280 1279
 		unset($attachment);
@@ -1317,17 +1316,17 @@  discard block
 block discarded – undo
1317 1316
 	 */
1318 1317
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1319 1318
 	{
1320
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1319
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1321 1320
 		//unset($folderid, $id, $message, $contentParameters);
1322 1321
 		$account = $folder = null;
1323 1322
 		$this->splitID($folderid, $account, $folder);
1324 1323
 		if (isset($message->flag)) {
1325 1324
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1326
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1327
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1325
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1326
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1328 1327
 			} else {
1329
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1330
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1328
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1329
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1331 1330
 			}
1332 1331
 		}
1333 1332
 		return $this->StatMessage($folderid, $id);
@@ -1349,23 +1348,23 @@  discard block
 block discarded – undo
1349 1348
 	 */
1350 1349
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1351 1350
 	{
1352
-		unset($contentParameters);	// not used, but required by function signature
1351
+		unset($contentParameters); // not used, but required by function signature
1353 1352
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1354 1353
 		$account = $srcFolder = $destFolder = null;
1355 1354
 		$this->splitID($folderid, $account, $srcFolder);
1356 1355
 		$this->splitID($newfolderid, $account, $destFolder);
1357 1356
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1358
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1357
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1359 1358
 		$this->mail->reopen($destFolder);
1360 1359
 		$status = $this->mail->getFolderStatus($destFolder);
1361 1360
 		$uidNext = $status['uidnext'];
1362 1361
 		$this->mail->reopen($srcFolder);
1363 1362
 
1364 1363
 		// move message
1365
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1366
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1364
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1365
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1367 1366
 		// return the new id "as string"
1368
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1367
+		return ($rv === true ? $uidNext : $rv[$id])."";
1369 1368
 	}
1370 1369
 
1371 1370
 	/**
@@ -1373,7 +1372,7 @@  discard block
 block discarded – undo
1373 1372
 	 *
1374 1373
 	 *  @param int $cutoffdate =null timestamp with cutoffdate, default 12 weeks
1375 1374
 	 */
1376
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1375
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1377 1376
 	{
1378 1377
 		if ($cutoffdate > 0)
1379 1378
 		{
@@ -1381,8 +1380,8 @@  discard block
 block discarded – undo
1381 1380
 		}
1382 1381
 		else
1383 1382
 		{
1384
-			$cutoffdate = Api\DateTime::to('now','ts')-(3600*24*28*3);
1385
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutoffdate));
1383
+			$cutoffdate = Api\DateTime::to('now', 'ts') - (3600 * 24 * 28 * 3);
1384
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutoffdate));
1386 1385
 		}
1387 1386
 		return $this->fetchMessages($folderid, $cutoffdate);
1388 1387
 	}
@@ -1399,11 +1398,11 @@  discard block
 block discarded – undo
1399 1398
 	 * @param string $_id =null uid of single message to fetch
1400 1399
 	 * @return array uid => array StatMessage($folderid, $_id)
1401 1400
 	 */
1402
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL)
1401
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL)
1403 1402
 	{
1404 1403
 		static $headers = array();
1405 1404
 
1406
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1405
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1407 1406
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1408 1407
 		$rv_messages = array();
1409 1408
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1414,63 +1413,63 @@  discard block
 block discarded – undo
1414 1413
 		}
1415 1414
 		else
1416 1415
 		{
1417
-			$headers = array();	// clear cache to not use too much memory
1416
+			$headers = array(); // clear cache to not use too much memory
1418 1417
 
1419
-			if ($this->debugLevel>1) $starttime = microtime (true);
1418
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1420 1419
 			$this->_connect($this->account);
1421
-			if ($this->debugLevel>1)
1420
+			if ($this->debugLevel > 1)
1422 1421
 			{
1423 1422
 				$endtime = microtime(true) - $starttime;
1424
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1423
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1425 1424
 			}
1426 1425
 			$messagelist = $_filter = array();
1427 1426
 			// if not connected, any further action must fail
1428
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1429
-			if ($this->debugLevel>1) $starttime = microtime (true);
1427
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1428
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1430 1429
 			$account = $_folderName = $id = null;
1431
-			$this->splitID($folderid,$account,$_folderName,$id);
1432
-			if ($this->debugLevel>1)
1430
+			$this->splitID($folderid, $account, $_folderName, $id);
1431
+			if ($this->debugLevel > 1)
1433 1432
 			{
1434 1433
 				$endtime = microtime(true) - $starttime;
1435
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1434
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1436 1435
 			}
1437
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1438
-			if ($this->debugLevel>1) $starttime = microtime (true);
1439
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1440
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1441
-			if ($this->debugLevel>1)
1436
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1437
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1438
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1439
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1440
+			if ($this->debugLevel > 1)
1442 1441
 			{
1443 1442
 				$endtime = microtime(true) - $starttime;
1444
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1443
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1445 1444
 			}
1446 1445
 		}
1447
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1446
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1448 1447
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1449 1448
 		$messagelist = array();
1450
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1449
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1451 1450
 		//if ($_returnModHash) $messageFolderHash = array();
1452 1451
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1453 1452
 		{
1454
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1453
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1455 1454
 			$headers[$vars['uid']] = $vars;
1456
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1455
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1457 1456
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1458 1457
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1459
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1458
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1460 1459
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1461 1460
 			$mess["id"] = $vars['uid'];
1462 1461
 			// 'seen' aka 'read' is the only flag we want to know about
1463 1462
 			$mess["flags"] = 0;
1464 1463
 			// outlook supports additional flags, set them to 0
1465
-			if($vars["seen"]) $mess["flags"] = 1;
1466
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1464
+			if ($vars["seen"]) $mess["flags"] = 1;
1465
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1467 1466
 			$messagelist[$vars['uid']] = $mess;
1468 1467
 			unset($mess);
1469 1468
 		}
1470
-		if ($this->debugLevel>1)
1469
+		if ($this->debugLevel > 1)
1471 1470
 		{
1472 1471
 			$endtime = microtime(true) - $gstarttime;
1473
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1472
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1474 1473
 		}
1475 1474
 		return $messagelist;
1476 1475
 	}
@@ -1521,32 +1520,32 @@  discard block
 block discarded – undo
1521 1520
 	public function getSearchResultsMailbox($_searchquery)
1522 1521
 	{
1523 1522
 		//$this->debugLevel=1;
1524
-		$searchquery=$_searchquery->GetDataArray();
1523
+		$searchquery = $_searchquery->GetDataArray();
1525 1524
 		if (!is_array($searchquery)) return array();
1526
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1525
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1527 1526
 
1528 1527
 		if (isset($searchquery['searchrebuildresults'])) {
1529 1528
 			$rebuildresults = $searchquery['searchrebuildresults'];
1530 1529
 		} else {
1531 1530
 			$rebuildresults = false;
1532 1531
 		}
1533
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1532
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1534 1533
 
1535 1534
 		if (isset($searchquery['deeptraversal'])) {
1536 1535
 			$deeptraversal = $searchquery['deeptraversal'];
1537 1536
 		} else {
1538 1537
 			$deeptraversal = false;
1539 1538
 		}
1540
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1539
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1541 1540
 
1542 1541
 		if (isset($searchquery['searchrange'])) {
1543
-			$range = explode("-",$_searchquery->GetSearchRange());
1544
-			$start =$range[0] + 1;
1542
+			$range = explode("-", $_searchquery->GetSearchRange());
1543
+			$start = $range[0] + 1;
1545 1544
 			$limit = $range[1] - $range[0] + 1;
1546 1545
 		} else {
1547 1546
 			$range = false;
1548 1547
 		}
1549
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1548
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1550 1549
 
1551 1550
 		//foreach($searchquery['query'] as $k => $value) {
1552 1551
 		//	$query = $value;
@@ -1569,15 +1568,15 @@  discard block
 block discarded – undo
1569 1568
 		}
1570 1569
 		if (!$folderid)
1571 1570
 		{
1572
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1573
-			$folderid = $this->createID($account=0,$_folderName);
1571
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1572
+			$folderid = $this->createID($account = 0, $_folderName);
1574 1573
 		}
1575
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1576
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1574
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1575
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1577 1576
 		$this->_connect($account);
1578 1577
 		// this should not be needed ???
1579
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1580
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1578
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1579
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1581 1580
 						 'string'=> $searchText,
1582 1581
 						 'status'=>'any'
1583 1582
 						);
@@ -1592,22 +1591,22 @@  discard block
 block discarded – undo
1592 1591
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1593 1592
 		 */
1594 1593
 			$_filter['range'] = "BETWEEN";
1595
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1596
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1597
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1598
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1594
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1595
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1596
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1597
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1599 1598
 		}
1600 1599
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1601
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1602
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1600
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1601
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1603 1602
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1604
-		$list=array();
1603
+		$list = array();
1605 1604
 
1606 1605
 		$cnt = count($rv_messages['header']);
1607 1606
 		//$list['status'] = 1;
1608 1607
 		$list['searchtotal'] = $cnt;
1609 1608
 		$list["range"] = $_searchquery->GetSearchRange();
1610
-		foreach((array)$rv_messages['header'] as $i => $vars)
1609
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1611 1610
 		{
1612 1611
 			$list[] = array(
1613 1612
 				"class" => "Email",
@@ -1627,20 +1626,20 @@  discard block
 block discarded – undo
1627 1626
 	 * @param string $folder
1628 1627
 	 * @return string
1629 1628
 	 */
1630
-	private function getParentID($account,$folder)
1629
+	private function getParentID($account, $folder)
1631 1630
 	{
1632 1631
 		$this->_connect($account);
1633
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1632
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1634 1633
 
1635 1634
 		$mailFolder = $this->folders[$folder];
1636 1635
 		if (!isset($mailFolder)) return false;
1637
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1638
-		$parent = explode($delimiter,$folder);
1636
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1637
+		$parent = explode($delimiter, $folder);
1639 1638
 		array_pop($parent);
1640
-		$parent = implode($delimiter,$parent);
1639
+		$parent = implode($delimiter, $parent);
1641 1640
 
1642 1641
 		$id = $parent ? $this->createID($account, $parent) : '0';
1643
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1642
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1644 1643
 		return $id;
1645 1644
 	}
1646 1645
 
@@ -1660,48 +1659,48 @@  discard block
 block discarded – undo
1660 1659
 			$account = $folder = null;
1661 1660
 			$this->splitID($id, $account, $folder);
1662 1661
 		}
1663
-		catch(Exception $e) {
1664
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1665
-			return $folderObj=false;
1662
+		catch (Exception $e) {
1663
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1664
+			return $folderObj = false;
1666 1665
 		}
1667 1666
 		$this->_connect($account);
1668
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1667
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1669 1668
 
1670 1669
 		$mailFolder = $this->folders[$folder];
1671
-		if (!isset($mailFolder)) return $folderObj=false;
1670
+		if (!isset($mailFolder)) return $folderObj = false;
1672 1671
 
1673 1672
 		$folderObj = new SyncFolder();
1674 1673
 		$folderObj->serverid = $id;
1675
-		$folderObj->parentid = $this->getParentID($account,$folder);
1674
+		$folderObj->parentid = $this->getParentID($account, $folder);
1676 1675
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1677
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1676
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1678 1677
 		// get folder-type
1679
-		foreach($this->folders as $inbox => $mailFolder) break;
1678
+		foreach ($this->folders as $inbox => $mailFolder) break;
1680 1679
 		if ($folder == $inbox)
1681 1680
 		{
1682 1681
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1683 1682
 		}
1684
-		elseif($this->mail->isDraftFolder($folder, false, true))
1683
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1685 1684
 		{
1686 1685
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1687 1686
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1688 1687
 			$folderObj->parentid = 0; // required by devices
1689 1688
 		}
1690
-		elseif($this->mail->isTrashFolder($folder, false, true))
1689
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1691 1690
 		{
1692 1691
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1693 1692
 			$this->_wasteID = $folder;
1694 1693
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1695 1694
 			$folderObj->parentid = 0; // required by devices
1696 1695
 		}
1697
-		elseif($this->mail->isSentFolder($folder, false, true))
1696
+		elseif ($this->mail->isSentFolder($folder, false, true))
1698 1697
 		{
1699 1698
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1700 1699
 			$folderObj->parentid = 0; // required by devices
1701 1700
 			$this->_sentID = $folder;
1702 1701
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1703 1702
 		}
1704
-		elseif($this->mail->isOutbox($folder, false, true))
1703
+		elseif ($this->mail->isOutbox($folder, false, true))
1705 1704
 		{
1706 1705
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1707 1706
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1713,7 +1712,7 @@  discard block
 block discarded – undo
1713 1712
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1714 1713
 		}
1715 1714
 
1716
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1715
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1717 1716
 		return $folderObj;
1718 1717
 	}
1719 1718
 
@@ -1761,18 +1760,18 @@  discard block
 block discarded – undo
1761 1760
 
1762 1761
 		if ($type != 'mail') return false;
1763 1762
 
1764
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1763
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1765 1764
 
1766 1765
         $this->mail->reopen($folder);
1767 1766
 
1768
-		if (!($status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true)))
1767
+		if (!($status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true)))
1769 1768
 		{
1770
-            ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1769
+            ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1771 1770
             return false;
1772 1771
         }
1773
-		$syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1772
+		$syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1774 1773
 
1775
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1774
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1776 1775
 		return array();
1777 1776
 	}
1778 1777
 
@@ -1785,8 +1784,8 @@  discard block
 block discarded – undo
1785 1784
 	function GetWasteBasket()
1786 1785
 	{
1787 1786
 		$this->_connect($this->account);
1788
-		$id = $this->createID($account=0, $this->_wasteID);
1789
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1787
+		$id = $this->createID($account = 0, $this->_wasteID);
1788
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1790 1789
 		return $id;
1791 1790
 	}
1792 1791
 
@@ -1807,7 +1806,7 @@  discard block
 block discarded – undo
1807 1806
      */
1808 1807
     public function DeleteMessage($folderid, $id, $contentParameters)
1809 1808
 	{
1810
-		unset($contentParameters);	// not used, but required by function signature
1809
+		unset($contentParameters); // not used, but required by function signature
1811 1810
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1812 1811
 		/*
1813 1812
 		$this->imap_reopenFolder($folderid);
@@ -1818,7 +1817,7 @@  discard block
 block discarded – undo
1818 1817
 		// we may have to split folderid
1819 1818
 		$account = $folder = null;
1820 1819
 		$this->splitID($folderid, $account, $folder);
1821
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1820
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1822 1821
 		$_messageUID = (array)$id;
1823 1822
 
1824 1823
 		$this->_connect($this->account);
@@ -1830,9 +1829,9 @@  discard block
 block discarded – undo
1830 1829
 		catch (Api\Exception $e)
1831 1830
 		{
1832 1831
 			$error = $e->getMessage();
1833
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1832
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1834 1833
 			// if the server thinks the message does not exist report deletion as success
1835
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1834
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1836 1835
 			return false;
1837 1836
 		}
1838 1837
 
@@ -1866,15 +1865,15 @@  discard block
 block discarded – undo
1866 1865
      */
1867 1866
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1868 1867
 	{
1869
-		unset($contentParameters);	// not used, but required by function signature
1868
+		unset($contentParameters); // not used, but required by function signature
1870 1869
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1871 1870
 		$account = $folder = null;
1872 1871
 		$this->splitID($folderid, $account, $folder);
1873 1872
 
1874 1873
 		$_messageUID = (array)$id;
1875 1874
 		$this->_connect($this->account);
1876
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1877
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1875
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1876
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1878 1877
 
1879 1878
 		return $rv;
1880 1879
 	}
@@ -1891,7 +1890,7 @@  discard block
 block discarded – undo
1891 1890
 	 */
1892 1891
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1893 1892
 	{
1894
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1893
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1895 1894
 		return false;
1896 1895
 	}
1897 1896
 
@@ -1906,7 +1905,7 @@  discard block
 block discarded – undo
1906 1905
 	 */
1907 1906
 	public function DeleteFolder($parentid, $id)
1908 1907
 	{
1909
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$parentid', '$id') NOT supported!");
1908
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$parentid', '$id') NOT supported!");
1910 1909
 		return false;
1911 1910
 	}
1912 1911
 
@@ -1926,8 +1925,8 @@  discard block
 block discarded – undo
1926 1925
 		$this->_connect($this->account);
1927 1926
 		$account = $folder = null;
1928 1927
 		$this->splitID($folderid, $account, $folder);
1929
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1930
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1928
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1929
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1931 1930
 
1932 1931
 		return $rv;
1933 1932
 	}
@@ -1941,17 +1940,17 @@  discard block
 block discarded – undo
1941 1940
 	 * @return string
1942 1941
 	 * @throws Api\Exception\WrongParameter
1943 1942
 	 */
1944
-	private function createID($account,$folder,$id=0)
1943
+	private function createID($account, $folder, $id = 0)
1945 1944
 	{
1946 1945
 		if (!is_numeric($folder))
1947 1946
 		{
1948 1947
 			// convert string $folder in numeric id
1949
-			$folder = $this->folder2hash($account,$f=$folder);
1948
+			$folder = $this->folder2hash($account, $f = $folder);
1950 1949
 		}
1951 1950
 
1952 1951
 		$str = $this->backend->createID($account, $folder, $id);
1953 1952
 
1954
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1953
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1955 1954
 
1956 1955
 		return $str;
1957 1956
 	}
@@ -1965,14 +1964,14 @@  discard block
 block discarded – undo
1965 1964
 	 * @param int &$id=null
1966 1965
 	 * @throws Api\Exception\WrongParameter
1967 1966
 	 */
1968
-	private function splitID($str,&$account,&$folder,&$id=null)
1967
+	private function splitID($str, &$account, &$folder, &$id = null)
1969 1968
 	{
1970 1969
 		$this->backend->splitID($str, $account, $folder, $id);
1971 1970
 
1972 1971
 		// convert numeric folder-id back to folder name
1973
-		$folder = $this->hash2folder($account,$f=$folder);
1972
+		$folder = $this->hash2folder($account, $f = $folder);
1974 1973
 
1975
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
1974
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$id)");
1976 1975
 	}
1977 1976
 
1978 1977
 	/**
@@ -1989,9 +1988,9 @@  discard block
 block discarded – undo
1989 1988
 	 * @param string $folder
1990 1989
 	 * @return int
1991 1990
 	 */
1992
-	private function folder2hash($account,$folder)
1991
+	private function folder2hash($account, $folder)
1993 1992
 	{
1994
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
1993
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
1995 1994
 
1996 1995
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
1997 1996
 		{
@@ -2012,9 +2011,9 @@  discard block
 block discarded – undo
2012 2011
 	 * @param int $index
2013 2012
 	 * @return string NULL if not used so far
2014 2013
 	 */
2015
-	private function hash2folder($account,$index)
2014
+	private function hash2folder($account, $index)
2016 2015
 	{
2017
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2016
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2018 2017
 
2019 2018
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2020 2019
 	}
@@ -2051,9 +2050,9 @@  discard block
 block discarded – undo
2051 2050
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2052 2051
 				($hashes = file_get_contents($file)))
2053 2052
 			{
2054
-				$this->folderHashes = json_decode($hashes,true);
2053
+				$this->folderHashes = json_decode($hashes, true);
2055 2054
 				// fallback in case hashes have been serialized instead of being json-encoded
2056
-				if (json_last_error()!=JSON_ERROR_NONE)
2055
+				if (json_last_error() != JSON_ERROR_NONE)
2057 2056
 				{
2058 2057
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2059 2058
 					$this->folderHashes = unserialize($hashes);
@@ -2099,9 +2098,9 @@  discard block
 block discarded – undo
2099 2098
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2100 2099
 	 * @throws Api\Exception\AssertionFailed
2101 2100
 	 */
2102
-	private function hashFile($old=false)
2101
+	private function hashFile($old = false)
2103 2102
 	{
2104
-		if (!($dev_id=Request::GetDeviceID()))
2103
+		if (!($dev_id = Request::GetDeviceID()))
2105 2104
 		{
2106 2105
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2107 2106
 		}
Please login to merge, or discard this patch.
Braces   +589 added lines, -173 removed lines patch added patch discarded remove patch
@@ -81,29 +81,47 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function __construct(activesync_backend $backend)
83 83
 	{
84
-		if ($GLOBALS['egw_setup']) return;
84
+		if ($GLOBALS['egw_setup'])
85
+		{
86
+			return;
87
+		}
85 88
 
86 89
 		//$this->debugLevel=2;
87 90
 		$this->backend = $backend;
88 91
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
89 92
 		{
90
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
93
+			if ($this->debugLevel>1)
94
+			{
95
+				error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
96
+			}
91 97
 			// globals preferences add appname varname value
92 98
 			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
93 99
 			// save prefs
94 100
 			$GLOBALS['egw']->preferences->save_repository(true);
95 101
 		}
96
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
102
+		if ($this->debugLevel>1)
103
+		{
104
+			error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
105
+		}
97 106
 
98 107
 		if (is_null(self::$profileID))
99 108
 		{
100
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
109
+			if ($this->debugLevel>1)
110
+			{
111
+				error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
112
+			}
101 113
 			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
102
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
114
+			if ($this->debugLevel>1)
115
+			{
116
+				error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
117
+			}
103 118
 		}
104 119
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
105 120
 		{
106
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
121
+			if ($this->debugLevel>1)
122
+			{
123
+				error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
124
+			}
107 125
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
108 126
 			{
109 127
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -113,7 +131,10 @@  discard block
 block discarded – undo
113 131
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
114 132
 			}
115 133
 		}
116
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
134
+		if ($this->debugLevel>1)
135
+		{
136
+			error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
137
+		}
117 138
 
118 139
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
119 140
 		if (!isset($GLOBALS['egw_setup']))
@@ -126,7 +147,10 @@  discard block
 block discarded – undo
126 147
 				self::$profileID = Mail\Account::get_default_acc_id();
127 148
 			}
128 149
 		}
129
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
150
+		if ($this->debugLevel>0)
151
+		{
152
+			error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
153
+		}
130 154
 		//$this->debugLevel=0;
131 155
 	}
132 156
 
@@ -233,8 +257,14 @@  discard block
 block discarded – undo
233 257
 				$this->_connect(0,true);
234 258
 				$this->_disconnect();
235 259
 
236
-				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
237
-				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
260
+				if (!$this->_wasteID)
261
+				{
262
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
263
+				}
264
+				if (!$this->_sentID)
265
+				{
266
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
267
+				}
238 268
 			}
239 269
 			catch(Exception $e) {
240 270
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
@@ -256,8 +286,14 @@  discard block
 block discarded – undo
256 286
 	 */
257 287
 	private function _connect($account=0)
258 288
 	{
259
-		if (!$account) $account = self::$profileID ? self::$profileID : 0;
260
-		if ($this->mail && $this->account != $account) $this->_disconnect();
289
+		if (!$account)
290
+		{
291
+			$account = self::$profileID ? self::$profileID : 0;
292
+		}
293
+		if ($this->mail && $this->account != $account)
294
+		{
295
+			$this->_disconnect();
296
+		}
261 297
 
262 298
 		$this->_wasteID = false;
263 299
 		$this->_sentID = false;
@@ -268,12 +304,18 @@  discard block
 block discarded – undo
268 304
 			// todo: tell mail which account to use
269 305
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
270 306
 			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
271
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
307
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
308
+			{
309
+				self::$profileID = $this->mail->icServer->ImapServerId;
310
+			}
272 311
 		}
273 312
 		else
274 313
 		{
275 314
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
276
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
315
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
316
+			{
317
+				self::$profileID = $this->mail->icServer->ImapServerId;
318
+			}
277 319
 		}
278 320
 		$this->mail->openConnection(self::$profileID,false);
279 321
 
@@ -290,8 +332,14 @@  discard block
 block discarded – undo
290 332
 	 */
291 333
 	private function _disconnect()
292 334
 	{
293
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
294
-		if ($this->mail) $this->mail->closeConnection();
335
+		if ($this->debugLevel>0)
336
+		{
337
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
338
+		}
339
+		if ($this->mail)
340
+		{
341
+			$this->mail->closeConnection();
342
+		}
295 343
 
296 344
 		unset($this->mail);
297 345
 		unset($this->account);
@@ -306,24 +354,43 @@  discard block
 block discarded – undo
306 354
 	public function GetFolderList()
307 355
 	{
308 356
 		$folderlist = array();
309
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
357
+		if ($this->debugLevel>0)
358
+		{
359
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
360
+		}
310 361
 		/*foreach($available_accounts as $account)*/ $account = 0;
311 362
 		{
312 363
 			$this->_connect($account);
313
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
314
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
364
+			if (!isset($this->folders))
365
+			{
366
+				$this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
367
+			}
368
+			if ($this->debugLevel>1)
369
+			{
370
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
371
+			}
315 372
 
316
-			foreach ($this->folders as $folder => $folderObj) {
317
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
373
+			foreach ($this->folders as $folder => $folderObj)
374
+			{
375
+				if ($this->debugLevel>1)
376
+				{
377
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
378
+				}
318 379
 				$folderlist[] = $f = array(
319 380
 					'id'     => $this->createID($account,$folder),
320 381
 					'mod'    => $folderObj->shortDisplayName,
321 382
 					'parent' => $this->getParentID($account,$folder),
322 383
 				);
323
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
384
+				if ($this->debugLevel>1)
385
+				{
386
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
387
+				}
324 388
 			}
325 389
 		}
326
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
390
+		if ($this->debugLevel>0)
391
+		{
392
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
393
+		}
327 394
 
328 395
 		return $folderlist;
329 396
 	}
@@ -384,11 +451,17 @@  discard block
 block discarded – undo
384 451
 		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
385 452
 
386 453
    		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 : ""));
387
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
454
+		if ($this->debugLevel>0)
455
+		{
456
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
457
+		}
388 458
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
389 459
 
390 460
 		// initialize our Mail
391
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
461
+		if (!isset($this->mail))
462
+		{
463
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
464
+		}
392 465
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
393 466
 		// use the standardIdentity
394 467
 		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
@@ -408,22 +481,34 @@  discard block
 block discarded – undo
408 481
 		// prepare addressee list; moved the adding of addresses to the mailobject down
409 482
 		// to
410 483
 
411
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
412
-			if (!$addressObject->valid) continue;
484
+		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject)
485
+		{
486
+			if (!$addressObject->valid)
487
+			{
488
+				continue;
489
+			}
413 490
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
414 491
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
415 492
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
416 493
 		}
417 494
 		// CC
418
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
419
-			if (!$addressObject->valid) continue;
495
+		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject)
496
+		{
497
+			if (!$addressObject->valid)
498
+			{
499
+				continue;
500
+			}
420 501
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
421 502
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
422 503
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
423 504
 		}
424 505
 		// BCC
425
-		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
426
-			if (!$addressObject->valid) continue;
506
+		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject)
507
+		{
508
+			if (!$addressObject->valid)
509
+			{
510
+				continue;
511
+			}
427 512
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
428 513
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
429 514
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
@@ -436,12 +521,14 @@  discard block
 block discarded – undo
436 521
 		$ContentType =$mailObject->getHeader('Content-Type');
437 522
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
438 523
 		// if the message is a multipart message, then we should use the sent body
439
-		if (preg_match("/multipart/i", $ContentType)) {
524
+		if (preg_match("/multipart/i", $ContentType))
525
+		{
440 526
 			$use_orgbody = true;
441 527
 		}
442 528
 
443 529
 		// save the original content-type header for the body part when forwarding
444
-		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
530
+		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody)
531
+		{
445 532
 			//continue; // ignore
446 533
 		}
447 534
 		// horde/egw_ mailer does everything as utf-8, the following should not be needed
@@ -450,7 +537,8 @@  discard block
 block discarded – undo
450 537
 		// if the message is a multipart message, then we should use the sent body
451 538
 		if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
452 539
 			((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
453
-			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
540
+			$k == "Content-Type" && preg_match("/multipart/i", $ContentType)))
541
+		{
454 542
 			$use_orgbody = true;
455 543
 		}
456 544
 		$Body =  $AltBody = "";
@@ -483,12 +571,19 @@  discard block
 block discarded – undo
483 571
 			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
484 572
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
485 573
 		}
486
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
487
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
574
+		if ($this->debugLevel>1 && $Body)
575
+		{
576
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
577
+		}
578
+		if ($this->debugLevel>1 && $AltBody)
579
+		{
580
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
581
+		}
488 582
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
489 583
 		// if this is a multipart message with a boundary, we must use the original body
490 584
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
491
-        if ($use_orgbody) {
585
+        if ($use_orgbody)
586
+        {
492 587
     	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
493 588
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
494 589
 			if (($cal_body = $mailObject->findBody('calendar')) &&
@@ -498,15 +593,20 @@  discard block
 block discarded – undo
498 593
 				{
499 594
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
500 595
 				}
501
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
596
+				if ($this->debugLevel)
597
+				{
598
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
599
+				}
502 600
 				$ClientSideMeetingRequest = true;
503 601
 			}
504 602
         }
505 603
 		// now handle the addressee list
506 604
 		$toCount = 0;
507 605
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
508
-		foreach((array)$toMailAddr as $address) {
509
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
606
+		foreach((array)$toMailAddr as $address)
607
+		{
608
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
609
+			{
510 610
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
511 611
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
512 612
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
@@ -520,19 +620,29 @@  discard block
 block discarded – undo
520 620
 			}
521 621
 		}
522 622
 		$ccCount = 0;
523
-		foreach((array)$ccMailAddr as $address) {
524
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
623
+		foreach((array)$ccMailAddr as $address)
624
+		{
625
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
626
+			{
525 627
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
526
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
628
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
629
+				{
630
+					continue;
631
+				}
527 632
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
528 633
 				$ccCount++;
529 634
 			}
530 635
 		}
531 636
 		$bccCount = 0;
532
-		foreach((array)$bccMailAddr as $address) {
533
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
637
+		foreach((array)$bccMailAddr as $address)
638
+		{
639
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
640
+			{
534 641
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
535
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
642
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
643
+				{
644
+					continue;
645
+				}
536 646
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
537 647
 				$bccCount++;
538 648
 			}
@@ -542,7 +652,10 @@  discard block
 block discarded – undo
542 652
 		{
543 653
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
544 654
 		}
545
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
655
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false)
656
+		{
657
+			return true;
658
+		}
546 659
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
547 660
 /*
548 661
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -572,7 +685,10 @@  discard block
 block discarded – undo
572 685
 		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
573 686
 		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
574 687
 		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
575
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
688
+		if ($this->debugLevel>0)
689
+		{
690
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
691
+		}
576 692
 		$sigTextHtml = $beforeHtml.$sigText;
577 693
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
578 694
 		$isreply = $isforward = false;
@@ -590,10 +706,17 @@  discard block
 block discarded – undo
590 706
 			$this->mail->reopen($folder);
591 707
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
592 708
 			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
593
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
594
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
709
+			if ($this->debugLevel>3)
710
+			{
711
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
712
+			}
713
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
714
+		    {
595 715
 				// may be html
596
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
716
+				if ($this->debugLevel>0)
717
+				{
718
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
719
+				}
597 720
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
598 721
 				$isreply = true;
599 722
 			}
@@ -602,8 +725,12 @@  discard block
 block discarded – undo
602 725
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
603 726
 			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
604 727
 			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
605
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
606
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
728
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
729
+			{
730
+				if ($this->debugLevel>0)
731
+				{
732
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
733
+				}
607 734
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
608 735
 				$isreply = true;
609 736
 			}
@@ -611,7 +738,10 @@  discard block
 block discarded – undo
611 738
 			{
612 739
 				$isreply = true;
613 740
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
614
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
741
+				if ($this->debugLevel>0)
742
+				{
743
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
744
+				}
615 745
 			}
616 746
 		}
617 747
 
@@ -625,11 +755,17 @@  discard block
 block discarded – undo
625 755
 			(isset($smartdata->replacemime) && $smartdata->replacemime == false)))
626 756
 		{
627 757
 			//force the default for the forwarding -> asmail
628
-			if (is_array($preferencesArray)) {
758
+			if (is_array($preferencesArray))
759
+			{
629 760
 				if (!array_key_exists('message_forwarding',$preferencesArray)
630 761
 					|| !isset($preferencesArray['message_forwarding'])
631
-					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
632
-			} else {
762
+					|| empty($preferencesArray['message_forwarding']))
763
+				{
764
+					$preferencesArray['message_forwarding'] = 'asmail';
765
+				}
766
+			}
767
+			else
768
+			{
633 769
 				$preferencesArray['message_forwarding'] = 'asmail';
634 770
 			}
635 771
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
@@ -661,27 +797,44 @@  discard block
 block discarded – undo
661 797
 				$this->mail->reopen($folder);
662 798
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
663 799
 				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
664
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
665
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
800
+				if ($this->debugLevel>0)
801
+				{
802
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
803
+				}
804
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
805
+				{
666 806
 					// may be html
667
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
807
+					if ($this->debugLevel>0)
808
+					{
809
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
810
+					}
668 811
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
669 812
 					$isforward = true;
670 813
 				}
671 814
 				// plain text Message part
672
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
815
+				if ($this->debugLevel>0)
816
+				{
817
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
818
+				}
673 819
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
674 820
 				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
675 821
 				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
676
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
677
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
822
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
823
+				{
824
+					if ($this->debugLevel>0)
825
+					{
826
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
827
+					}
678 828
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
679 829
 					$isforward = true;
680 830
 				}
681 831
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
682 832
 				{
683 833
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
684
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
834
+					if ($this->debugLevel>0)
835
+					{
836
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
837
+					}
685 838
 					$isforward = true;
686 839
 				}
687 840
 				// get all the attachments and add them too.
@@ -694,7 +847,10 @@  discard block
 block discarded – undo
694 847
 					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
695 848
 					foreach((array)$attachments as $key => $attachment)
696 849
 					{
697
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
850
+						if ($this->debugLevel>0)
851
+						{
852
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
853
+						}
698 854
 						$attachmentNames .= $attachment['name']."\n";
699 855
 						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
700 856
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
@@ -712,18 +868,27 @@  discard block
 block discarded – undo
712 868
 		// now set the body
713 869
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
714 870
 		{
715
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
871
+			if ($this->debugLevel>1)
872
+			{
873
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
874
+			}
716 875
 			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
717 876
 		}
718 877
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
719 878
 		{
720
-			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
+			}
721 883
 			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
722 884
 		}
723 885
 		//advanced debugging
724 886
 		// Horde SMTP Class uses utf-8 by default.
725 887
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
726
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
888
+		if ($this->debugLevel>2)
889
+		{
890
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
891
+		}
727 892
 
728 893
 		// set a higher timeout for big messages
729 894
 		@set_time_limit(120);
@@ -750,7 +915,9 @@  discard block
 block discarded – undo
750 915
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
751 916
 			{
752 917
 				$this->mail->deleteMessages(array($uid),$folder);
753
-			} else {
918
+			}
919
+			else
920
+			{
754 921
 				$this->mail->flagMessages("answered", array($uid),$folder);
755 922
 				if ($smartdata_task== "forward")
756 923
 				{
@@ -764,7 +931,8 @@  discard block
 block discarded – undo
764 931
 		{
765 932
 			$asf = false;
766 933
 			$sentFolder = $this->mail->getSentFolder();
767
-			if ($this->_sentID) {
934
+			if ($this->_sentID)
935
+			{
768 936
 				$folderArray[] = $this->_sentID;
769 937
 			}
770 938
 			else if(isset($sentFolder) && $sentFolder != 'none')
@@ -778,27 +946,40 @@  discard block
 block discarded – undo
778 946
 				// we dont try guessing
779 947
 				$asf = true;
780 948
 			}
781
-			if (count($folderArray) > 0) {
782
-				foreach((array)$bccMailAddr as $address) {
783
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
949
+			if (count($folderArray) > 0)
950
+			{
951
+				foreach((array)$bccMailAddr as $address)
952
+				{
953
+					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
954
+					{
784 955
 						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
785 956
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
786 957
 					}
787 958
 				}
788 959
 				$BCCmail='';
789
-				if (count($mailAddr)>0) $BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
790
-				foreach($folderArray as $folderName) {
791
-					if($this->mail->isSentFolder($folderName)) {
960
+				if (count($mailAddr)>0)
961
+				{
962
+					$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
963
+				}
964
+				foreach($folderArray as $folderName)
965
+				{
966
+					if($this->mail->isSentFolder($folderName))
967
+					{
792 968
 						$flags = '\\Seen';
793
-					} elseif($this->mail->isDraftFolder($folderName)) {
969
+					}
970
+					elseif($this->mail->isDraftFolder($folderName))
971
+					{
794 972
 						$flags = '\\Draft';
795
-					} else {
973
+					}
974
+					else
975
+					{
796 976
 						$flags = '';
797 977
 					}
798 978
 					$asf = true;
799 979
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
800 980
 					$this->mail->openConnection(self::$profileID,false);
801
-					if ($this->mail->folderExists($folderName)) {
981
+					if ($this->mail->folderExists($folderName))
982
+					{
802 983
 						try
803 984
 						{
804 985
 							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
@@ -856,16 +1037,25 @@  discard block
 block discarded – undo
856 1037
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
857 1038
 
858 1039
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
859
-		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
1040
+		if (!$mimesupport && ($key = array_search('4', $bodypreference)))
1041
+		{
1042
+			unset($bodypreference[$key]);
1043
+		}
860 1044
 
861 1045
 		//$this->debugLevel=4;
862
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1046
+		if (!isset($this->mail))
1047
+		{
1048
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1049
+		}
863 1050
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
864 1051
 		$account = $_folderName = $xid = null;
865 1052
 		$this->splitID($folderid,$account,$_folderName,$xid);
866 1053
 		$this->mail->reopen($_folderName);
867 1054
 		$stat = $this->StatMessage($folderid, $id);
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($stat));
1055
+		if ($this->debugLevel>3)
1056
+		{
1057
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($stat));
1058
+		}
869 1059
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 1060
 		if ($stat)
871 1061
 		{
@@ -881,16 +1071,25 @@  discard block
 block discarded – undo
881 1071
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
882 1072
 			// simple style
883 1073
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
884
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1074
+			if ($this->debugLevel>0)
1075
+			{
1076
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1077
+			}
885 1078
 
886
-			if ($bodypreference === false) {
1079
+			if ($bodypreference === false)
1080
+			{
887 1081
 				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
888 1082
 				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
889 1083
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
890
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
1084
+				if (stripos($raw_body,'<style')!==false)
1085
+				{
1086
+					$body = preg_replace("/<style.*?<\/style>/is", "", $raw_body);
1087
+				}
1088
+				// in case there is only a html part
891 1089
 				// remove all other html
892 1090
 				$body = strip_tags($raw_body);
893
-				if(strlen($body) > $truncsize) {
1091
+				if(strlen($body) > $truncsize)
1092
+				{
894 1093
 					$body = Utils::Utf8_truncate($body, $truncsize);
895 1094
 					$output->bodytruncated = 1;
896 1095
 				}
@@ -905,7 +1104,8 @@  discard block
 block discarded – undo
905 1104
 			{
906 1105
 				//Select body type preference
907 1106
 				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
908
-				if ($bodypreference !== false) {
1107
+				if ($bodypreference !== false)
1108
+				{
909 1109
 					// bodypreference can occur multiple times
910 1110
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
911 1111
 					$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -939,25 +1139,49 @@  discard block
 block discarded – undo
939 1139
 					// fetch the body (try to gather data only once)
940 1140
 					$css ='';
941 1141
 					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
942
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1142
+					if ($this->debugLevel>2)
1143
+					{
1144
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1145
+					}
943 1146
 					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
944
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
945
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
1147
+					if ($this->debugLevel>3)
1148
+					{
1149
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
1150
+					}
1151
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
1152
+					{
946 1153
 						// may be html
947
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1154
+						if ($this->debugLevel>0)
1155
+						{
1156
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1157
+						}
948 1158
 						$css = $this->mail->getStyles($bodyStruct);
949 1159
 						$output->nativebodytype=2;
950
-					} else {
1160
+					}
1161
+					else
1162
+					{
951 1163
 						// plain text Message
952
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1164
+						if ($this->debugLevel>0)
1165
+						{
1166
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1167
+						}
953 1168
 						$output->nativebodytype=1;
954 1169
 						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
955
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1170
+						if ($this->debugLevel>3)
1171
+						{
1172
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1173
+						}
956 1174
 						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
957
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1175
+						if ($this->debugLevel>3)
1176
+						{
1177
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1178
+						}
958 1179
 					}
959 1180
 					// whatever format decode (using the correct encoding)
960
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1181
+					if ($this->debugLevel>3)
1182
+					{
1183
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1184
+					}
961 1185
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
962 1186
 					// prepare plaintextbody
963 1187
 					$plainBody='';
@@ -978,12 +1202,18 @@  discard block
 block discarded – undo
978 1202
 					// remove all other html
979 1203
 					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
980 1204
 					$plainBody = strip_tags($plainBody);
981
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1205
+					if ($this->debugLevel>3 && $output->nativebodytype==1)
1206
+					{
1207
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1208
+					}
982 1209
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
983 1210
 
984
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
1211
+					if ($bpReturnType==2)
1212
+					{
1213
+						//SYNC_BODYPREFERENCE_HTML
985 1214
 					{
986 1215
 						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
1216
+					}
987 1217
 						// Send HTML if requested and native type was html
988 1218
 						$output->asbody->type = 2;
989 1219
 						$htmlbody = '<html>'.
@@ -995,7 +1225,10 @@  discard block
 block discarded – undo
995 1225
 							'<body>';
996 1226
 						if ($output->nativebodytype==2)
997 1227
 						{
998
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
1228
+							if ($css)
1229
+							{
1230
+								Api\Mail\Html::replaceTagsCompletley($body,'style');
1231
+							}
999 1232
 							// as we fetch html, and body is HTML, we may not need to handle this
1000 1233
 							$htmlbody .= $body;
1001 1234
 						}
@@ -1020,7 +1253,10 @@  discard block
 block discarded – undo
1020 1253
 					else
1021 1254
 					{
1022 1255
 						// Send Plaintext as Fallback or if original body is plainttext
1023
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1256
+						if ($this->debugLevel>0)
1257
+						{
1258
+							ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1259
+						}
1024 1260
 						/* we use plainBody (set above) instead
1025 1261
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1026 1262
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1057,7 +1293,9 @@  discard block
 block discarded – undo
1057 1293
 			{
1058 1294
 				$output->flag->flagstatus = 2;
1059 1295
 				//$output->flag->flagtype = "Flag for Follow up";
1060
-			} else {
1296
+			}
1297
+			else
1298
+			{
1061 1299
 				$output->flag->flagstatus = 0;
1062 1300
 			}
1063 1301
 			if ($stat['answered'])
@@ -1074,11 +1312,21 @@  discard block
 block discarded – undo
1074 1312
 			$output->datereceived = $this->mail->_strtotime($headers['DATE'],'ts',true);
1075 1313
 //error_log(__METHOD__.__LINE__.' To:'.$headers['TO']);
1076 1314
 			$output->to = $headers['TO'];
1077
-			if ($headers['TO']) $output->displayto = ($headers['TO'] ? $headers['TO']:null); //$stat['FETCHED_HEADER']['to_name']
1315
+			if ($headers['TO'])
1316
+			{
1317
+				$output->displayto = ($headers['TO'] ? $headers['TO']:null);
1318
+			}
1319
+			//$stat['FETCHED_HEADER']['to_name']
1078 1320
 //error_log(__METHOD__.__LINE__.' From:'.$headers['FROM']);
1079 1321
 			$output->from = $headers['FROM'];
1080
-			if (isset($headers['CC']) && $headers['CC']) $output->cc = ($headers['CC'] ? $headers['CC']:null);
1081
-			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO']) $output->reply_to = ($headers['REPLY_TO']?$headers['REPLY_TO']:null);
1322
+			if (isset($headers['CC']) && $headers['CC'])
1323
+			{
1324
+				$output->cc = ($headers['CC'] ? $headers['CC']:null);
1325
+			}
1326
+			if (isset($headers['REPLY_TO']) && $headers['REPLY_TO'])
1327
+			{
1328
+				$output->reply_to = ($headers['REPLY_TO']?$headers['REPLY_TO']:null);
1329
+			}
1082 1330
 
1083 1331
 			$output->messageclass = "IPM.Note";
1084 1332
 			if (stripos($stat['mimetype'],'multipart')!== false &&
@@ -1086,7 +1334,8 @@  discard block
 block discarded – undo
1086 1334
 			{
1087 1335
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1088 1336
 			}
1089
-			if (Request::GetProtocolVersion() >= 12.0) {
1337
+			if (Request::GetProtocolVersion() >= 12.0)
1338
+			{
1090 1339
 				$output->contentclass = "urn:content-classes:message";
1091 1340
 			}
1092 1341
 
@@ -1099,7 +1348,10 @@  discard block
 block discarded – undo
1099 1348
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1100 1349
 				foreach ($attachments as $key => $attach)
1101 1350
 				{
1102
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1351
+					if ($this->debugLevel>0)
1352
+					{
1353
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1354
+					}
1103 1355
 
1104 1356
 					// pass meeting requests to calendar plugin
1105 1357
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
@@ -1116,17 +1368,24 @@  discard block
 block discarded – undo
1116 1368
 						unset($attachment);
1117 1369
 						continue;	// do NOT add attachment as attachment
1118 1370
 					}
1119
-					if (Request::GetProtocolVersion() >= 12.0) {
1371
+					if (Request::GetProtocolVersion() >= 12.0)
1372
+					{
1120 1373
 						$attachment = new SyncBaseAttachment();
1121 1374
 						if (!isset($output->asattachments) || !is_array($output->asattachments))
1122
-							$output->asattachments = array();
1375
+						{
1376
+													$output->asattachments = array();
1377
+						}
1123 1378
 						$attachment->estimatedDataSize = $attach['size'];
1124 1379
 						$attachment->method = 1;
1125 1380
 						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1126
-					} else {
1381
+					}
1382
+					else
1383
+					{
1127 1384
 						$attachment = new SyncAttachment();
1128 1385
 						if (!isset($output->attachments) || !is_array($output->attachments))
1129
-							$output->attachments = array();
1386
+						{
1387
+													$output->attachments = array();
1388
+						}
1130 1389
 						$attachment->attsize = $attach['size'];
1131 1390
 						$attachment->attmethod = 1;
1132 1391
 						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
@@ -1143,10 +1402,13 @@  discard block
 block discarded – undo
1143 1402
 						{
1144 1403
 							$attachment->isinline = true;
1145 1404
 						}
1146
-						if (Request::GetProtocolVersion() >= 12.0) {
1405
+						if (Request::GetProtocolVersion() >= 12.0)
1406
+						{
1147 1407
 							$attachment->method=1;
1148 1408
 							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1149
-						} else {
1409
+						}
1410
+						else
1411
+						{
1150 1412
 							$attachment->attmethod=6;
1151 1413
 							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1152 1414
 						}
@@ -1154,9 +1416,12 @@  discard block
 block discarded – undo
1154 1416
 						$attachment->contenttype = trim($attach['mimeType']);
1155 1417
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."'  ".$attachment->contentid);
1156 1418
 					}
1157
-					if (Request::GetProtocolVersion() >= 12.0) {
1419
+					if (Request::GetProtocolVersion() >= 12.0)
1420
+					{
1158 1421
 						array_push($output->asattachments, $attachment);
1159
-					} else {
1422
+					}
1423
+					else
1424
+					{
1160 1425
 						array_push($output->attachments, $attachment);
1161 1426
 					}
1162 1427
 					unset($attachment);
@@ -1169,8 +1434,11 @@  discard block
 block discarded – undo
1169 1434
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1170 1435
             $output->internetcpid = INTERNET_CPID_UTF8;
1171 1436
 
1172
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1173
-//$this->debugLevel=0;
1437
+			if ($this->debugLevel>3)
1438
+			{
1439
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1440
+			}
1441
+			//$this->debugLevel=0;
1174 1442
 			return $output;
1175 1443
 		}
1176 1444
 //$this->debugLevel=0;
@@ -1229,7 +1497,8 @@  discard block
 block discarded – undo
1229 1497
      * @param string $attname - should contain (folder)id
1230 1498
 	 * @return SyncItemOperationsAttachment-object
1231 1499
 	 */
1232
-	function GetAttachmentData($fid,$attname) {
1500
+	function GetAttachmentData($fid,$attname)
1501
+	{
1233 1502
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1234 1503
 		return $this->_GetAttachmentData($fid,$attname);
1235 1504
 	}
@@ -1244,7 +1513,8 @@  discard block
 block discarded – undo
1244 1513
      * @param string $attname - should contain (folder)id
1245 1514
 	 * @return SyncItemOperationsAttachment-object
1246 1515
 	 */
1247
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1516
+	function ItemOperationsGetAttachmentData($fid,$attname)
1517
+	{
1248 1518
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1249 1519
 		return $this->_GetAttachmentData($fid,$attname);
1250 1520
 	}
@@ -1266,7 +1536,10 @@  discard block
 block discarded – undo
1266 1536
 
1267 1537
 		$this->splitID($folderid, $account, $folder);
1268 1538
 
1269
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1539
+		if (!isset($this->mail))
1540
+		{
1541
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1542
+		}
1270 1543
 
1271 1544
 		$this->mail->reopen($folder);
1272 1545
 		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
@@ -1275,7 +1548,9 @@  discard block
 block discarded – undo
1275 1548
 		$SIOattachment->data = $attachment['attachment'];
1276 1549
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1277 1550
 		if (isset($attachment['type']) )
1278
-			$SIOattachment->contenttype = $attachment['type'];
1551
+		{
1552
+					$SIOattachment->contenttype = $attachment['type'];
1553
+		}
1279 1554
 
1280 1555
 		unset($attachment);
1281 1556
 
@@ -1321,11 +1596,15 @@  discard block
 block discarded – undo
1321 1596
 		//unset($folderid, $id, $message, $contentParameters);
1322 1597
 		$account = $folder = null;
1323 1598
 		$this->splitID($folderid, $account, $folder);
1324
-		if (isset($message->flag)) {
1325
-			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1599
+		if (isset($message->flag))
1600
+		{
1601
+			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2)
1602
+			{
1326 1603
 				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1327 1604
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1328
-			} else {
1605
+			}
1606
+			else
1607
+			{
1329 1608
 				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1330 1609
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1331 1610
 			}
@@ -1355,7 +1634,10 @@  discard block
 block discarded – undo
1355 1634
 		$this->splitID($folderid, $account, $srcFolder);
1356 1635
 		$this->splitID($newfolderid, $account, $destFolder);
1357 1636
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1358
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1637
+		if (!isset($this->mail))
1638
+		{
1639
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1640
+		}
1359 1641
 		$this->mail->reopen($destFolder);
1360 1642
 		$status = $this->mail->getFolderStatus($destFolder);
1361 1643
 		$uidNext = $status['uidnext'];
@@ -1403,7 +1685,10 @@  discard block
 block discarded – undo
1403 1685
 	{
1404 1686
 		static $headers = array();
1405 1687
 
1406
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1688
+		if ($this->debugLevel>1)
1689
+		{
1690
+			$gstarttime = microtime (true);
1691
+		}
1407 1692
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1408 1693
 		$rv_messages = array();
1409 1694
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1416,7 +1701,10 @@  discard block
 block discarded – undo
1416 1701
 		{
1417 1702
 			$headers = array();	// clear cache to not use too much memory
1418 1703
 
1419
-			if ($this->debugLevel>1) $starttime = microtime (true);
1704
+			if ($this->debugLevel>1)
1705
+			{
1706
+				$starttime = microtime (true);
1707
+			}
1420 1708
 			$this->_connect($this->account);
1421 1709
 			if ($this->debugLevel>1)
1422 1710
 			{
@@ -1425,8 +1713,14 @@  discard block
 block discarded – undo
1425 1713
 			}
1426 1714
 			$messagelist = $_filter = array();
1427 1715
 			// if not connected, any further action must fail
1428
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1429
-			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
+			}
1430 1724
 			$account = $_folderName = $id = null;
1431 1725
 			$this->splitID($folderid,$account,$_folderName,$id);
1432 1726
 			if ($this->debugLevel>1)
@@ -1434,8 +1728,14 @@  discard block
 block discarded – undo
1434 1728
 				$endtime = microtime(true) - $starttime;
1435 1729
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1436 1730
 			}
1437
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1438
-			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
+			}
1439 1739
 			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1440 1740
 			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1441 1741
 			if ($this->debugLevel>1)
@@ -1444,26 +1744,55 @@  discard block
 block discarded – undo
1444 1744
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1445 1745
 			}
1446 1746
 		}
1447
-		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
+		}
1448 1751
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1449 1752
 		$messagelist = array();
1450
-		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
+		}
1451 1757
 		//if ($_returnModHash) $messageFolderHash = array();
1452 1758
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1453 1759
 		{
1454
-			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
+			}
1455 1764
 			$headers[$vars['uid']] = $vars;
1456
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1457
-			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1458
-			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1459
-			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
+			}
1460 1783
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1461 1784
 			$mess["id"] = $vars['uid'];
1462 1785
 			// 'seen' aka 'read' is the only flag we want to know about
1463 1786
 			$mess["flags"] = 0;
1464 1787
 			// outlook supports additional flags, set them to 0
1465
-			if($vars["seen"]) $mess["flags"] = 1;
1466
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1788
+			if($vars["seen"])
1789
+			{
1790
+				$mess["flags"] = 1;
1791
+			}
1792
+			if ($this->debugLevel>3)
1793
+			{
1794
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1795
+			}
1467 1796
 			$messagelist[$vars['uid']] = $mess;
1468 1797
 			unset($mess);
1469 1798
 		}
@@ -1488,9 +1817,18 @@  discard block
 block discarded – undo
1488 1817
 	static function doFlagsMod($headerFlags)
1489 1818
 	{
1490 1819
 		$flags = 'nnn';
1491
-		if ($headerFlags['flagged']) $flags[0] = 'f';
1492
-		if ($headerFlags['answered']) $flags[1] = 'a';
1493
-		if ($headerFlags['forwarded']) $flags[2] = 'f';
1820
+		if ($headerFlags['flagged'])
1821
+		{
1822
+			$flags[0] = 'f';
1823
+		}
1824
+		if ($headerFlags['answered'])
1825
+		{
1826
+			$flags[1] = 'a';
1827
+		}
1828
+		if ($headerFlags['forwarded'])
1829
+		{
1830
+			$flags[2] = 'f';
1831
+		}
1494 1832
 		//ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags));
1495 1833
 		return $flags;
1496 1834
 	}
@@ -1522,31 +1860,55 @@  discard block
 block discarded – undo
1522 1860
 	{
1523 1861
 		//$this->debugLevel=1;
1524 1862
 		$searchquery=$_searchquery->GetDataArray();
1525
-		if (!is_array($searchquery)) return array();
1526
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1863
+		if (!is_array($searchquery))
1864
+		{
1865
+			return array();
1866
+		}
1867
+		if ($this->debugLevel>0)
1868
+		{
1869
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1870
+		}
1527 1871
 
1528
-		if (isset($searchquery['searchrebuildresults'])) {
1872
+		if (isset($searchquery['searchrebuildresults']))
1873
+		{
1529 1874
 			$rebuildresults = $searchquery['searchrebuildresults'];
1530
-		} else {
1875
+		}
1876
+		else
1877
+		{
1531 1878
 			$rebuildresults = false;
1532 1879
 		}
1533
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1880
+		if ($this->debugLevel>0)
1881
+		{
1882
+			ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1883
+		}
1534 1884
 
1535
-		if (isset($searchquery['deeptraversal'])) {
1885
+		if (isset($searchquery['deeptraversal']))
1886
+		{
1536 1887
 			$deeptraversal = $searchquery['deeptraversal'];
1537
-		} else {
1888
+		}
1889
+		else
1890
+		{
1538 1891
 			$deeptraversal = false;
1539 1892
 		}
1540
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1893
+		if ($this->debugLevel>0)
1894
+		{
1895
+			ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1896
+		}
1541 1897
 
1542
-		if (isset($searchquery['searchrange'])) {
1898
+		if (isset($searchquery['searchrange']))
1899
+		{
1543 1900
 			$range = explode("-",$_searchquery->GetSearchRange());
1544 1901
 			$start =$range[0] + 1;
1545 1902
 			$limit = $range[1] - $range[0] + 1;
1546
-		} else {
1903
+		}
1904
+		else
1905
+		{
1547 1906
 			$range = false;
1548 1907
 		}
1549
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1908
+		if ($this->debugLevel>0)
1909
+		{
1910
+			ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1911
+		}
1550 1912
 
1551 1913
 		//foreach($searchquery['query'] as $k => $value) {
1552 1914
 		//	$query = $value;
@@ -1598,7 +1960,10 @@  discard block
 block discarded – undo
1598 1960
 			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1599 1961
 		}
1600 1962
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1601
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1963
+		if ($this->debugLevel>1)
1964
+		{
1965
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1966
+		}
1602 1967
 		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1603 1968
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1604 1969
 		$list=array();
@@ -1630,17 +1995,26 @@  discard block
 block discarded – undo
1630 1995
 	private function getParentID($account,$folder)
1631 1996
 	{
1632 1997
 		$this->_connect($account);
1633
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1998
+		if (!isset($this->folders))
1999
+		{
2000
+			$this->folders = $this->mail->getFolderObjects(true,false);
2001
+		}
1634 2002
 
1635 2003
 		$mailFolder = $this->folders[$folder];
1636
-		if (!isset($mailFolder)) return false;
2004
+		if (!isset($mailFolder))
2005
+		{
2006
+			return false;
2007
+		}
1637 2008
 		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1638 2009
 		$parent = explode($delimiter,$folder);
1639 2010
 		array_pop($parent);
1640 2011
 		$parent = implode($delimiter,$parent);
1641 2012
 
1642 2013
 		$id = $parent ? $this->createID($account, $parent) : '0';
1643
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2014
+		if ($this->debugLevel>1)
2015
+		{
2016
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2017
+		}
1644 2018
 		return $id;
1645 2019
 	}
1646 2020
 
@@ -1654,7 +2028,10 @@  discard block
 block discarded – undo
1654 2028
 	{
1655 2029
 		static $last_id = null;
1656 2030
 		static $folderObj = null;
1657
-		if (isset($last_id) && $last_id === $id) return $folderObj;
2031
+		if (isset($last_id) && $last_id === $id)
2032
+		{
2033
+			return $folderObj;
2034
+		}
1658 2035
 
1659 2036
 		try {
1660 2037
 			$account = $folder = null;
@@ -1665,18 +2042,30 @@  discard block
 block discarded – undo
1665 2042
 			return $folderObj=false;
1666 2043
 		}
1667 2044
 		$this->_connect($account);
1668
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2045
+		if (!isset($this->folders))
2046
+		{
2047
+			$this->folders = $this->mail->getFolderObjects(true,false);
2048
+		}
1669 2049
 
1670 2050
 		$mailFolder = $this->folders[$folder];
1671
-		if (!isset($mailFolder)) return $folderObj=false;
2051
+		if (!isset($mailFolder))
2052
+		{
2053
+			return $folderObj=false;
2054
+		}
1672 2055
 
1673 2056
 		$folderObj = new SyncFolder();
1674 2057
 		$folderObj->serverid = $id;
1675 2058
 		$folderObj->parentid = $this->getParentID($account,$folder);
1676 2059
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1677
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2060
+		if ($this->debugLevel>1)
2061
+		{
2062
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2063
+		}
1678 2064
 		// get folder-type
1679
-		foreach($this->folders as $inbox => $mailFolder) break;
2065
+		foreach($this->folders as $inbox => $mailFolder)
2066
+		{
2067
+			break;
2068
+		}
1680 2069
 		if ($folder == $inbox)
1681 2070
 		{
1682 2071
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
@@ -1713,7 +2102,10 @@  discard block
 block discarded – undo
1713 2102
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1714 2103
 		}
1715 2104
 
1716
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2105
+		if ($this->debugLevel>1)
2106
+		{
2107
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2108
+		}
1717 2109
 		return $folderObj;
1718 2110
 	}
1719 2111
 
@@ -1757,11 +2149,20 @@  discard block
 block discarded – undo
1757 2149
 	{
1758 2150
 		$account = $folder = null;
1759 2151
 		$this->splitID($folderid, $account, $folder);
1760
-		if (is_numeric($account)) $type = 'mail';
2152
+		if (is_numeric($account))
2153
+		{
2154
+			$type = 'mail';
2155
+		}
1761 2156
 
1762
-		if ($type != 'mail') return false;
2157
+		if ($type != 'mail')
2158
+		{
2159
+			return false;
2160
+		}
1763 2161
 
1764
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2162
+		if (!isset($this->mail))
2163
+		{
2164
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2165
+		}
1765 2166
 
1766 2167
         $this->mail->reopen($folder);
1767 2168
 
@@ -1806,7 +2207,7 @@  discard block
 block discarded – undo
1806 2207
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1807 2208
      */
1808 2209
     public function DeleteMessage($folderid, $id, $contentParameters)
1809
-	{
2210
+    {
1810 2211
 		unset($contentParameters);	// not used, but required by function signature
1811 2212
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1812 2213
 		/*
@@ -1832,7 +2233,10 @@  discard block
 block discarded – undo
1832 2233
 			$error = $e->getMessage();
1833 2234
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1834 2235
 			// if the server thinks the message does not exist report deletion as success
1835
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
2236
+			if (stripos($error,'[NONEXISTENT]')!==false)
2237
+			{
2238
+				return true;
2239
+			}
1836 2240
 			return false;
1837 2241
 		}
1838 2242
 
@@ -1865,7 +2269,7 @@  discard block
 block discarded – undo
1865 2269
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1866 2270
      */
1867 2271
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1868
-	{
2272
+    {
1869 2273
 		unset($contentParameters);	// not used, but required by function signature
1870 2274
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1871 2275
 		$account = $folder = null;
@@ -1951,7 +2355,10 @@  discard block
 block discarded – undo
1951 2355
 
1952 2356
 		$str = $this->backend->createID($account, $folder, $id);
1953 2357
 
1954
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2358
+		if ($this->debugLevel>1)
2359
+		{
2360
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2361
+		}
1955 2362
 
1956 2363
 		return $str;
1957 2364
 	}
@@ -1972,7 +2379,10 @@  discard block
 block discarded – undo
1972 2379
 		// convert numeric folder-id back to folder name
1973 2380
 		$folder = $this->hash2folder($account,$f=$folder);
1974 2381
 
1975
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2382
+		if ($this->debugLevel>1)
2383
+		{
2384
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2385
+		}
1976 2386
 	}
1977 2387
 
1978 2388
 	/**
@@ -1991,7 +2401,10 @@  discard block
 block discarded – undo
1991 2401
 	 */
1992 2402
 	private function folder2hash($account,$folder)
1993 2403
 	{
1994
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2404
+		if(!isset($this->folderHashes))
2405
+		{
2406
+			$this->readFolderHashes();
2407
+		}
1995 2408
 
1996 2409
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
1997 2410
 		{
@@ -2014,7 +2427,10 @@  discard block
 block discarded – undo
2014 2427
 	 */
2015 2428
 	private function hash2folder($account,$index)
2016 2429
 	{
2017
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2430
+		if(!isset($this->folderHashes))
2431
+		{
2432
+			$this->readFolderHashes();
2433
+		}
2018 2434
 
2019 2435
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2020 2436
 	}
Please login to merge, or discard this patch.