Completed
Push — master ( 45c272...e3132b )
by Klaus
23:14
created
mail/inc/class.mail_zpush.inc.php 1 patch
Spacing   +343 added lines, -344 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,58 +372,58 @@  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->setFrom($activeMailProfile['ident_email'],Mail::generateIdentityString($activeMailProfile,false));
402
+		$mailObject->Sender = $activeMailProfile['ident_email'];
403
+		$mailObject->setFrom($activeMailProfile['ident_email'], Mail::generateIdentityString($activeMailProfile, false));
404 404
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
405 405
 
406 406
 
407 407
 		// prepare addressee list; moved the adding of addresses to the mailobject down
408 408
 		// to
409 409
 
410
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
410
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
411 411
 			if (!$addressObject->valid) continue;
412
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
412
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
413 413
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
414 414
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
415 415
 		}
416 416
 		// CC
417
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
417
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
418 418
 			if (!$addressObject->valid) continue;
419
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
419
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
420 420
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
421 421
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
422 422
 		}
423 423
 		// BCC
424
-		foreach(Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
424
+		foreach (Mail::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
425 425
 			if (!$addressObject->valid) continue;
426
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
426
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
427 427
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
428 428
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
429 429
 		}
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		$use_orgbody = false;
433 433
 
434 434
 		$k = 'Content-Type';
435
-		$ContentType =$mailObject->getHeader('Content-Type');
435
+		$ContentType = $mailObject->getHeader('Content-Type');
436 436
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
437 437
 		// if the message is a multipart message, then we should use the sent body
438 438
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -452,43 +452,43 @@  discard block
 block discarded – undo
452 452
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
453 453
 			$use_orgbody = true;
454 454
 		}
455
-		$Body =  $AltBody = "";
455
+		$Body = $AltBody = "";
456 456
 		// get body of the transmitted message
457 457
 		// if this is a simple message, no structure at all
458 458
 		if (preg_match("/text/i", $ContentType))
459 459
 		{
460
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
460
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
461 461
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
462
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
463
-			if  ($simpleBodyType == "text/plain")
462
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
463
+			if ($simpleBodyType == "text/plain")
464 464
 			{
465 465
 				$Body = $body;
466 466
 				$AltBody = "<pre>".nl2br($body)."</pre>";
467
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
467
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
468 468
 			}
469 469
 			else
470 470
 			{
471 471
 				$AltBody = $body;
472
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
473
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
472
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
473
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
474 474
 			}
475 475
 		}
476 476
 		else
477 477
 		{
478 478
 			// if this is a structured message
479 479
 			// prefer plain over html
480
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
480
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
481 481
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
482
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
482
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
483 483
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
484 484
 		}
485
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
486
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
485
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
486
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
487 487
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
488 488
 		// if this is a multipart message with a boundary, we must use the original body
489 489
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
490 490
         if ($use_orgbody) {
491
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
491
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
492 492
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
493 493
 			if (($cal_body = $mailObject->findBody('calendar')) &&
494 494
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -497,21 +497,21 @@  discard block
 block discarded – undo
497 497
 				{
498 498
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
499 499
 				}
500
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
500
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
501 501
 				$ClientSideMeetingRequest = true;
502 502
 			}
503 503
         }
504 504
 		// now handle the addressee list
505 505
 		$toCount = 0;
506 506
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
507
-		foreach((array)$toMailAddr as $address) {
508
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
509
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
507
+		foreach ((array)$toMailAddr as $address) {
508
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
509
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
510 510
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
511 511
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
512 512
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
513 513
 				{
514
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
514
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
515 515
 					continue;
516 516
 				}
517 517
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -519,29 +519,29 @@  discard block
 block discarded – undo
519 519
 			}
520 520
 		}
521 521
 		$ccCount = 0;
522
-		foreach((array)$ccMailAddr as $address) {
523
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
524
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
522
+		foreach ((array)$ccMailAddr as $address) {
523
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
524
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
525 525
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
526 526
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
527 527
 				$ccCount++;
528 528
 			}
529 529
 		}
530 530
 		$bccCount = 0;
531
-		foreach((array)$bccMailAddr as $address) {
532
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
533
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
531
+		foreach ((array)$bccMailAddr as $address) {
532
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
533
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
534 534
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
535 535
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
536 536
 				$bccCount++;
537 537
 			}
538 538
 		}
539 539
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
540
-		if ($toCount+$ccCount+$bccCount == 0)
540
+		if ($toCount + $ccCount + $bccCount == 0)
541 541
 		{
542 542
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
543 543
 		}
544
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
544
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
545 545
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
546 546
 /*
547 547
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -549,29 +549,29 @@  discard block
 block discarded – undo
549 549
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body (modified):'.$body);
550 550
 */
551 551
 		// add signature!! -----------------------------------------------------------------
552
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
552
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ActiveMailProfile:'.array2string($activeMailProfile));
553 553
 		try
554 554
 		{
555 555
 			$acc = Mail\Account::read($this->mail->icServer->ImapServerId);
556 556
 			//error_log(__METHOD__.__LINE__.array2string($acc));
557
-			$_signature = Mail\Account::read_identity($acc['ident_id'],true);
557
+			$_signature = Mail\Account::read_identity($acc['ident_id'], true);
558 558
 		}
559 559
 		catch (Exception $e)
560 560
 		{
561
-			$_signature=array();
561
+			$_signature = array();
562 562
 		}
563 563
 		$signature = $_signature['ident_signature'];
564 564
 		if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
565 565
 			$preferencesArray['disableRulerForSignatureSeparation']) ||
566
-			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) =='')
566
+			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) == '')
567 567
 		{
568 568
 			$disableRuler = true;
569 569
 		}
570 570
 		$beforePlain = $beforeHtml = "";
571
-		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
572
-		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
573
-		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
574
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
571
+		$beforeHtml = ($disableRuler ? '&nbsp;<br>' : '&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
572
+		$beforePlain = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
573
+		$sigText = Mail::merge($signature, array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
574
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Signature to use:'.$sigText);
575 575
 		$sigTextHtml = $beforeHtml.$sigText;
576 576
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
577 577
 		$isreply = $isforward = false;
@@ -583,26 +583,26 @@  discard block
 block discarded – undo
583 583
 		{
584 584
 			// now get on, and fetch the original mail
585 585
 			$uid = $smartdata->source->itemid;
586
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
586
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
587 587
 			$this->splitID($smartdata->source->folderid, $account, $folder);
588 588
 
589 589
 			$this->mail->reopen($folder);
590 590
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
591
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
592
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
593
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
591
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
592
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
593
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
594 594
 				// may be html
595
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
595
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
596 596
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
597 597
 				$isreply = true;
598 598
 			}
599 599
 			// plain text Message part
600
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
600
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
601 601
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
602
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
603
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
604
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
605
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
602
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
603
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
604
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
605
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
606 606
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
607 607
 				$isreply = true;
608 608
 			}
@@ -610,12 +610,12 @@  discard block
 block discarded – undo
610 610
 			{
611 611
 				$isreply = true;
612 612
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
613
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
613
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
614 614
 			}
615 615
 		}
616 616
 
617 617
 		// how to forward and other prefs
618
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
618
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
619 619
 
620 620
 		// forward -------------------------------------------------------------------------
621 621
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 		{
626 626
 			//force the default for the forwarding -> asmail
627 627
 			if (is_array($preferencesArray)) {
628
-				if (!array_key_exists('message_forwarding',$preferencesArray)
628
+				if (!array_key_exists('message_forwarding', $preferencesArray)
629 629
 					|| !isset($preferencesArray['message_forwarding'])
630 630
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
631 631
 			} else {
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
 			}
634 634
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
635 635
 			$uid = $smartdata->source->itemid;
636
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
636
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
637 637
 			$this->splitID($smartdata->source->folderid, $account, $folder);
638 638
 
639 639
 			$this->mail->reopen($folder);
640 640
             // receive entire mail (header + body)
641 641
 			// get message headers for specified message
642
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
642
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
643 643
 			// build a new mime message, forward entire old mail as file
644 644
 			if ($preferencesArray['message_forwarding'] == 'asmail')
645 645
 			{
646
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
647
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
646
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
647
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
648 648
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
649 649
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
650 650
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -654,50 +654,50 @@  discard block
 block discarded – undo
654 654
 			{
655 655
 				// now get on, and fetch the original mail
656 656
 				$uid = $smartdata->source->itemid;
657
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
657
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
658 658
 				$this->splitID($smartdata->source->folderid, $account, $folder);
659 659
 
660 660
 				$this->mail->reopen($folder);
661 661
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
662
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
663
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
664
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
662
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
663
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
664
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
665 665
 					// may be html
666
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
666
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
667 667
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
668 668
 					$isforward = true;
669 669
 				}
670 670
 				// plain text Message part
671
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
671
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
672 672
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
673
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
674
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
675
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
676
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
673
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
674
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
675
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
676
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
677 677
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
678 678
 					$isforward = true;
679 679
 				}
680 680
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
681 681
 				{
682 682
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
683
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
683
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
684 684
 					$isforward = true;
685 685
 				}
686 686
 				// get all the attachments and add them too.
687 687
 				// start handle Attachments
688 688
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
689
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
689
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
690 690
 				$attachmentNames = false;
691
-				if (is_array($attachments) && count($attachments)>0)
691
+				if (is_array($attachments) && count($attachments) > 0)
692 692
 				{
693
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
694
-					foreach((array)$attachments as $key => $attachment)
693
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
694
+					foreach ((array)$attachments as $key => $attachment)
695 695
 					{
696
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
696
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
697 697
 						$attachmentNames .= $attachment['name']."\n";
698
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
698
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
699 699
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
700
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
700
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
701 701
 					}
702 702
 				}
703 703
 			}
@@ -711,36 +711,36 @@  discard block
 block discarded – undo
711 711
 		// now set the body
712 712
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
713 713
 		{
714
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
715
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
714
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
715
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
716 716
 		}
717 717
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
718 718
 		{
719
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
720
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
719
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
720
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
721 721
 		}
722 722
 		//advanced debugging
723 723
 		// Horde SMTP Class uses utf-8 by default.
724 724
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
725
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
725
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
726 726
 
727 727
 		// set a higher timeout for big messages
728 728
 		@set_time_limit(120);
729
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
729
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
730 730
 		// send
731 731
 		$send = true;
732 732
 		try {
733 733
 			$mailObject->Send();
734 734
 		}
735
-		catch(Exception $e) {
736
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
735
+		catch (Exception $e) {
736
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
737 737
 			$send = false;
738 738
 		}
739 739
 
740
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
740
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
741 741
 		{
742 742
 			$uid = $smartdata->source->itemid;
743
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
743
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
744 744
 			$this->splitID($smartdata->source->folderid, $account, $folder);
745 745
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
746 746
 			$this->mail->reopen($folder);
@@ -748,89 +748,89 @@  discard block
 block discarded – undo
748 748
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
749 749
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
750 750
 			{
751
-				$this->mail->deleteMessages(array($uid),$folder);
751
+				$this->mail->deleteMessages(array($uid), $folder);
752 752
 			} else {
753
-				$this->mail->flagMessages("answered", array($uid),$folder);
754
-				if ($smartdata_task== "forward")
753
+				$this->mail->flagMessages("answered", array($uid), $folder);
754
+				if ($smartdata_task == "forward")
755 755
 				{
756
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
756
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
757 757
 				}
758 758
 			}
759 759
 		}
760 760
 
761
-		$asf = ($send ? true:false); // initalize accordingly
762
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
761
+		$asf = ($send ? true : false); // initalize accordingly
762
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
763 763
 		{
764 764
 			$asf = false;
765 765
 			$sentFolder = $this->mail->getSentFolder();
766 766
 			if ($this->_sentID) {
767 767
 				$folderArray[] = $this->_sentID;
768 768
 			}
769
-			else if(isset($sentFolder) && $sentFolder != 'none')
769
+			else if (isset($sentFolder) && $sentFolder != 'none')
770 770
 			{
771 771
 				$folderArray[] = $sentFolder;
772 772
 			}
773 773
 			// No Sent folder set, try defaults
774 774
 			else
775 775
 			{
776
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
776
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
777 777
 				// we dont try guessing
778 778
 				$asf = true;
779 779
 			}
780 780
 			if (count($folderArray) > 0) {
781
-				foreach((array)$bccMailAddr as $address) {
782
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
783
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
781
+				foreach ((array)$bccMailAddr as $address) {
782
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
783
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
784 784
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
785 785
 					}
786 786
 				}
787
-				$BCCmail='';
788
-				if (count($mailAddr)>0) $BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
789
-				foreach($folderArray as $folderName) {
790
-					if($this->mail->isSentFolder($folderName)) {
787
+				$BCCmail = '';
788
+				if (count($mailAddr) > 0) $BCCmail = $mailObject->AddrAppend("Bcc", $mailAddr);
789
+				foreach ($folderArray as $folderName) {
790
+					if ($this->mail->isSentFolder($folderName)) {
791 791
 						$flags = '\\Seen';
792
-					} elseif($this->mail->isDraftFolder($folderName)) {
792
+					} elseif ($this->mail->isDraftFolder($folderName)) {
793 793
 						$flags = '\\Draft';
794 794
 					} else {
795 795
 						$flags = '';
796 796
 					}
797 797
 					$asf = true;
798 798
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
799
-					$this->mail->openConnection(self::$profileID,false);
799
+					$this->mail->openConnection(self::$profileID, false);
800 800
 					if ($this->mail->folderExists($folderName)) {
801 801
 						try
802 802
 						{
803
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
803
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
804 804
 									$flags);
805 805
 						}
806 806
 						catch (Api\Exception\WrongUserinput $e)
807 807
 						{
808 808
 							//$asf = false;
809
-							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()));
809
+							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 810
 						}
811 811
 					}
812 812
 					else
813 813
 					{
814 814
 						//$asf = false;
815
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
815
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
816 816
 					}
817
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
817
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
818 818
 				}
819 819
 				//$this->mail->closeConnection();
820 820
 			}
821 821
 		}
822 822
 
823
-		$this->debugLevel=0;
823
+		$this->debugLevel = 0;
824 824
 
825 825
 		if ($send && $asf)
826 826
 		{
827
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
827
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
828 828
 			return true;
829 829
 		}
830 830
 		else
831 831
 		{
832
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
833
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
832
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
833
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
834 834
 		}
835 835
 	}
836 836
 
@@ -848,43 +848,43 @@  discard block
 block discarded – undo
848 848
 	public function GetMessage($folderid, $id, $contentparameters)
849 849
 	{
850 850
 		//$this->debugLevel=4;
851
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
851
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
852 852
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
853 853
 		$mimesupport = $contentparameters->GetMimeSupport();
854
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
854
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
855 855
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
856 856
 
857 857
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
858 858
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
859 859
 
860 860
 		//$this->debugLevel=4;
861
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
862
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
861
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
862
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
863 863
 		$account = $_folderName = $xid = null;
864
-		$this->splitID($folderid,$account,$_folderName,$xid);
864
+		$this->splitID($folderid, $account, $_folderName, $xid);
865 865
 		$this->mail->reopen($_folderName);
866
-		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
866
+		$messages = $this->fetchMessages($folderid, NULL, $id, true); // true: return all headers
867 867
 		$headers = $messages[$id];
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
868
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($headers));
869 869
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 870
 		if ($headers)
871 871
 		{
872
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($headers));
872
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($headers));
873 873
 			// initialize the object
874 874
 			$output = new SyncMail();
875 875
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
876 876
 			// simple style
877 877
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
878
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
878
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
879 879
 
880 880
 			if ($bodypreference === false) {
881
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
882
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
881
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
882
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
883 883
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
884
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
884
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
885 885
 				// remove all other html
886 886
 				$body = strip_tags($raw_body);
887
-				if(strlen($body) > $truncsize) {
887
+				if (strlen($body) > $truncsize) {
888 888
 					$body = Utils::Utf8_truncate($body, $truncsize);
889 889
 					$output->bodytruncated = 1;
890 890
 				}
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 			else // style with bodypreferences
899 899
 			{
900 900
 				//Select body type preference
901
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
901
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
902 902
 				if ($bodypreference !== false) {
903 903
 					// bodypreference can occur multiple times
904 904
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -912,12 +912,12 @@  discard block
 block discarded – undo
912 912
 					}
913 913
 */
914 914
 				}
915
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
915
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
916 916
 				// set the protocoll class
917 917
 				$output->asbody = new SyncBaseBody();
918 918
 
919 919
 				// return full mime-message without any (charset) conversation directly as stream
920
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
920
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)
921 921
 				{
922 922
 					//SYNC_BODYPREFERENCE_MIME
923 923
 					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
@@ -926,58 +926,58 @@  discard block
 block discarded – undo
926 926
 					fseek($stream, 0, SEEK_SET);
927 927
 					$output->asbody->data = $stream;
928 928
 					$output->asbody->estimatedDataSize = $fstat['size'];
929
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
929
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
930 930
 				}
931 931
 				else
932 932
 				{
933 933
 					// fetch the body (try to gather data only once)
934
-					$css ='';
935
-					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
936
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
937
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
938
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
939
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
934
+					$css = '';
935
+					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
936
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
937
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
938
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
939
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
940 940
 						// may be html
941
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
941
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
942 942
 						$css = $this->mail->getStyles($bodyStruct);
943
-						$output->nativebodytype=2;
943
+						$output->nativebodytype = 2;
944 944
 					} else {
945 945
 						// plain text Message
946
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
947
-						$output->nativebodytype=1;
948
-						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
949
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
950
-						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
951
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
946
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
947
+						$output->nativebodytype = 1;
948
+						$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
949
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
950
+						$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
951
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
952 952
 					}
953 953
 					// whatever format decode (using the correct encoding)
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
954
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
955 955
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
956 956
 					// prepare plaintextbody
957
-					$plainBody='';
957
+					$plainBody = '';
958 958
 					if ($output->nativebodytype == 2)
959 959
 					{
960
-						$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
961
-						if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
960
+						$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
961
+						if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
962 962
 						{
963 963
 							$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
964 964
 						}
965 965
 						else
966 966
 						{
967
-							$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
967
+							$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
968 968
 						}
969 969
 					}
970 970
 					//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
971
-					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
971
+					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
972 972
 					// remove all other html
973
-					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
973
+					$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
974 974
 					$plainBody = strip_tags($plainBody);
975
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
975
+					if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
976 976
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
977 977
 
978
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
978
+					if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
979 979
 					{
980
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
980
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
981 981
 						// Send HTML if requested and native type was html
982 982
 						$output->asbody->type = 2;
983 983
 						$htmlbody = '<html>'.
@@ -987,23 +987,23 @@  discard block
 block discarded – undo
987 987
 							$css.
988 988
 							'</head>'.
989 989
 							'<body>';
990
-						if ($output->nativebodytype==2)
990
+						if ($output->nativebodytype == 2)
991 991
 						{
992
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
992
+							if ($css) Api\Mail\Html::replaceTagsCompletley($body, 'style');
993 993
 							// as we fetch html, and body is HTML, we may not need to handle this
994 994
 							$htmlbody .= $body;
995 995
 						}
996 996
 						else
997 997
 						{
998 998
 							// html requested but got only plaintext, so fake html
999
-							$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
999
+							$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
1000 1000
 						}
1001 1001
 						$htmlbody .= '</body>'.
1002 1002
 								'</html>';
1003 1003
 
1004
-						if(isset($truncsize) && strlen($htmlbody) > $truncsize)
1004
+						if (isset($truncsize) && strlen($htmlbody) > $truncsize)
1005 1005
 						{
1006
-							$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
1006
+							$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
1007 1007
 							$output->asbody->truncated = 1;
1008 1008
 						}
1009 1009
 						// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
 					else
1015 1015
 					{
1016 1016
 						// Send Plaintext as Fallback or if original body is plainttext
1017
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1017
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1018 1018
 						/* we use plainBody (set above) instead
1019 1019
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1020 1020
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
 						*/
1025 1025
 						$output->asbody->type = 1;
1026 1026
 						$output->nativebodytype = 1;
1027
-						if(isset($truncsize) &&
1027
+						if (isset($truncsize) &&
1028 1028
 							strlen($plainBody) > $truncsize)
1029 1029
 						{
1030 1030
 							$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 				}
1044 1044
 			}
1045 1045
 			// end AS12 Stuff
1046
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1046
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1047 1047
 			$output->read = $headers["flags"];
1048 1048
 
1049 1049
 			$output->flag = new SyncMailFlags();
@@ -1063,9 +1063,8 @@  discard block
 block discarded – undo
1063 1063
 				$output->lastverexecuted = AS_FORWARD;
1064 1064
 			}
1065 1065
 			$output->subject = $headers['subject'];
1066
-			$output->importance = $headers['priority'] > 3 ? 0 :
1067
-				($headers['priority'] < 3 ? 2 : 1) ;
1068
-			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1066
+			$output->importance = $headers['priority'] > 3 ? 0 : ($headers['priority'] < 3 ? 2 : 1);
1067
+			$output->datereceived = $this->mail->_strtotime($headers['date'], 'ts', true);
1069 1068
 			$output->to = $headers['to_address'];
1070 1069
 			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1071 1070
 			$output->from = $headers['sender_address'];
@@ -1073,8 +1072,8 @@  discard block
 block discarded – undo
1073 1072
 			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1074 1073
 
1075 1074
 			$output->messageclass = "IPM.Note";
1076
-			if (stripos($headers['mimetype'],'multipart')!== false &&
1077
-				stripos($headers['mimetype'],'signed')!== false)
1075
+			if (stripos($headers['mimetype'], 'multipart') !== false &&
1076
+				stripos($headers['mimetype'], 'signed') !== false)
1078 1077
 			{
1079 1078
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1080 1079
 			}
@@ -1083,20 +1082,20 @@  discard block
 block discarded – undo
1083 1082
 			}
1084 1083
 
1085 1084
 			// start handle Attachments (include text/calendar multipart alternative)
1086
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1085
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1087 1086
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1088
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1087
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1089 1088
 			{
1090
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1089
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1091 1090
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1092 1091
 				foreach ($attachments as $key => $attach)
1093 1092
 				{
1094
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1093
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1095 1094
 
1096 1095
 					// pass meeting requests to calendar plugin
1097 1096
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1098 1097
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1099
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1098
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1100 1099
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1101 1100
 					{
1102 1101
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1106,7 +1105,7 @@  discard block
 block discarded – undo
1106 1105
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1107 1106
 						//$output->messageclass = "IPM.Schedule.Meeting";
1108 1107
 						unset($attachment);
1109
-						continue;	// do NOT add attachment as attachment
1108
+						continue; // do NOT add attachment as attachment
1110 1109
 					}
1111 1110
 					if (Request::GetProtocolVersion() >= 12.0) {
1112 1111
 						$attachment = new SyncBaseAttachment();
@@ -1114,33 +1113,33 @@  discard block
 block discarded – undo
1114 1113
 							$output->asattachments = array();
1115 1114
 						$attachment->estimatedDataSize = $attach['size'];
1116 1115
 						$attachment->method = 1;
1117
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1116
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1118 1117
 					} else {
1119 1118
 						$attachment = new SyncAttachment();
1120 1119
 						if (!isset($output->attachments) || !is_array($output->attachments))
1121 1120
 							$output->attachments = array();
1122 1121
 						$attachment->attsize = $attach['size'];
1123 1122
 						$attachment->attmethod = 1;
1124
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1123
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1125 1124
 					}
1126 1125
 
1127 1126
 					$attachment->displayname = $attach['name'];
1128 1127
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1129 1128
 
1130
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1129
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1131 1130
 					//$attachment->isinline=0; // if not inline, do not use isinline
1132
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1131
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1133 1132
 					{
1134 1133
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1135 1134
 						{
1136 1135
 							$attachment->isinline = true;
1137 1136
 						}
1138 1137
 						if (Request::GetProtocolVersion() >= 12.0) {
1139
-							$attachment->method=1;
1140
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1138
+							$attachment->method = 1;
1139
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1141 1140
 						} else {
1142
-							$attachment->attmethod=6;
1143
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1141
+							$attachment->attmethod = 6;
1142
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1144 1143
 						}
1145 1144
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1146 1145
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1161,7 +1160,7 @@  discard block
 block discarded – undo
1161 1160
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1162 1161
             $output->internetcpid = INTERNET_CPID_UTF8;
1163 1162
 
1164
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1163
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1165 1164
 //$this->debugLevel=0;
1166 1165
 			return $output;
1167 1166
 		}
@@ -1184,30 +1183,30 @@  discard block
 block discarded – undo
1184 1183
 	{
1185 1184
 		if (!class_exists('calendar_zpush'))
1186 1185
 		{
1187
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1186
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1188 1187
 			return null;
1189 1188
 		}
1190 1189
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1191 1190
 		{
1192
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1191
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1193 1192
 			return false;
1194 1193
 		}
1195 1194
 		$ret = false;
1196
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1195
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1197 1196
 		{
1198 1197
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1199
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1198
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1200 1199
 			{
1201
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1200
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1202 1201
 
1203 1202
 				// calling backend again with iCal attachment, to let calendar add the event
1204 1203
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1205
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1204
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1206 1205
 					$response);
1207 1206
 				break;
1208 1207
 			}
1209 1208
 		}
1210
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1209
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1211 1210
 		return $ret;
1212 1211
 	}
1213 1212
 
@@ -1221,9 +1220,9 @@  discard block
 block discarded – undo
1221 1220
      * @param string $attname - should contain (folder)id
1222 1221
 	 * @return SyncItemOperationsAttachment-object
1223 1222
 	 */
1224
-	function GetAttachmentData($fid,$attname) {
1225
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1226
-		return $this->_GetAttachmentData($fid,$attname);
1223
+	function GetAttachmentData($fid, $attname) {
1224
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1225
+		return $this->_GetAttachmentData($fid, $attname);
1227 1226
 	}
1228 1227
 
1229 1228
 	/**
@@ -1236,9 +1235,9 @@  discard block
 block discarded – undo
1236 1235
      * @param string $attname - should contain (folder)id
1237 1236
 	 * @return SyncItemOperationsAttachment-object
1238 1237
 	 */
1239
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1240
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1241
-		return $this->_GetAttachmentData($fid,$attname);
1238
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1239
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1240
+		return $this->_GetAttachmentData($fid, $attname);
1242 1241
 	}
1243 1242
 
1244 1243
 	/**
@@ -1250,23 +1249,23 @@  discard block
 block discarded – undo
1250 1249
      * @param string $attname - should contain (folder)id
1251 1250
 	 * @return SyncItemOperationsAttachment-object
1252 1251
 	 */
1253
-	private function _GetAttachmentData($fid,$attname)
1252
+	private function _GetAttachmentData($fid, $attname)
1254 1253
 	{
1255
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1254
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1256 1255
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1257 1256
 		list($folderid, $id, $part) = explode(":", $attname);
1258 1257
 
1259 1258
 		$this->splitID($folderid, $account, $folder);
1260 1259
 
1261
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1260
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1262 1261
 
1263 1262
 		$this->mail->reopen($folder);
1264
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1263
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1265 1264
 		$SIOattachment = new SyncItemOperationsAttachment();
1266
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1265
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1267 1266
 		$SIOattachment->data = $attachment['attachment'];
1268 1267
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1269
-		if (isset($attachment['type']) )
1268
+		if (isset($attachment['type']))
1270 1269
 			$SIOattachment->contenttype = $attachment['type'];
1271 1270
 
1272 1271
 		unset($attachment);
@@ -1309,17 +1308,17 @@  discard block
 block discarded – undo
1309 1308
 	 */
1310 1309
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1311 1310
 	{
1312
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1311
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1313 1312
 		//unset($folderid, $id, $message, $contentParameters);
1314 1313
 		$account = $folder = null;
1315 1314
 		$this->splitID($folderid, $account, $folder);
1316 1315
 		if (isset($message->flag)) {
1317 1316
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1318
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1319
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1317
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1318
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1320 1319
 			} else {
1321
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1322
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1320
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1321
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1323 1322
 			}
1324 1323
 		}
1325 1324
 		return $this->StatMessage($folderid, $id);
@@ -1341,23 +1340,23 @@  discard block
 block discarded – undo
1341 1340
 	 */
1342 1341
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1343 1342
 	{
1344
-		unset($contentParameters);	// not used, but required by function signature
1343
+		unset($contentParameters); // not used, but required by function signature
1345 1344
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1346 1345
 		$account = $srcFolder = $destFolder = null;
1347 1346
 		$this->splitID($folderid, $account, $srcFolder);
1348 1347
 		$this->splitID($newfolderid, $account, $destFolder);
1349 1348
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1350
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1349
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1351 1350
 		$this->mail->reopen($destFolder);
1352 1351
 		$status = $this->mail->getFolderStatus($destFolder);
1353 1352
 		$uidNext = $status['uidnext'];
1354 1353
 		$this->mail->reopen($srcFolder);
1355 1354
 
1356 1355
 		// move message
1357
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1358
-		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
1356
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1357
+		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
1359 1358
 		// return the new id "as string"
1360
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1359
+		return ($rv === true ? $uidNext : $rv[$id])."";
1361 1360
 	}
1362 1361
 
1363 1362
 	/**
@@ -1365,7 +1364,7 @@  discard block
 block discarded – undo
1365 1364
 	 *
1366 1365
 	 *  @param int $cutoffdate =null timestamp with cutoffdate, default 12 weeks
1367 1366
 	 */
1368
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1367
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1369 1368
 	{
1370 1369
 		if ($cutoffdate > 0)
1371 1370
 		{
@@ -1373,8 +1372,8 @@  discard block
 block discarded – undo
1373 1372
 		}
1374 1373
 		else
1375 1374
 		{
1376
-			$cutoffdate = Api\DateTime::to('now','ts')-(3600*24*28*3);
1377
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutoffdate));
1375
+			$cutoffdate = Api\DateTime::to('now', 'ts') - (3600 * 24 * 28 * 3);
1376
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using 12 weeks.'.date("d-M-Y", $cutoffdate));
1378 1377
 		}
1379 1378
 		return $this->fetchMessages($folderid, $cutoffdate);
1380 1379
 	}
@@ -1392,11 +1391,11 @@  discard block
 block discarded – undo
1392 1391
 	 * @param boolean $return_all_headers =false true: additinal contain all headers eg. "subject"
1393 1392
 	 * @return array uid => array StatMessage($folderid, $_id)
1394 1393
 	 */
1395
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL, $return_all_headers=false)
1394
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL, $return_all_headers = false)
1396 1395
 	{
1397 1396
 		static $headers = array();
1398 1397
 
1399
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1398
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1400 1399
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1401 1400
 		$rv_messages = array();
1402 1401
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1407,64 +1406,64 @@  discard block
 block discarded – undo
1407 1406
 		}
1408 1407
 		else
1409 1408
 		{
1410
-			$headers = array();	// clear cache to not use too much memory
1409
+			$headers = array(); // clear cache to not use too much memory
1411 1410
 
1412
-			if ($this->debugLevel>1) $starttime = microtime (true);
1411
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1413 1412
 			$this->_connect($this->account);
1414
-			if ($this->debugLevel>1)
1413
+			if ($this->debugLevel > 1)
1415 1414
 			{
1416 1415
 				$endtime = microtime(true) - $starttime;
1417
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1416
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1418 1417
 			}
1419 1418
 			$messagelist = $_filter = array();
1420 1419
 			// if not connected, any further action must fail
1421
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1422
-			if ($this->debugLevel>1) $starttime = microtime (true);
1420
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1421
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1423 1422
 			$account = $_folderName = $id = null;
1424
-			$this->splitID($folderid,$account,$_folderName,$id);
1425
-			if ($this->debugLevel>1)
1423
+			$this->splitID($folderid, $account, $_folderName, $id);
1424
+			if ($this->debugLevel > 1)
1426 1425
 			{
1427 1426
 				$endtime = microtime(true) - $starttime;
1428
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1427
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1429 1428
 			}
1430
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1431
-			if ($this->debugLevel>1) $starttime = microtime (true);
1432
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1433
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1434
-			if ($this->debugLevel>1)
1429
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1430
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1431
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1432
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1433
+			if ($this->debugLevel > 1)
1435 1434
 			{
1436 1435
 				$endtime = microtime(true) - $starttime;
1437
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1436
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1438 1437
 			}
1439 1438
 		}
1440
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1439
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1441 1440
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1442 1441
 		$messagelist = array();
1443
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1442
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1444 1443
 		//if ($_returnModHash) $messageFolderHash = array();
1445 1444
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1446 1445
 		{
1447
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1446
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1448 1447
 			$headers[$vars['uid']] = $vars;
1449
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1448
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1450 1449
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1451 1450
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1452
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1451
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1453 1452
 			$mess = $return_all_headers ? $vars : array();
1454 1453
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1455 1454
 			$mess["id"] = $vars['uid'];
1456 1455
 			// 'seen' aka 'read' is the only flag we want to know about
1457 1456
 			$mess["flags"] = 0;
1458 1457
 			// outlook supports additional flags, set them to 0
1459
-			if($vars["seen"]) $mess["flags"] = 1;
1460
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1458
+			if ($vars["seen"]) $mess["flags"] = 1;
1459
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1461 1460
 			$messagelist[$vars['uid']] = $mess;
1462 1461
 			unset($mess);
1463 1462
 		}
1464
-		if ($this->debugLevel>1)
1463
+		if ($this->debugLevel > 1)
1465 1464
 		{
1466 1465
 			$endtime = microtime(true) - $gstarttime;
1467
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1466
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1468 1467
 		}
1469 1468
 		return $messagelist;
1470 1469
 	}
@@ -1515,32 +1514,32 @@  discard block
 block discarded – undo
1515 1514
 	public function getSearchResultsMailbox($_searchquery)
1516 1515
 	{
1517 1516
 		//$this->debugLevel=1;
1518
-		$searchquery=$_searchquery->GetDataArray();
1517
+		$searchquery = $_searchquery->GetDataArray();
1519 1518
 		if (!is_array($searchquery)) return array();
1520
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1519
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1521 1520
 
1522 1521
 		if (isset($searchquery['searchrebuildresults'])) {
1523 1522
 			$rebuildresults = $searchquery['searchrebuildresults'];
1524 1523
 		} else {
1525 1524
 			$rebuildresults = false;
1526 1525
 		}
1527
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1526
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1528 1527
 
1529 1528
 		if (isset($searchquery['deeptraversal'])) {
1530 1529
 			$deeptraversal = $searchquery['deeptraversal'];
1531 1530
 		} else {
1532 1531
 			$deeptraversal = false;
1533 1532
 		}
1534
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1533
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1535 1534
 
1536 1535
 		if (isset($searchquery['searchrange'])) {
1537
-			$range = explode("-",$_searchquery->GetSearchRange());
1538
-			$start =$range[0] + 1;
1536
+			$range = explode("-", $_searchquery->GetSearchRange());
1537
+			$start = $range[0] + 1;
1539 1538
 			$limit = $range[1] - $range[0] + 1;
1540 1539
 		} else {
1541 1540
 			$range = false;
1542 1541
 		}
1543
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1542
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1544 1543
 
1545 1544
 		//foreach($searchquery['query'] as $k => $value) {
1546 1545
 		//	$query = $value;
@@ -1563,15 +1562,15 @@  discard block
 block discarded – undo
1563 1562
 		}
1564 1563
 		if (!$folderid)
1565 1564
 		{
1566
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1567
-			$folderid = $this->createID($account=0,$_folderName);
1565
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1566
+			$folderid = $this->createID($account = 0, $_folderName);
1568 1567
 		}
1569
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1570
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1568
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1569
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1571 1570
 		$this->_connect($account);
1572 1571
 		// this should not be needed ???
1573
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1574
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1572
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1573
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1575 1574
 						 'string'=> $searchText,
1576 1575
 						 'status'=>'any'
1577 1576
 						);
@@ -1586,22 +1585,22 @@  discard block
 block discarded – undo
1586 1585
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1587 1586
 		 */
1588 1587
 			$_filter['range'] = "BETWEEN";
1589
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1590
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1591
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1592
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1588
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1589
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1590
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1591
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1593 1592
 		}
1594 1593
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1595
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1596
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1594
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1595
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1597 1596
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1598
-		$list=array();
1597
+		$list = array();
1599 1598
 
1600 1599
 		$cnt = count($rv_messages['header']);
1601 1600
 		//$list['status'] = 1;
1602 1601
 		$list['searchtotal'] = $cnt;
1603 1602
 		$list["range"] = $_searchquery->GetSearchRange();
1604
-		foreach((array)$rv_messages['header'] as $i => $vars)
1603
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1605 1604
 		{
1606 1605
 			$list[] = array(
1607 1606
 				"class" => "Email",
@@ -1621,20 +1620,20 @@  discard block
 block discarded – undo
1621 1620
 	 * @param string $folder
1622 1621
 	 * @return string
1623 1622
 	 */
1624
-	private function getParentID($account,$folder)
1623
+	private function getParentID($account, $folder)
1625 1624
 	{
1626 1625
 		$this->_connect($account);
1627
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1626
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1628 1627
 
1629 1628
 		$mailFolder = $this->folders[$folder];
1630 1629
 		if (!isset($mailFolder)) return false;
1631
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1632
-		$parent = explode($delimiter,$folder);
1630
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1631
+		$parent = explode($delimiter, $folder);
1633 1632
 		array_pop($parent);
1634
-		$parent = implode($delimiter,$parent);
1633
+		$parent = implode($delimiter, $parent);
1635 1634
 
1636 1635
 		$id = $parent ? $this->createID($account, $parent) : '0';
1637
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1636
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1638 1637
 		return $id;
1639 1638
 	}
1640 1639
 
@@ -1654,48 +1653,48 @@  discard block
 block discarded – undo
1654 1653
 			$account = $folder = null;
1655 1654
 			$this->splitID($id, $account, $folder);
1656 1655
 		}
1657
-		catch(Exception $e) {
1658
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1659
-			return $folderObj=false;
1656
+		catch (Exception $e) {
1657
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1658
+			return $folderObj = false;
1660 1659
 		}
1661 1660
 		$this->_connect($account);
1662
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1661
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1663 1662
 
1664 1663
 		$mailFolder = $this->folders[$folder];
1665
-		if (!isset($mailFolder)) return $folderObj=false;
1664
+		if (!isset($mailFolder)) return $folderObj = false;
1666 1665
 
1667 1666
 		$folderObj = new SyncFolder();
1668 1667
 		$folderObj->serverid = $id;
1669
-		$folderObj->parentid = $this->getParentID($account,$folder);
1668
+		$folderObj->parentid = $this->getParentID($account, $folder);
1670 1669
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1671
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1670
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1672 1671
 		// get folder-type
1673
-		foreach($this->folders as $inbox => $mailFolder) break;
1672
+		foreach ($this->folders as $inbox => $mailFolder) break;
1674 1673
 		if ($folder == $inbox)
1675 1674
 		{
1676 1675
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1677 1676
 		}
1678
-		elseif($this->mail->isDraftFolder($folder, false, true))
1677
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1679 1678
 		{
1680 1679
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1681 1680
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1682 1681
 			$folderObj->parentid = 0; // required by devices
1683 1682
 		}
1684
-		elseif($this->mail->isTrashFolder($folder, false, true))
1683
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1685 1684
 		{
1686 1685
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1687 1686
 			$this->_wasteID = $folder;
1688 1687
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1689 1688
 			$folderObj->parentid = 0; // required by devices
1690 1689
 		}
1691
-		elseif($this->mail->isSentFolder($folder, false, true))
1690
+		elseif ($this->mail->isSentFolder($folder, false, true))
1692 1691
 		{
1693 1692
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1694 1693
 			$folderObj->parentid = 0; // required by devices
1695 1694
 			$this->_sentID = $folder;
1696 1695
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1697 1696
 		}
1698
-		elseif($this->mail->isOutbox($folder, false, true))
1697
+		elseif ($this->mail->isOutbox($folder, false, true))
1699 1698
 		{
1700 1699
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1701 1700
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1707,7 +1706,7 @@  discard block
 block discarded – undo
1707 1706
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1708 1707
 		}
1709 1708
 
1710
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1709
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1711 1710
 		return $folderObj;
1712 1711
 	}
1713 1712
 
@@ -1755,18 +1754,18 @@  discard block
 block discarded – undo
1755 1754
 
1756 1755
 		if ($type != 'mail') return false;
1757 1756
 
1758
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1757
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1759 1758
 
1760 1759
         $this->mail->reopen($folder);
1761 1760
 
1762
-		if (!($status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true)))
1761
+		if (!($status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true)))
1763 1762
 		{
1764
-            ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1763
+            ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1765 1764
             return false;
1766 1765
         }
1767
-		$syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1766
+		$syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1768 1767
 
1769
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1768
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1770 1769
 		return array();
1771 1770
 	}
1772 1771
 
@@ -1779,8 +1778,8 @@  discard block
 block discarded – undo
1779 1778
 	function GetWasteBasket()
1780 1779
 	{
1781 1780
 		$this->_connect($this->account);
1782
-		$id = $this->createID($account=0, $this->_wasteID);
1783
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1781
+		$id = $this->createID($account = 0, $this->_wasteID);
1782
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1784 1783
 		return $id;
1785 1784
 	}
1786 1785
 
@@ -1801,7 +1800,7 @@  discard block
 block discarded – undo
1801 1800
      */
1802 1801
     public function DeleteMessage($folderid, $id, $contentParameters)
1803 1802
 	{
1804
-		unset($contentParameters);	// not used, but required by function signature
1803
+		unset($contentParameters); // not used, but required by function signature
1805 1804
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1806 1805
 		/*
1807 1806
 		$this->imap_reopenFolder($folderid);
@@ -1812,7 +1811,7 @@  discard block
 block discarded – undo
1812 1811
 		// we may have to split folderid
1813 1812
 		$account = $folder = null;
1814 1813
 		$this->splitID($folderid, $account, $folder);
1815
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1814
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1816 1815
 		$_messageUID = (array)$id;
1817 1816
 
1818 1817
 		$this->_connect($this->account);
@@ -1824,9 +1823,9 @@  discard block
 block discarded – undo
1824 1823
 		catch (Api\Exception $e)
1825 1824
 		{
1826 1825
 			$error = $e->getMessage();
1827
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1826
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1828 1827
 			// if the server thinks the message does not exist report deletion as success
1829
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1828
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1830 1829
 			return false;
1831 1830
 		}
1832 1831
 
@@ -1860,15 +1859,15 @@  discard block
 block discarded – undo
1860 1859
      */
1861 1860
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1862 1861
 	{
1863
-		unset($contentParameters);	// not used, but required by function signature
1862
+		unset($contentParameters); // not used, but required by function signature
1864 1863
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1865 1864
 		$account = $folder = null;
1866 1865
 		$this->splitID($folderid, $account, $folder);
1867 1866
 
1868 1867
 		$_messageUID = (array)$id;
1869 1868
 		$this->_connect($this->account);
1870
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1871
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1869
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1870
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1872 1871
 
1873 1872
 		return $rv;
1874 1873
 	}
@@ -1885,7 +1884,7 @@  discard block
 block discarded – undo
1885 1884
 	 */
1886 1885
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1887 1886
 	{
1888
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1887
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1889 1888
 		return false;
1890 1889
 	}
1891 1890
 
@@ -1900,7 +1899,7 @@  discard block
 block discarded – undo
1900 1899
 	 */
1901 1900
 	public function DeleteFolder($parentid, $id)
1902 1901
 	{
1903
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$parentid', '$id') NOT supported!");
1902
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$parentid', '$id') NOT supported!");
1904 1903
 		return false;
1905 1904
 	}
1906 1905
 
@@ -1920,8 +1919,8 @@  discard block
 block discarded – undo
1920 1919
 		$this->_connect($this->account);
1921 1920
 		$account = $folder = null;
1922 1921
 		$this->splitID($folderid, $account, $folder);
1923
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1924
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1922
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1923
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1925 1924
 
1926 1925
 		return $rv;
1927 1926
 	}
@@ -1935,17 +1934,17 @@  discard block
 block discarded – undo
1935 1934
 	 * @return string
1936 1935
 	 * @throws Api\Exception\WrongParameter
1937 1936
 	 */
1938
-	private function createID($account,$folder,$id=0)
1937
+	private function createID($account, $folder, $id = 0)
1939 1938
 	{
1940 1939
 		if (!is_numeric($folder))
1941 1940
 		{
1942 1941
 			// convert string $folder in numeric id
1943
-			$folder = $this->folder2hash($account,$f=$folder);
1942
+			$folder = $this->folder2hash($account, $f = $folder);
1944 1943
 		}
1945 1944
 
1946 1945
 		$str = $this->backend->createID($account, $folder, $id);
1947 1946
 
1948
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1947
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1949 1948
 
1950 1949
 		return $str;
1951 1950
 	}
@@ -1959,14 +1958,14 @@  discard block
 block discarded – undo
1959 1958
 	 * @param int &$id=null
1960 1959
 	 * @throws Api\Exception\WrongParameter
1961 1960
 	 */
1962
-	private function splitID($str,&$account,&$folder,&$id=null)
1961
+	private function splitID($str, &$account, &$folder, &$id = null)
1963 1962
 	{
1964 1963
 		$this->backend->splitID($str, $account, $folder, $id);
1965 1964
 
1966 1965
 		// convert numeric folder-id back to folder name
1967
-		$folder = $this->hash2folder($account,$f=$folder);
1966
+		$folder = $this->hash2folder($account, $f = $folder);
1968 1967
 
1969
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
1968
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$id)");
1970 1969
 	}
1971 1970
 
1972 1971
 	/**
@@ -1983,9 +1982,9 @@  discard block
 block discarded – undo
1983 1982
 	 * @param string $folder
1984 1983
 	 * @return int
1985 1984
 	 */
1986
-	private function folder2hash($account,$folder)
1985
+	private function folder2hash($account, $folder)
1987 1986
 	{
1988
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
1987
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
1989 1988
 
1990 1989
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
1991 1990
 		{
@@ -2006,9 +2005,9 @@  discard block
 block discarded – undo
2006 2005
 	 * @param int $index
2007 2006
 	 * @return string NULL if not used so far
2008 2007
 	 */
2009
-	private function hash2folder($account,$index)
2008
+	private function hash2folder($account, $index)
2010 2009
 	{
2011
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2010
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2012 2011
 
2013 2012
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2014 2013
 	}
@@ -2045,9 +2044,9 @@  discard block
 block discarded – undo
2045 2044
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2046 2045
 				($hashes = file_get_contents($file)))
2047 2046
 			{
2048
-				$this->folderHashes = json_decode($hashes,true);
2047
+				$this->folderHashes = json_decode($hashes, true);
2049 2048
 				// fallback in case hashes have been serialized instead of being json-encoded
2050
-				if (json_last_error()!=JSON_ERROR_NONE)
2049
+				if (json_last_error() != JSON_ERROR_NONE)
2051 2050
 				{
2052 2051
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2053 2052
 					$this->folderHashes = unserialize($hashes);
@@ -2093,9 +2092,9 @@  discard block
 block discarded – undo
2093 2092
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2094 2093
 	 * @throws Api\Exception\AssertionFailed
2095 2094
 	 */
2096
-	private function hashFile($old=false)
2095
+	private function hashFile($old = false)
2097 2096
 	{
2098
-		if (!($dev_id=Request::GetDeviceID()))
2097
+		if (!($dev_id = Request::GetDeviceID()))
2099 2098
 		{
2100 2099
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2101 2100
 		}
Please login to merge, or discard this patch.