Completed
Push — master ( 648b6f...910b92 )
by Klaus
33:59 queued 13:24
created
mail/inc/class.mail_zpush.inc.php 2 patches
Spacing   +350 added lines, -351 removed lines patch added patch discarded remove patch
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
 		$this->backend = $backend;
91 91
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
92 92
 		{
93
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
93
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
94 94
 			// globals preferences add appname varname value
95
-			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
95
+			$GLOBALS['egw']->preferences->add('activesync', 'mail-ActiveSyncProfileID', 0, 'user');
96 96
 			// save prefs
97 97
 			$GLOBALS['egw']->preferences->save_repository(true);
98 98
 		}
99
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
99
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
100 100
 
101 101
 		if (is_null(self::$profileID))
102 102
 		{
103
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
104
-			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
105
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
103
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
104
+			self::$profileID = & Api\Cache::getSession('mail', 'activeSyncProfileID');
105
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
106 106
 		}
107 107
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
108 108
 		{
109
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
109
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
110 110
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
111 111
 			{
112 112
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
117 117
 			}
118 118
 		}
119
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
119
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
120 120
 
121 121
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
122 122
 		if (!isset($GLOBALS['egw_setup']))
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 			try {
125 125
 				Mail\Account::read(self::$profileID);
126 126
 			}
127
-			catch(Exception $e) {
127
+			catch (Exception $e) {
128 128
 				unset($e);
129 129
 				self::$profileID = Mail\Account::get_default_acc_id();
130 130
 			}
131 131
 		}
132
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
132
+		if ($this->debugLevel > 0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
133 133
 		//$this->debugLevel=0;
134 134
 	}
135 135
 
@@ -242,13 +242,13 @@  discard block
 block discarded – undo
242 242
 			$this->__construct($this->backend);
243 243
 
244 244
 			try {
245
-				$this->_connect(0,true);
245
+				$this->_connect(0, true);
246 246
 				$this->_disconnect();
247 247
 
248 248
 				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
249 249
 				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
250 250
 			}
251
-			catch(Exception $e) {
251
+			catch (Exception $e) {
252 252
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
253 253
 			}
254 254
 			if ($errors)
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 * @param int $account integer id of account to use
267 267
 	 * @todo support different accounts
268 268
 	 */
269
-	private function _connect($account=0)
269
+	private function _connect($account = 0)
270 270
 	{
271 271
 		if (!$account) $account = self::$profileID ? self::$profileID : 0;
272 272
 		if ($this->mail && $this->account != $account) $this->_disconnect();
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 			$this->account = $account;
280 280
 			// todo: tell mail which account to use
281 281
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
282
-			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
282
+			$this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
283 283
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
284 284
 		}
285 285
 		else
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
288 288
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
289 289
 		}
290
-		$this->mail->openConnection(self::$profileID,false);
290
+		$this->mail->openConnection(self::$profileID, false);
291 291
 
292 292
 		$this->_wasteID = $this->mail->getTrashFolder(false);
293 293
 		//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 */
303 303
 	private function _disconnect()
304 304
 	{
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
305
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__);
306 306
 		if ($this->mail) $this->mail->closeConnection();
307 307
 
308 308
 		unset($this->mail);
@@ -318,24 +318,24 @@  discard block
 block discarded – undo
318 318
 	public function GetFolderList()
319 319
 	{
320 320
 		$folderlist = array();
321
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
321
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__);
322 322
 		/*foreach($available_accounts as $account)*/ $account = 0;
323 323
 		{
324 324
 			$this->_connect($account);
325
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
326
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
325
+			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false, $_alwaysGetDefaultFolders = true);
326
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($this->folders));
327 327
 
328 328
 			foreach ($this->folders as $folder => $folderObj) {
329
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
329
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' folder='.$folder);
330 330
 				$folderlist[] = $f = array(
331
-					'id'     => $this->createID($account,$folder),
331
+					'id'     => $this->createID($account, $folder),
332 332
 					'mod'    => $folderObj->shortDisplayName,
333
-					'parent' => $this->getParentID($account,$folder),
333
+					'parent' => $this->getParentID($account, $folder),
334 334
 				);
335
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
335
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($f));
336 336
 			}
337 337
 		}
338
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
338
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($folderlist));
339 339
 
340 340
 		return $folderlist;
341 341
 	}
@@ -384,83 +384,83 @@  discard block
 block discarded – undo
384 384
 		$ClientSideMeetingRequest = false;
385 385
 		$allowSendingInvitations = 'sendifnocalnotif';
386 386
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
387
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']=='nosend')
387
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] == 'nosend')
388 388
 		{
389 389
 			$allowSendingInvitations = false;
390 390
 		}
391 391
 		elseif (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
392
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']!='nosend')
392
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] != 'nosend')
393 393
 		{
394 394
 			$allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'];
395 395
 		}
396
-		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
396
+		$smartdata_task = ($smartdata->replyflag ? 'reply' : ($smartdata->forwardflag ? 'forward' : 'new'));
397 397
 
398
-   		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
399
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
398
+   		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.(isset($smartdata->mime) ? $smartdata->mime : "")."task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
399
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
400 400
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
401 401
 
402 402
 		// initialize our Mail
403
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
403
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
404 404
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
405 405
 		// use the standardIdentity
406
-		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
406
+		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles, self::$profileID);
407 407
 
408
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
408
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
409 409
 		// collect identity / signature for later usage, and to determine if we may have to manipulate TransferEncoding and Charset
410 410
 		try
411 411
 		{
412 412
 			$acc = Mail\Account::read($this->mail->icServer->ImapServerId);
413 413
 			//error_log(__METHOD__.__LINE__.array2string($acc));
414
-			$_signature = Mail\Account::read_identity($acc['ident_id'],true);
414
+			$_signature = Mail\Account::read_identity($acc['ident_id'], true);
415 415
 		}
416 416
 		catch (Exception $e)
417 417
 		{
418
-			$_signature=array();
418
+			$_signature = array();
419 419
 		}
420 420
 		$signature = $_signature['ident_signature'];
421 421
 		if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
422 422
 			$preferencesArray['disableRulerForSignatureSeparation']) ||
423
-			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) =='')
423
+			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) == '')
424 424
 		{
425 425
 			$disableRuler = true;
426 426
 		}
427 427
 		$beforePlain = $beforeHtml = "";
428
-		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
429
-		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
430
-		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
431
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
428
+		$beforeHtml = ($disableRuler ? '&nbsp;<br>' : '&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
429
+		$beforePlain = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
430
+		$sigText = Mail::merge($signature, array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
431
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Signature to use:'.$sigText);
432 432
 		$sigTextHtml = $beforeHtml.$sigText;
433 433
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
434 434
 
435
-		$force8bit=false;
436
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
435
+		$force8bit = false;
436
+		if (Api\Translation::detect_encoding($sigTextPlain) != 'ascii') $force8bit = true;
437 437
 		// initialize the new Api\Mailer object for sending
438 438
 		$mailObject = new Api\Mailer(self::$profileID);
439
-		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
439
+		$this->mail->parseRawMessageIntoMailObject($mailObject, $smartdata->mime, $force8bit);
440 440
 		// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
441
-		$mailObject->Sender  = $activeMailProfile['ident_email'];
442
-		$mailObject->setFrom($activeMailProfile['ident_email'],Mail::generateIdentityString($activeMailProfile,false));
441
+		$mailObject->Sender = $activeMailProfile['ident_email'];
442
+		$mailObject->setFrom($activeMailProfile['ident_email'], Mail::generateIdentityString($activeMailProfile, false));
443 443
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
444 444
 
445 445
 		// prepare addressee list; moved the adding of addresses to the mailobject down
446 446
 		// to
447
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
447
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
448 448
 			if (!$addressObject->valid) continue;
449
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
449
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
450 450
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
451 451
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
452 452
 		}
453 453
 		// CC
454
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
454
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
455 455
 			if (!$addressObject->valid) continue;
456
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
456
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
457 457
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
458 458
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
459 459
 		}
460 460
 		// BCC
461
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
461
+		foreach ($mailObject->getAddresses('bcc') as $addressObject) {
462 462
 			if (!$addressObject->valid) continue;
463
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
463
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
464 464
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
465 465
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
466 466
 		}
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
 		$use_orgbody = false;
470 470
 
471 471
 		$k = 'Content-Type';
472
-		$ContentType =$mailObject->getHeader('Content-Type');
472
+		$ContentType = $mailObject->getHeader('Content-Type');
473 473
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
474 474
 		// if the message is a multipart message, then we should use the sent body
475 475
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -489,43 +489,43 @@  discard block
 block discarded – undo
489 489
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
490 490
 			$use_orgbody = true;
491 491
 		}
492
-		$Body =  $AltBody = "";
492
+		$Body = $AltBody = "";
493 493
 		// get body of the transmitted message
494 494
 		// if this is a simple message, no structure at all
495 495
 		if (preg_match("/text/i", $ContentType))
496 496
 		{
497
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
497
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
498 498
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
499
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
500
-			if  ($simpleBodyType == "text/plain")
499
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
500
+			if ($simpleBodyType == "text/plain")
501 501
 			{
502 502
 				$Body = $body;
503 503
 				$AltBody = "<pre>".nl2br($body)."</pre>";
504
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
504
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
505 505
 			}
506 506
 			else
507 507
 			{
508 508
 				$AltBody = $body;
509
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
510
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
509
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
510
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
511 511
 			}
512 512
 		}
513 513
 		else
514 514
 		{
515 515
 			// if this is a structured message
516 516
 			// prefer plain over html
517
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
517
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
518 518
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
519
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
519
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
520 520
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
521 521
 		}
522
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
523
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
522
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
523
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
524 524
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
525 525
 		// if this is a multipart message with a boundary, we must use the original body
526 526
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
527 527
         if ($use_orgbody) {
528
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
528
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
529 529
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
530 530
 			if (($cal_body = $mailObject->findBody('calendar')) &&
531 531
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -534,21 +534,21 @@  discard block
 block discarded – undo
534 534
 				{
535 535
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
536 536
 				}
537
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
537
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
538 538
 				$ClientSideMeetingRequest = true;
539 539
 			}
540 540
         }
541 541
 		// now handle the addressee list
542 542
 		$toCount = 0;
543 543
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
544
-		foreach((array)$toMailAddr as $address) {
545
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
546
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
544
+		foreach ((array)$toMailAddr as $address) {
545
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
546
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
547 547
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
548 548
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
549 549
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
550 550
 				{
551
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
551
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
552 552
 					continue;
553 553
 				}
554 554
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -556,29 +556,29 @@  discard block
 block discarded – undo
556 556
 			}
557 557
 		}
558 558
 		$ccCount = 0;
559
-		foreach((array)$ccMailAddr as $address) {
560
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
561
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
559
+		foreach ((array)$ccMailAddr as $address) {
560
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
561
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
562 562
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
563 563
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
564 564
 				$ccCount++;
565 565
 			}
566 566
 		}
567 567
 		$bccCount = 0;
568
-		foreach((array)$bccMailAddr as $address) {
569
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
570
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
568
+		foreach ((array)$bccMailAddr as $address) {
569
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
570
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
571 571
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
572 572
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
573 573
 				$bccCount++;
574 574
 			}
575 575
 		}
576 576
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
577
-		if ($toCount+$ccCount+$bccCount == 0)
577
+		if ($toCount + $ccCount + $bccCount == 0)
578 578
 		{
579 579
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
580 580
 		}
581
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
581
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
582 582
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
583 583
 /*
584 584
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -595,26 +595,26 @@  discard block
 block discarded – undo
595 595
 		{
596 596
 			// now get on, and fetch the original mail
597 597
 			$uid = $smartdata->source->itemid;
598
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
598
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
599 599
 			$this->splitID($smartdata->source->folderid, $account, $folder);
600 600
 
601 601
 			$this->mail->reopen($folder);
602 602
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
603
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
604
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
605
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
603
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
604
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
605
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
606 606
 				// may be html
607
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
607
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
608 608
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
609 609
 				$isreply = true;
610 610
 			}
611 611
 			// plain text Message part
612
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
612
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
613 613
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
614
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
615
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
616
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
617
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
614
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
615
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
616
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
617
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
618 618
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
619 619
 				$isreply = true;
620 620
 			}
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 			{
623 623
 				$isreply = true;
624 624
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
625
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
625
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
626 626
 			}
627 627
 		}
628 628
 
629 629
 		// how to forward and other prefs
630
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
630
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
631 631
 
632 632
 		// forward -------------------------------------------------------------------------
633 633
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 		{
638 638
 			//force the default for the forwarding -> asmail
639 639
 			if (is_array($preferencesArray)) {
640
-				if (!array_key_exists('message_forwarding',$preferencesArray)
640
+				if (!array_key_exists('message_forwarding', $preferencesArray)
641 641
 					|| !isset($preferencesArray['message_forwarding'])
642 642
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
643 643
 			} else {
@@ -645,18 +645,18 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
647 647
 			$uid = $smartdata->source->itemid;
648
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
648
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
649 649
 			$this->splitID($smartdata->source->folderid, $account, $folder);
650 650
 
651 651
 			$this->mail->reopen($folder);
652 652
             // receive entire mail (header + body)
653 653
 			// get message headers for specified message
654
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
654
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
655 655
 			// build a new mime message, forward entire old mail as file
656 656
 			if ($preferencesArray['message_forwarding'] == 'asmail')
657 657
 			{
658
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
659
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
658
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
659
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
660 660
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
661 661
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
662 662
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -666,50 +666,50 @@  discard block
 block discarded – undo
666 666
 			{
667 667
 				// now get on, and fetch the original mail
668 668
 				$uid = $smartdata->source->itemid;
669
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
669
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
670 670
 				$this->splitID($smartdata->source->folderid, $account, $folder);
671 671
 
672 672
 				$this->mail->reopen($folder);
673 673
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
674
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
675
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
676
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
674
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
675
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
676
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
677 677
 					// may be html
678
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
678
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
679 679
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
680 680
 					$isforward = true;
681 681
 				}
682 682
 				// plain text Message part
683
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
683
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
684 684
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
685
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
686
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
687
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
688
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
685
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
686
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
687
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
688
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
689 689
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
690 690
 					$isforward = true;
691 691
 				}
692 692
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
693 693
 				{
694 694
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
695
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
695
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
696 696
 					$isforward = true;
697 697
 				}
698 698
 				// get all the attachments and add them too.
699 699
 				// start handle Attachments
700 700
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
701
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
701
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
702 702
 				$attachmentNames = false;
703
-				if (is_array($attachments) && count($attachments)>0)
703
+				if (is_array($attachments) && count($attachments) > 0)
704 704
 				{
705
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
706
-					foreach((array)$attachments as $key => $attachment)
705
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
706
+					foreach ((array)$attachments as $key => $attachment)
707 707
 					{
708
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
708
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
709 709
 						$attachmentNames .= $attachment['name']."\n";
710
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
710
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
711 711
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
712
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
712
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
713 713
 					}
714 714
 				}
715 715
 			}
@@ -724,38 +724,38 @@  discard block
 block discarded – undo
724 724
 		// now set the body
725 725
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
726 726
 		{
727
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
727
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
728 728
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
729
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
729
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
730 730
 		}
731 731
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
732 732
 		{
733
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
733
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
734 734
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
735
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
735
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
736 736
 		}
737 737
 		//advanced debugging
738 738
 		// Horde SMTP Class uses utf-8 by default.
739 739
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
740
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
740
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
741 741
 
742 742
 		// set a higher timeout for big messages
743 743
 		@set_time_limit(120);
744
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
744
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
745 745
 		// send
746 746
 		$send = true;
747 747
 		try {
748 748
 			$mailObject->Send();
749 749
 		}
750
-		catch(Exception $e) {
751
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
750
+		catch (Exception $e) {
751
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
752 752
 			$send = false;
753 753
 		}
754 754
 
755
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
755
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
756 756
 		{
757 757
 			$uid = $smartdata->source->itemid;
758
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
758
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
759 759
 			$this->splitID($smartdata->source->folderid, $account, $folder);
760 760
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
761 761
 			$this->mail->reopen($folder);
@@ -763,90 +763,90 @@  discard block
 block discarded – undo
763 763
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
764 764
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
765 765
 			{
766
-				$this->mail->deleteMessages(array($uid),$folder);
766
+				$this->mail->deleteMessages(array($uid), $folder);
767 767
 			} else {
768
-				$this->mail->flagMessages("answered", array($uid),$folder);
769
-				if ($smartdata_task== "forward")
768
+				$this->mail->flagMessages("answered", array($uid), $folder);
769
+				if ($smartdata_task == "forward")
770 770
 				{
771
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
771
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
772 772
 				}
773 773
 			}
774 774
 		}
775 775
 
776
-		$asf = ($send ? true:false); // initalize accordingly
777
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
776
+		$asf = ($send ? true : false); // initalize accordingly
777
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
778 778
 		{
779 779
 			$asf = false;
780 780
 			$sentFolder = $this->mail->getSentFolder();
781 781
 			if ($this->_sentID) {
782 782
 				$folderArray[] = $this->_sentID;
783 783
 			}
784
-			else if(isset($sentFolder) && $sentFolder != 'none')
784
+			else if (isset($sentFolder) && $sentFolder != 'none')
785 785
 			{
786 786
 				$folderArray[] = $sentFolder;
787 787
 			}
788 788
 			// No Sent folder set, try defaults
789 789
 			else
790 790
 			{
791
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
791
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
792 792
 				// we dont try guessing
793 793
 				$asf = true;
794 794
 			}
795 795
 			if (count($folderArray) > 0) {
796
-				foreach((array)$bccMailAddr as $address) {
797
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
798
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
796
+				foreach ((array)$bccMailAddr as $address) {
797
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
798
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
799 799
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
800 800
 					}
801 801
 				}
802 802
 				//$BCCmail='';
803
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
803
+				if (count($mailAddr) > 0) $mailObject->forceBccHeader();
804 804
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
805
-				foreach($folderArray as $folderName) {
806
-					if($this->mail->isSentFolder($folderName)) {
805
+				foreach ($folderArray as $folderName) {
806
+					if ($this->mail->isSentFolder($folderName)) {
807 807
 						$flags = '\\Seen';
808
-					} elseif($this->mail->isDraftFolder($folderName)) {
808
+					} elseif ($this->mail->isDraftFolder($folderName)) {
809 809
 						$flags = '\\Draft';
810 810
 					} else {
811 811
 						$flags = '';
812 812
 					}
813 813
 					$asf = true;
814 814
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
815
-					$this->mail->openConnection(self::$profileID,false);
815
+					$this->mail->openConnection(self::$profileID, false);
816 816
 					if ($this->mail->folderExists($folderName)) {
817 817
 						try
818 818
 						{
819
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
819
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
820 820
 									$flags);
821 821
 						}
822 822
 						catch (Api\Exception\WrongUserinput $e)
823 823
 						{
824 824
 							//$asf = false;
825
-							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()));
825
+							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()));
826 826
 						}
827 827
 					}
828 828
 					else
829 829
 					{
830 830
 						//$asf = false;
831
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
831
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
832 832
 					}
833
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
833
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
834 834
 				}
835 835
 				//$this->mail->closeConnection();
836 836
 			}
837 837
 		}
838 838
 
839
-		$this->debugLevel=0;
839
+		$this->debugLevel = 0;
840 840
 
841 841
 		if ($send && $asf)
842 842
 		{
843
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
843
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
844 844
 			return true;
845 845
 		}
846 846
 		else
847 847
 		{
848
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
849
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
848
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
849
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
850 850
 		}
851 851
 	}
852 852
 
@@ -864,43 +864,43 @@  discard block
 block discarded – undo
864 864
 	public function GetMessage($folderid, $id, $contentparameters)
865 865
 	{
866 866
 		//$this->debugLevel=4;
867
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
867
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
868 868
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
869 869
 		$mimesupport = $contentparameters->GetMimeSupport();
870
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
870
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
871 871
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
872 872
 
873 873
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
874 874
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
875 875
 
876 876
 		//$this->debugLevel=4;
877
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
878
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
877
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
878
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
879 879
 		$account = $_folderName = $xid = null;
880
-		$this->splitID($folderid,$account,$_folderName,$xid);
880
+		$this->splitID($folderid, $account, $_folderName, $xid);
881 881
 		$this->mail->reopen($_folderName);
882
-		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
882
+		$messages = $this->fetchMessages($folderid, NULL, $id, true); // true: return all headers
883 883
 		$headers = $messages[$id];
884
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
884
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($headers));
885 885
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
886 886
 		if ($headers)
887 887
 		{
888
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($headers));
888
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($headers));
889 889
 			// initialize the object
890 890
 			$output = new SyncMail();
891 891
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
892 892
 			// simple style
893 893
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
894
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
894
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
895 895
 
896 896
 			if ($bodypreference === false) {
897
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
898
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
897
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
898
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
899 899
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
900
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
900
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
901 901
 				// remove all other html
902 902
 				$body = strip_tags($raw_body);
903
-				if(strlen($body) > $truncsize) {
903
+				if (strlen($body) > $truncsize) {
904 904
 					$body = Utils::Utf8_truncate($body, $truncsize);
905 905
 					$output->bodytruncated = 1;
906 906
 				}
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
 			else // style with bodypreferences
915 915
 			{
916 916
 				//Select body type preference
917
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
917
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
918 918
 				if ($bodypreference !== false) {
919 919
 					// bodypreference can occur multiple times
920 920
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -928,12 +928,12 @@  discard block
 block discarded – undo
928 928
 					}
929 929
 */
930 930
 				}
931
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
931
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
932 932
 				// set the protocoll class
933 933
 				$output->asbody = new SyncBaseBody();
934 934
 
935 935
 				// return full mime-message without any (charset) conversation directly as stream
936
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
936
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)
937 937
 				{
938 938
 					//SYNC_BODYPREFERENCE_MIME
939 939
 					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
@@ -942,58 +942,58 @@  discard block
 block discarded – undo
942 942
 					fseek($stream, 0, SEEK_SET);
943 943
 					$output->asbody->data = $stream;
944 944
 					$output->asbody->estimatedDataSize = $fstat['size'];
945
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
945
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
946 946
 				}
947 947
 				else
948 948
 				{
949 949
 					// fetch the body (try to gather data only once)
950
-					$css ='';
951
-					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
952
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
953
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
955
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
950
+					$css = '';
951
+					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
952
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
953
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
954
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
955
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
956 956
 						// may be html
957
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
957
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
958 958
 						$css = $this->mail->getStyles($bodyStruct);
959
-						$output->nativebodytype=2;
959
+						$output->nativebodytype = 2;
960 960
 					} else {
961 961
 						// plain text Message
962
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
963
-						$output->nativebodytype=1;
964
-						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
965
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
966
-						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
967
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
962
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
963
+						$output->nativebodytype = 1;
964
+						$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
965
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
966
+						$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
967
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
968 968
 					}
969 969
 					// whatever format decode (using the correct encoding)
970
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
970
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
971 971
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
972 972
 					// prepare plaintextbody
973
-					$plainBody='';
973
+					$plainBody = '';
974 974
 					if ($output->nativebodytype == 2)
975 975
 					{
976
-						$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
977
-						if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
976
+						$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
977
+						if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
978 978
 						{
979 979
 							$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
980 980
 						}
981 981
 						else
982 982
 						{
983
-							$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
983
+							$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
984 984
 						}
985 985
 					}
986 986
 					//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
987
-					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
987
+					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
988 988
 					// remove all other html
989
-					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
989
+					$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
990 990
 					$plainBody = strip_tags($plainBody);
991
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
991
+					if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
992 992
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
993 993
 
994
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
994
+					if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
995 995
 					{
996
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
996
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
997 997
 						// Send HTML if requested and native type was html
998 998
 						$output->asbody->type = 2;
999 999
 						$htmlbody = '<html>'.
@@ -1003,23 +1003,23 @@  discard block
 block discarded – undo
1003 1003
 							$css.
1004 1004
 							'</head>'.
1005 1005
 							'<body>';
1006
-						if ($output->nativebodytype==2)
1006
+						if ($output->nativebodytype == 2)
1007 1007
 						{
1008
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
1008
+							if ($css) Api\Mail\Html::replaceTagsCompletley($body, 'style');
1009 1009
 							// as we fetch html, and body is HTML, we may not need to handle this
1010 1010
 							$htmlbody .= $body;
1011 1011
 						}
1012 1012
 						else
1013 1013
 						{
1014 1014
 							// html requested but got only plaintext, so fake html
1015
-							$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
1015
+							$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
1016 1016
 						}
1017 1017
 						$htmlbody .= '</body>'.
1018 1018
 								'</html>';
1019 1019
 
1020
-						if(isset($truncsize) && strlen($htmlbody) > $truncsize)
1020
+						if (isset($truncsize) && strlen($htmlbody) > $truncsize)
1021 1021
 						{
1022
-							$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
1022
+							$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
1023 1023
 							$output->asbody->truncated = 1;
1024 1024
 						}
1025 1025
 						// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 					else
1031 1031
 					{
1032 1032
 						// Send Plaintext as Fallback or if original body is plainttext
1033
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1033
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1034 1034
 						/* we use plainBody (set above) instead
1035 1035
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1036 1036
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 						*/
1041 1041
 						$output->asbody->type = 1;
1042 1042
 						$output->nativebodytype = 1;
1043
-						if(isset($truncsize) &&
1043
+						if (isset($truncsize) &&
1044 1044
 							strlen($plainBody) > $truncsize)
1045 1045
 						{
1046 1046
 							$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
 				}
1060 1060
 			}
1061 1061
 			// end AS12 Stuff
1062
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1062
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1063 1063
 			$output->read = $headers["flags"];
1064 1064
 
1065 1065
 			$output->flag = new SyncMailFlags();
@@ -1079,9 +1079,8 @@  discard block
 block discarded – undo
1079 1079
 				$output->lastverexecuted = AS_FORWARD;
1080 1080
 			}
1081 1081
 			$output->subject = $headers['subject'];
1082
-			$output->importance = $headers['priority'] > 3 ? 0 :
1083
-				($headers['priority'] < 3 ? 2 : 1) ;
1084
-			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1082
+			$output->importance = $headers['priority'] > 3 ? 0 : ($headers['priority'] < 3 ? 2 : 1);
1083
+			$output->datereceived = $this->mail->_strtotime($headers['date'], 'ts', true);
1085 1084
 			$output->to = $headers['to_address'];
1086 1085
 			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1087 1086
 			$output->from = $headers['sender_address'];
@@ -1089,8 +1088,8 @@  discard block
 block discarded – undo
1089 1088
 			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1090 1089
 
1091 1090
 			$output->messageclass = "IPM.Note";
1092
-			if (stripos($headers['mimetype'],'multipart')!== false &&
1093
-				stripos($headers['mimetype'],'signed')!== false)
1091
+			if (stripos($headers['mimetype'], 'multipart') !== false &&
1092
+				stripos($headers['mimetype'], 'signed') !== false)
1094 1093
 			{
1095 1094
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1096 1095
 			}
@@ -1099,20 +1098,20 @@  discard block
 block discarded – undo
1099 1098
 			}
1100 1099
 
1101 1100
 			// start handle Attachments (include text/calendar multipart alternative)
1102
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1101
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1103 1102
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1104
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1103
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1105 1104
 			{
1106
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1105
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1107 1106
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1108 1107
 				foreach ($attachments as $key => $attach)
1109 1108
 				{
1110
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1109
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1111 1110
 
1112 1111
 					// pass meeting requests to calendar plugin
1113 1112
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1114 1113
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1115
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1114
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1116 1115
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1117 1116
 					{
1118 1117
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1122,7 +1121,7 @@  discard block
 block discarded – undo
1122 1121
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1123 1122
 						//$output->messageclass = "IPM.Schedule.Meeting";
1124 1123
 						unset($attachment);
1125
-						continue;	// do NOT add attachment as attachment
1124
+						continue; // do NOT add attachment as attachment
1126 1125
 					}
1127 1126
 					if (Request::GetProtocolVersion() >= 12.0) {
1128 1127
 						$attachment = new SyncBaseAttachment();
@@ -1130,33 +1129,33 @@  discard block
 block discarded – undo
1130 1129
 							$output->asattachments = array();
1131 1130
 						$attachment->estimatedDataSize = $attach['size'];
1132 1131
 						$attachment->method = 1;
1133
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1132
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1134 1133
 					} else {
1135 1134
 						$attachment = new SyncAttachment();
1136 1135
 						if (!isset($output->attachments) || !is_array($output->attachments))
1137 1136
 							$output->attachments = array();
1138 1137
 						$attachment->attsize = $attach['size'];
1139 1138
 						$attachment->attmethod = 1;
1140
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1139
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1141 1140
 					}
1142 1141
 
1143 1142
 					$attachment->displayname = $attach['name'];
1144 1143
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1145 1144
 
1146
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1145
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1147 1146
 					//$attachment->isinline=0; // if not inline, do not use isinline
1148
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1147
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1149 1148
 					{
1150 1149
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1151 1150
 						{
1152 1151
 							$attachment->isinline = true;
1153 1152
 						}
1154 1153
 						if (Request::GetProtocolVersion() >= 12.0) {
1155
-							$attachment->method=1;
1156
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1154
+							$attachment->method = 1;
1155
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1157 1156
 						} else {
1158
-							$attachment->attmethod=6;
1159
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1157
+							$attachment->attmethod = 6;
1158
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1160 1159
 						}
1161 1160
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1162 1161
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1177,7 +1176,7 @@  discard block
 block discarded – undo
1177 1176
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1178 1177
             $output->internetcpid = INTERNET_CPID_UTF8;
1179 1178
 
1180
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1179
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1181 1180
 //$this->debugLevel=0;
1182 1181
 			return $output;
1183 1182
 		}
@@ -1200,30 +1199,30 @@  discard block
 block discarded – undo
1200 1199
 	{
1201 1200
 		if (!class_exists('calendar_zpush'))
1202 1201
 		{
1203
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1202
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1204 1203
 			return null;
1205 1204
 		}
1206 1205
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1207 1206
 		{
1208
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1207
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1209 1208
 			return false;
1210 1209
 		}
1211 1210
 		$ret = false;
1212
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1211
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1213 1212
 		{
1214 1213
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1215
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1214
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1216 1215
 			{
1217
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1216
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1218 1217
 
1219 1218
 				// calling backend again with iCal attachment, to let calendar add the event
1220 1219
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1221
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1220
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1222 1221
 					$response);
1223 1222
 				break;
1224 1223
 			}
1225 1224
 		}
1226
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1225
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1227 1226
 		return $ret;
1228 1227
 	}
1229 1228
 
@@ -1237,9 +1236,9 @@  discard block
 block discarded – undo
1237 1236
      * @param string $attname - should contain (folder)id
1238 1237
 	 * @return SyncItemOperationsAttachment-object
1239 1238
 	 */
1240
-	function GetAttachmentData($fid,$attname) {
1241
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1242
-		return $this->_GetAttachmentData($fid,$attname);
1239
+	function GetAttachmentData($fid, $attname) {
1240
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1241
+		return $this->_GetAttachmentData($fid, $attname);
1243 1242
 	}
1244 1243
 
1245 1244
 	/**
@@ -1252,9 +1251,9 @@  discard block
 block discarded – undo
1252 1251
      * @param string $attname - should contain (folder)id
1253 1252
 	 * @return SyncItemOperationsAttachment-object
1254 1253
 	 */
1255
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1256
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1257
-		return $this->_GetAttachmentData($fid,$attname);
1254
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1255
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1256
+		return $this->_GetAttachmentData($fid, $attname);
1258 1257
 	}
1259 1258
 
1260 1259
 	/**
@@ -1266,23 +1265,23 @@  discard block
 block discarded – undo
1266 1265
      * @param string $attname - should contain (folder)id
1267 1266
 	 * @return SyncItemOperationsAttachment-object
1268 1267
 	 */
1269
-	private function _GetAttachmentData($fid,$attname)
1268
+	private function _GetAttachmentData($fid, $attname)
1270 1269
 	{
1271
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1270
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1272 1271
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1273 1272
 		list($folderid, $id, $part) = explode(":", $attname);
1274 1273
 
1275 1274
 		$this->splitID($folderid, $account, $folder);
1276 1275
 
1277
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1276
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1278 1277
 
1279 1278
 		$this->mail->reopen($folder);
1280
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1279
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1281 1280
 		$SIOattachment = new SyncItemOperationsAttachment();
1282
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1281
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1283 1282
 		$SIOattachment->data = $attachment['attachment'];
1284 1283
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1285
-		if (isset($attachment['type']) )
1284
+		if (isset($attachment['type']))
1286 1285
 			$SIOattachment->contenttype = $attachment['type'];
1287 1286
 
1288 1287
 		unset($attachment);
@@ -1325,17 +1324,17 @@  discard block
 block discarded – undo
1325 1324
 	 */
1326 1325
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1327 1326
 	{
1328
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1327
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1329 1328
 		//unset($folderid, $id, $message, $contentParameters);
1330 1329
 		$account = $folder = null;
1331 1330
 		$this->splitID($folderid, $account, $folder);
1332 1331
 		if (isset($message->flag)) {
1333 1332
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1334
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1335
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1333
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1334
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1336 1335
 			} else {
1337
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1338
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1336
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1337
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1339 1338
 			}
1340 1339
 		}
1341 1340
 		return $this->StatMessage($folderid, $id);
@@ -1357,23 +1356,23 @@  discard block
 block discarded – undo
1357 1356
 	 */
1358 1357
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1359 1358
 	{
1360
-		unset($contentParameters);	// not used, but required by function signature
1359
+		unset($contentParameters); // not used, but required by function signature
1361 1360
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1362 1361
 		$account = $srcFolder = $destFolder = null;
1363 1362
 		$this->splitID($folderid, $account, $srcFolder);
1364 1363
 		$this->splitID($newfolderid, $account, $destFolder);
1365 1364
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1366
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1365
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1367 1366
 		$this->mail->reopen($destFolder);
1368 1367
 		$status = $this->mail->getFolderStatus($destFolder);
1369 1368
 		$uidNext = $status['uidnext'];
1370 1369
 		$this->mail->reopen($srcFolder);
1371 1370
 
1372 1371
 		// move message
1373
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1374
-		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
1372
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1373
+		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
1375 1374
 		// return the new id "as string"
1376
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1375
+		return ($rv === true ? $uidNext : $rv[$id])."";
1377 1376
 	}
1378 1377
 
1379 1378
 	/**
@@ -1381,7 +1380,7 @@  discard block
 block discarded – undo
1381 1380
 	 *
1382 1381
 	 *  @param int $cutoffdate =null timestamp with cutoffdate, default 12 weeks
1383 1382
 	 */
1384
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1383
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1385 1384
 	{
1386 1385
 		if ($cutoffdate > 0)
1387 1386
 		{
@@ -1394,14 +1393,14 @@  discard block
 block discarded – undo
1394 1393
 			{
1395 1394
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1396 1395
 			}
1397
-			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1398
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1396
+			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now', 'ts') - (3600 * 24 * $maximumSyncRangeInDays) : null);
1397
+			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1399 1398
 		}
1400 1399
 		try {
1401 1400
 			return $this->fetchMessages($folderid, $cutoffdate);
1402 1401
 		} catch (Exception $e)
1403 1402
 		{
1404
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details?$e->details:''));
1403
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details ? $e->details : ''));
1405 1404
 			return array();
1406 1405
 		}
1407 1406
 	}
@@ -1419,11 +1418,11 @@  discard block
 block discarded – undo
1419 1418
 	 * @param boolean $return_all_headers =false true: additinal contain all headers eg. "subject"
1420 1419
 	 * @return array uid => array StatMessage($folderid, $_id)
1421 1420
 	 */
1422
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL, $return_all_headers=false)
1421
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL, $return_all_headers = false)
1423 1422
 	{
1424 1423
 		static $headers = array();
1425 1424
 
1426
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1425
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1427 1426
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1428 1427
 		$rv_messages = array();
1429 1428
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1434,64 +1433,64 @@  discard block
 block discarded – undo
1434 1433
 		}
1435 1434
 		else
1436 1435
 		{
1437
-			$headers = array();	// clear cache to not use too much memory
1436
+			$headers = array(); // clear cache to not use too much memory
1438 1437
 
1439
-			if ($this->debugLevel>1) $starttime = microtime (true);
1438
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1440 1439
 			$this->_connect($this->account);
1441
-			if ($this->debugLevel>1)
1440
+			if ($this->debugLevel > 1)
1442 1441
 			{
1443 1442
 				$endtime = microtime(true) - $starttime;
1444
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1443
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1445 1444
 			}
1446 1445
 			$messagelist = $_filter = array();
1447 1446
 			// if not connected, any further action must fail
1448
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1449
-			if ($this->debugLevel>1) $starttime = microtime (true);
1447
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1448
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1450 1449
 			$account = $_folderName = $id = null;
1451
-			$this->splitID($folderid,$account,$_folderName,$id);
1452
-			if ($this->debugLevel>1)
1450
+			$this->splitID($folderid, $account, $_folderName, $id);
1451
+			if ($this->debugLevel > 1)
1453 1452
 			{
1454 1453
 				$endtime = microtime(true) - $starttime;
1455
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1454
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1456 1455
 			}
1457
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1458
-			if ($this->debugLevel>1) $starttime = microtime (true);
1459
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1460
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1461
-			if ($this->debugLevel>1)
1456
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1457
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1458
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1459
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1460
+			if ($this->debugLevel > 1)
1462 1461
 			{
1463 1462
 				$endtime = microtime(true) - $starttime;
1464
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1463
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1465 1464
 			}
1466 1465
 		}
1467
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1466
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1468 1467
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1469 1468
 		$messagelist = array();
1470
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1469
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1471 1470
 		//if ($_returnModHash) $messageFolderHash = array();
1472 1471
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1473 1472
 		{
1474
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1473
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1475 1474
 			$headers[$vars['uid']] = $vars;
1476
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1475
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1477 1476
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1478 1477
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1479
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1478
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1480 1479
 			$mess = $return_all_headers ? $vars : array();
1481 1480
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1482 1481
 			$mess["id"] = $vars['uid'];
1483 1482
 			// 'seen' aka 'read' is the only flag we want to know about
1484 1483
 			$mess["flags"] = 0;
1485 1484
 			// outlook supports additional flags, set them to 0
1486
-			if($vars["seen"]) $mess["flags"] = 1;
1487
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1485
+			if ($vars["seen"]) $mess["flags"] = 1;
1486
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1488 1487
 			$messagelist[$vars['uid']] = $mess;
1489 1488
 			unset($mess);
1490 1489
 		}
1491
-		if ($this->debugLevel>1)
1490
+		if ($this->debugLevel > 1)
1492 1491
 		{
1493 1492
 			$endtime = microtime(true) - $gstarttime;
1494
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1493
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1495 1494
 		}
1496 1495
 		return $messagelist;
1497 1496
 	}
@@ -1542,32 +1541,32 @@  discard block
 block discarded – undo
1542 1541
 	public function getSearchResultsMailbox($_searchquery)
1543 1542
 	{
1544 1543
 		//$this->debugLevel=1;
1545
-		$searchquery=$_searchquery->GetDataArray();
1544
+		$searchquery = $_searchquery->GetDataArray();
1546 1545
 		if (!is_array($searchquery)) return array();
1547
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1546
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1548 1547
 
1549 1548
 		if (isset($searchquery['searchrebuildresults'])) {
1550 1549
 			$rebuildresults = $searchquery['searchrebuildresults'];
1551 1550
 		} else {
1552 1551
 			$rebuildresults = false;
1553 1552
 		}
1554
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1553
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1555 1554
 
1556 1555
 		if (isset($searchquery['deeptraversal'])) {
1557 1556
 			$deeptraversal = $searchquery['deeptraversal'];
1558 1557
 		} else {
1559 1558
 			$deeptraversal = false;
1560 1559
 		}
1561
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1560
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1562 1561
 
1563 1562
 		if (isset($searchquery['searchrange'])) {
1564
-			$range = explode("-",$_searchquery->GetSearchRange());
1565
-			$start =$range[0] + 1;
1563
+			$range = explode("-", $_searchquery->GetSearchRange());
1564
+			$start = $range[0] + 1;
1566 1565
 			$limit = $range[1] - $range[0] + 1;
1567 1566
 		} else {
1568 1567
 			$range = false;
1569 1568
 		}
1570
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1569
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1571 1570
 
1572 1571
 		//foreach($searchquery['query'] as $k => $value) {
1573 1572
 		//	$query = $value;
@@ -1590,15 +1589,15 @@  discard block
 block discarded – undo
1590 1589
 		}
1591 1590
 		if (!$folderid)
1592 1591
 		{
1593
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1594
-			$folderid = $this->createID($account=0,$_folderName);
1592
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1593
+			$folderid = $this->createID($account = 0, $_folderName);
1595 1594
 		}
1596
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1597
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1595
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1596
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1598 1597
 		$this->_connect($account);
1599 1598
 		// this should not be needed ???
1600
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1601
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1599
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1600
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1602 1601
 						 'string'=> $searchText,
1603 1602
 						 'status'=>'any'
1604 1603
 						);
@@ -1613,22 +1612,22 @@  discard block
 block discarded – undo
1613 1612
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1614 1613
 		 */
1615 1614
 			$_filter['range'] = "BETWEEN";
1616
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1617
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1618
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1619
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1615
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1616
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1617
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1618
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1620 1619
 		}
1621 1620
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1622
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1623
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1621
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1622
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1624 1623
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1625
-		$list=array();
1624
+		$list = array();
1626 1625
 
1627 1626
 		$cnt = count($rv_messages['header']);
1628 1627
 		//$list['status'] = 1;
1629 1628
 		$list['searchtotal'] = $cnt;
1630 1629
 		$list["range"] = $_searchquery->GetSearchRange();
1631
-		foreach((array)$rv_messages['header'] as $i => $vars)
1630
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1632 1631
 		{
1633 1632
 			$list[] = array(
1634 1633
 				"class" => "Email",
@@ -1648,20 +1647,20 @@  discard block
 block discarded – undo
1648 1647
 	 * @param string $folder
1649 1648
 	 * @return string
1650 1649
 	 */
1651
-	private function getParentID($account,$folder)
1650
+	private function getParentID($account, $folder)
1652 1651
 	{
1653 1652
 		$this->_connect($account);
1654
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1653
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1655 1654
 
1656 1655
 		$mailFolder = $this->folders[$folder];
1657 1656
 		if (!isset($mailFolder)) return false;
1658
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1659
-		$parent = explode($delimiter,$folder);
1657
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1658
+		$parent = explode($delimiter, $folder);
1660 1659
 		array_pop($parent);
1661
-		$parent = implode($delimiter,$parent);
1660
+		$parent = implode($delimiter, $parent);
1662 1661
 
1663 1662
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1664
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1663
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1665 1664
 		return $id;
1666 1665
 	}
1667 1666
 
@@ -1681,48 +1680,48 @@  discard block
 block discarded – undo
1681 1680
 			$account = $folder = null;
1682 1681
 			$this->splitID($id, $account, $folder);
1683 1682
 		}
1684
-		catch(Exception $e) {
1685
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1686
-			return $folderObj=false;
1683
+		catch (Exception $e) {
1684
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1685
+			return $folderObj = false;
1687 1686
 		}
1688 1687
 		$this->_connect($account);
1689
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1688
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1690 1689
 
1691 1690
 		$mailFolder = $this->folders[$folder];
1692
-		if (!isset($mailFolder)) return $folderObj=false;
1691
+		if (!isset($mailFolder)) return $folderObj = false;
1693 1692
 
1694 1693
 		$folderObj = new SyncFolder();
1695 1694
 		$folderObj->serverid = $id;
1696
-		$folderObj->parentid = $this->getParentID($account,$folder);
1695
+		$folderObj->parentid = $this->getParentID($account, $folder);
1697 1696
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1698
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1697
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1699 1698
 		// get folder-type
1700
-		foreach($this->folders as $inbox => $mailFolder) break;
1699
+		foreach ($this->folders as $inbox => $mailFolder) break;
1701 1700
 		if ($folder == $inbox)
1702 1701
 		{
1703 1702
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1704 1703
 		}
1705
-		elseif($this->mail->isDraftFolder($folder, false, true))
1704
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1706 1705
 		{
1707 1706
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1708 1707
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1709 1708
 			$folderObj->parentid = 0; // required by devices
1710 1709
 		}
1711
-		elseif($this->mail->isTrashFolder($folder, false, true))
1710
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1712 1711
 		{
1713 1712
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1714 1713
 			$this->_wasteID = $folder;
1715 1714
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1716 1715
 			$folderObj->parentid = 0; // required by devices
1717 1716
 		}
1718
-		elseif($this->mail->isSentFolder($folder, false, true))
1717
+		elseif ($this->mail->isSentFolder($folder, false, true))
1719 1718
 		{
1720 1719
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1721 1720
 			$folderObj->parentid = 0; // required by devices
1722 1721
 			$this->_sentID = $folder;
1723 1722
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1724 1723
 		}
1725
-		elseif($this->mail->isOutbox($folder, false, true))
1724
+		elseif ($this->mail->isOutbox($folder, false, true))
1726 1725
 		{
1727 1726
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1728 1727
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1734,7 +1733,7 @@  discard block
 block discarded – undo
1734 1733
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1735 1734
 		}
1736 1735
 
1737
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1736
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1738 1737
 		return $folderObj;
1739 1738
 	}
1740 1739
 
@@ -1782,18 +1781,18 @@  discard block
 block discarded – undo
1782 1781
 
1783 1782
 		if ($type != 'mail') return false;
1784 1783
 
1785
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1784
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1786 1785
 
1787 1786
         $this->mail->reopen($folder);
1788 1787
 
1789
-		if (!($status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true)))
1788
+		if (!($status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true)))
1790 1789
 		{
1791
-            ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1790
+            ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1792 1791
             return false;
1793 1792
         }
1794
-		$syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1793
+		$syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1795 1794
 
1796
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1795
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1797 1796
 		return array();
1798 1797
 	}
1799 1798
 
@@ -1806,8 +1805,8 @@  discard block
 block discarded – undo
1806 1805
 	function GetWasteBasket()
1807 1806
 	{
1808 1807
 		$this->_connect($this->account);
1809
-		$id = $this->createID($account=0, $this->_wasteID);
1810
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1808
+		$id = $this->createID($account = 0, $this->_wasteID);
1809
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1811 1810
 		return $id;
1812 1811
 	}
1813 1812
 
@@ -1828,7 +1827,7 @@  discard block
 block discarded – undo
1828 1827
      */
1829 1828
     public function DeleteMessage($folderid, $id, $contentParameters)
1830 1829
 	{
1831
-		unset($contentParameters);	// not used, but required by function signature
1830
+		unset($contentParameters); // not used, but required by function signature
1832 1831
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1833 1832
 		/*
1834 1833
 		$this->imap_reopenFolder($folderid);
@@ -1839,7 +1838,7 @@  discard block
 block discarded – undo
1839 1838
 		// we may have to split folderid
1840 1839
 		$account = $folder = null;
1841 1840
 		$this->splitID($folderid, $account, $folder);
1842
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1841
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1843 1842
 		$_messageUID = (array)$id;
1844 1843
 
1845 1844
 		$this->_connect($this->account);
@@ -1851,9 +1850,9 @@  discard block
 block discarded – undo
1851 1850
 		catch (Api\Exception $e)
1852 1851
 		{
1853 1852
 			$error = $e->getMessage();
1854
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1853
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1855 1854
 			// if the server thinks the message does not exist report deletion as success
1856
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1855
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1857 1856
 			return false;
1858 1857
 		}
1859 1858
 
@@ -1887,15 +1886,15 @@  discard block
 block discarded – undo
1887 1886
      */
1888 1887
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1889 1888
 	{
1890
-		unset($contentParameters);	// not used, but required by function signature
1889
+		unset($contentParameters); // not used, but required by function signature
1891 1890
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1892 1891
 		$account = $folder = null;
1893 1892
 		$this->splitID($folderid, $account, $folder);
1894 1893
 
1895 1894
 		$_messageUID = (array)$id;
1896 1895
 		$this->_connect($this->account);
1897
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1898
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1896
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1897
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1899 1898
 
1900 1899
 		return $rv;
1901 1900
 	}
@@ -1913,7 +1912,7 @@  discard block
 block discarded – undo
1913 1912
 	 */
1914 1913
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1915 1914
 	{
1916
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type)");
1915
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type)");
1917 1916
 		$account = $parent_id = null;
1918 1917
 		$this->splitID($id, $account, $parentFolder, $app);
1919 1918
 
@@ -1930,17 +1929,17 @@  discard block
 block discarded – undo
1930 1929
 			$this->splitID($oldid, $account, $oldFolder, $app);
1931 1930
 			$old_hash = $this->folder2hash($account, $oldFolder);
1932 1931
 		}
1933
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.":{$action}Folder('$id'=>($parentFolder ($parent_id)), '$oldid'".($oldid?"=>($oldFolder ($old_hash))":'').", '$displayname', $type)");
1932
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.":{$action}Folder('$id'=>($parentFolder ($parent_id)), '$oldid'".($oldid ? "=>($oldFolder ($old_hash))" : '').", '$displayname', $type)");
1934 1933
 		$this->_connect($this->account);
1935 1934
 		try
1936 1935
 		{
1937
-			if ($action=='rename')
1936
+			if ($action == 'rename')
1938 1937
 			{
1939 1938
 				$newFolderName = $this->mail->renameFolder($oldFolder, $parentFolder, $displayname);
1940 1939
 			}
1941
-			elseif ($action=='create')
1940
+			elseif ($action == 'create')
1942 1941
 			{
1943
-				$error=null;
1942
+				$error = null;
1944 1943
 				$newFolderName = $this->mail->createFolder($parentFolder, $displayname, $error);
1945 1944
 			}
1946 1945
 		}
@@ -1952,7 +1951,7 @@  discard block
 block discarded – undo
1952 1951
 		$newHash = $this->rename_folder_hash($account, $old_hash, $newFolderName);
1953 1952
 		$newID = $this->createID($account, $newHash);
1954 1953
 
1955
-		ZLog::Write(LOGLEVEL_DEBUG,":{$action}Folder('$id'=>($parentFolder), '$oldid'".($oldid?"=>($oldFolder)":'').", '$displayname' => $newFolderName (ID:$newID))");
1954
+		ZLog::Write(LOGLEVEL_DEBUG, ":{$action}Folder('$id'=>($parentFolder), '$oldid'".($oldid ? "=>($oldFolder)" : '').", '$displayname' => $newFolderName (ID:$newID))");
1956 1955
 		return $this->StatFolder($newID);
1957 1956
 	}
1958 1957
 
@@ -1965,13 +1964,13 @@  discard block
 block discarded – undo
1965 1964
 	 * @throws StatusException              could throw specific SYNC_FSSTATUS_* exceptions
1966 1965
 	 * @return boolean true or false on error
1967 1966
 	 */
1968
-	public function DeleteFolder($id, $parentid=false)
1967
+	public function DeleteFolder($id, $parentid = false)
1969 1968
 	{
1970 1969
 		$account = $parent_id = $app = null;
1971 1970
 		$this->splitID($id, $account, $folder, $app);
1972 1971
 		$old_hash = $this->folder2hash($account, $folder);
1973 1972
 		if ($parentid) $this->splitID($parentid, $account, $parentfolder, $app);
1974
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."( '$id (-> $folder)','$parentid ".($parentid?'(->'.$parentfolder.')':'')."') called!");
1973
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."( '$id (-> $folder)','$parentid ".($parentid ? '(->'.$parentfolder.')' : '')."') called!");
1975 1974
 		$ret = $this->mail->deleteFolder($folder);
1976 1975
 		if ($ret) $newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##");
1977 1976
 		return $ret;
@@ -1993,8 +1992,8 @@  discard block
 block discarded – undo
1993 1992
 		$this->_connect($this->account);
1994 1993
 		$account = $folder = null;
1995 1994
 		$this->splitID($folderid, $account, $folder);
1996
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1997
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1995
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1996
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1998 1997
 
1999 1998
 		return $rv;
2000 1999
 	}
@@ -2008,17 +2007,17 @@  discard block
 block discarded – undo
2008 2007
 	 * @return string
2009 2008
 	 * @throws Api\Exception\WrongParameter
2010 2009
 	 */
2011
-	private function createID($account,$folder,$id=0)
2010
+	private function createID($account, $folder, $id = 0)
2012 2011
 	{
2013 2012
 		if (!is_numeric($folder))
2014 2013
 		{
2015 2014
 			// convert string $folder in numeric id
2016
-			$folder = $this->folder2hash($account,$f=$folder);
2015
+			$folder = $this->folder2hash($account, $f = $folder);
2017 2016
 		}
2018 2017
 
2019 2018
 		$str = $this->backend->createID($account, $folder, $id);
2020 2019
 
2021
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2020
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2022 2021
 
2023 2022
 		return $str;
2024 2023
 	}
@@ -2032,14 +2031,14 @@  discard block
 block discarded – undo
2032 2031
 	 * @param int &$appid=null (for mail=mail is to be expected)
2033 2032
 	 * @throws Api\Exception\WrongParameter
2034 2033
 	 */
2035
-	private function splitID($str,&$account,&$folder,&$appid=null)
2034
+	private function splitID($str, &$account, &$folder, &$appid = null)
2036 2035
 	{
2037 2036
 		$this->backend->splitID($str, $account, $folder, $appid);
2038 2037
 
2039 2038
 		// convert numeric folder-id back to folder name
2040
-		$folder = $this->hash2folder($account,$f=$folder);
2039
+		$folder = $this->hash2folder($account, $f = $folder);
2041 2040
 
2042
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)");
2041
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$appid)");
2043 2042
 	}
2044 2043
 
2045 2044
 	/**
@@ -2056,9 +2055,9 @@  discard block
 block discarded – undo
2056 2055
 	 * @param string $folder
2057 2056
 	 * @return int
2058 2057
 	 */
2059
-	private function folder2hash($account,$folder)
2058
+	private function folder2hash($account, $folder)
2060 2059
 	{
2061
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2060
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2062 2061
 
2063 2062
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2064 2063
 		{
@@ -2079,9 +2078,9 @@  discard block
 block discarded – undo
2079 2078
 	 * @param int $index
2080 2079
 	 * @return string NULL if not used so far
2081 2080
 	 */
2082
-	private function hash2folder($account,$index)
2081
+	private function hash2folder($account, $index)
2083 2082
 	{
2084
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2083
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2085 2084
 
2086 2085
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2087 2086
 	}
@@ -2137,9 +2136,9 @@  discard block
 block discarded – undo
2137 2136
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2138 2137
 				($hashes = file_get_contents($file)))
2139 2138
 			{
2140
-				$this->folderHashes = json_decode($hashes,true);
2139
+				$this->folderHashes = json_decode($hashes, true);
2141 2140
 				// fallback in case hashes have been serialized instead of being json-encoded
2142
-				if (json_last_error()!=JSON_ERROR_NONE)
2141
+				if (json_last_error() != JSON_ERROR_NONE)
2143 2142
 				{
2144 2143
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2145 2144
 					$this->folderHashes = unserialize($hashes);
@@ -2185,9 +2184,9 @@  discard block
 block discarded – undo
2185 2184
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2186 2185
 	 * @throws Api\Exception\AssertionFailed
2187 2186
 	 */
2188
-	private function hashFile($old=false)
2187
+	private function hashFile($old = false)
2189 2188
 	{
2190
-		if (!($dev_id=Request::GetDeviceID()))
2189
+		if (!($dev_id = Request::GetDeviceID()))
2191 2190
 		{
2192 2191
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2193 2192
 		}
Please login to merge, or discard this patch.
Braces   +607 added lines, -178 removed lines patch added patch discarded remove patch
@@ -84,29 +84,47 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function __construct(activesync_backend $backend)
86 86
 	{
87
-		if ($GLOBALS['egw_setup']) return;
87
+		if ($GLOBALS['egw_setup'])
88
+		{
89
+			return;
90
+		}
88 91
 
89 92
 		//$this->debugLevel=2;
90 93
 		$this->backend = $backend;
91 94
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
92 95
 		{
93
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
96
+			if ($this->debugLevel>1)
97
+			{
98
+				error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
99
+			}
94 100
 			// globals preferences add appname varname value
95 101
 			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
96 102
 			// save prefs
97 103
 			$GLOBALS['egw']->preferences->save_repository(true);
98 104
 		}
99
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
105
+		if ($this->debugLevel>1)
106
+		{
107
+			error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
108
+		}
100 109
 
101 110
 		if (is_null(self::$profileID))
102 111
 		{
103
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
112
+			if ($this->debugLevel>1)
113
+			{
114
+				error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
115
+			}
104 116
 			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
105
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
117
+			if ($this->debugLevel>1)
118
+			{
119
+				error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
120
+			}
106 121
 		}
107 122
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
108 123
 		{
109
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
124
+			if ($this->debugLevel>1)
125
+			{
126
+				error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
127
+			}
110 128
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
111 129
 			{
112 130
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -116,7 +134,10 @@  discard block
 block discarded – undo
116 134
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
117 135
 			}
118 136
 		}
119
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
137
+		if ($this->debugLevel>1)
138
+		{
139
+			error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
140
+		}
120 141
 
121 142
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
122 143
 		if (!isset($GLOBALS['egw_setup']))
@@ -129,7 +150,10 @@  discard block
 block discarded – undo
129 150
 				self::$profileID = Mail\Account::get_default_acc_id();
130 151
 			}
131 152
 		}
132
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
153
+		if ($this->debugLevel>0)
154
+		{
155
+			error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
156
+		}
133 157
 		//$this->debugLevel=0;
134 158
 	}
135 159
 
@@ -245,8 +269,14 @@  discard block
 block discarded – undo
245 269
 				$this->_connect(0,true);
246 270
 				$this->_disconnect();
247 271
 
248
-				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
249
-				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
272
+				if (!$this->_wasteID)
273
+				{
274
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
275
+				}
276
+				if (!$this->_sentID)
277
+				{
278
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
279
+				}
250 280
 			}
251 281
 			catch(Exception $e) {
252 282
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
@@ -268,8 +298,14 @@  discard block
 block discarded – undo
268 298
 	 */
269 299
 	private function _connect($account=0)
270 300
 	{
271
-		if (!$account) $account = self::$profileID ? self::$profileID : 0;
272
-		if ($this->mail && $this->account != $account) $this->_disconnect();
301
+		if (!$account)
302
+		{
303
+			$account = self::$profileID ? self::$profileID : 0;
304
+		}
305
+		if ($this->mail && $this->account != $account)
306
+		{
307
+			$this->_disconnect();
308
+		}
273 309
 
274 310
 		$this->_wasteID = false;
275 311
 		$this->_sentID = false;
@@ -280,12 +316,18 @@  discard block
 block discarded – undo
280 316
 			// todo: tell mail which account to use
281 317
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
282 318
 			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
283
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
319
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
320
+			{
321
+				self::$profileID = $this->mail->icServer->ImapServerId;
322
+			}
284 323
 		}
285 324
 		else
286 325
 		{
287 326
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
288
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
327
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
328
+			{
329
+				self::$profileID = $this->mail->icServer->ImapServerId;
330
+			}
289 331
 		}
290 332
 		$this->mail->openConnection(self::$profileID,false);
291 333
 
@@ -302,8 +344,14 @@  discard block
 block discarded – undo
302 344
 	 */
303 345
 	private function _disconnect()
304 346
 	{
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
306
-		if ($this->mail) $this->mail->closeConnection();
347
+		if ($this->debugLevel>0)
348
+		{
349
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
350
+		}
351
+		if ($this->mail)
352
+		{
353
+			$this->mail->closeConnection();
354
+		}
307 355
 
308 356
 		unset($this->mail);
309 357
 		unset($this->account);
@@ -318,24 +366,43 @@  discard block
 block discarded – undo
318 366
 	public function GetFolderList()
319 367
 	{
320 368
 		$folderlist = array();
321
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
369
+		if ($this->debugLevel>0)
370
+		{
371
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
372
+		}
322 373
 		/*foreach($available_accounts as $account)*/ $account = 0;
323 374
 		{
324 375
 			$this->_connect($account);
325
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
326
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
376
+			if (!isset($this->folders))
377
+			{
378
+				$this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
379
+			}
380
+			if ($this->debugLevel>1)
381
+			{
382
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
383
+			}
327 384
 
328
-			foreach ($this->folders as $folder => $folderObj) {
329
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
385
+			foreach ($this->folders as $folder => $folderObj)
386
+			{
387
+				if ($this->debugLevel>1)
388
+				{
389
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
390
+				}
330 391
 				$folderlist[] = $f = array(
331 392
 					'id'     => $this->createID($account,$folder),
332 393
 					'mod'    => $folderObj->shortDisplayName,
333 394
 					'parent' => $this->getParentID($account,$folder),
334 395
 				);
335
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
396
+				if ($this->debugLevel>1)
397
+				{
398
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
399
+				}
336 400
 			}
337 401
 		}
338
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
402
+		if ($this->debugLevel>0)
403
+		{
404
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
405
+		}
339 406
 
340 407
 		return $folderlist;
341 408
 	}
@@ -396,11 +463,17 @@  discard block
 block discarded – undo
396 463
 		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
397 464
 
398 465
    		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
399
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
466
+		if ($this->debugLevel>0)
467
+		{
468
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
469
+		}
400 470
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
401 471
 
402 472
 		// initialize our Mail
403
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
473
+		if (!isset($this->mail))
474
+		{
475
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
476
+		}
404 477
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
405 478
 		// use the standardIdentity
406 479
 		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
@@ -428,12 +501,18 @@  discard block
 block discarded – undo
428 501
 		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
429 502
 		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
430 503
 		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
431
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
504
+		if ($this->debugLevel>0)
505
+		{
506
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
507
+		}
432 508
 		$sigTextHtml = $beforeHtml.$sigText;
433 509
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
434 510
 
435 511
 		$force8bit=false;
436
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
512
+		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii')
513
+		{
514
+			$force8bit=true;
515
+		}
437 516
 		// initialize the new Api\Mailer object for sending
438 517
 		$mailObject = new Api\Mailer(self::$profileID);
439 518
 		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
@@ -444,22 +523,34 @@  discard block
 block discarded – undo
444 523
 
445 524
 		// prepare addressee list; moved the adding of addresses to the mailobject down
446 525
 		// to
447
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
448
-			if (!$addressObject->valid) continue;
526
+		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject)
527
+		{
528
+			if (!$addressObject->valid)
529
+			{
530
+				continue;
531
+			}
449 532
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
450 533
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
451 534
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
452 535
 		}
453 536
 		// CC
454
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
455
-			if (!$addressObject->valid) continue;
537
+		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject)
538
+		{
539
+			if (!$addressObject->valid)
540
+			{
541
+				continue;
542
+			}
456 543
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
457 544
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
458 545
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
459 546
 		}
460 547
 		// BCC
461
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
462
-			if (!$addressObject->valid) continue;
548
+		foreach($mailObject->getAddresses('bcc') as $addressObject)
549
+		{
550
+			if (!$addressObject->valid)
551
+			{
552
+				continue;
553
+			}
463 554
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
464 555
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
465 556
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
@@ -472,12 +563,14 @@  discard block
 block discarded – undo
472 563
 		$ContentType =$mailObject->getHeader('Content-Type');
473 564
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
474 565
 		// if the message is a multipart message, then we should use the sent body
475
-		if (preg_match("/multipart/i", $ContentType)) {
566
+		if (preg_match("/multipart/i", $ContentType))
567
+		{
476 568
 			$use_orgbody = true;
477 569
 		}
478 570
 
479 571
 		// save the original content-type header for the body part when forwarding
480
-		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
572
+		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody)
573
+		{
481 574
 			//continue; // ignore
482 575
 		}
483 576
 		// horde/egw_ mailer does everything as utf-8, the following should not be needed
@@ -486,7 +579,8 @@  discard block
 block discarded – undo
486 579
 		// if the message is a multipart message, then we should use the sent body
487 580
 		if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
488 581
 			((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
489
-			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
582
+			$k == "Content-Type" && preg_match("/multipart/i", $ContentType)))
583
+		{
490 584
 			$use_orgbody = true;
491 585
 		}
492 586
 		$Body =  $AltBody = "";
@@ -519,12 +613,19 @@  discard block
 block discarded – undo
519 613
 			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
520 614
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
521 615
 		}
522
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
523
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
616
+		if ($this->debugLevel>1 && $Body)
617
+		{
618
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
619
+		}
620
+		if ($this->debugLevel>1 && $AltBody)
621
+		{
622
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
623
+		}
524 624
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
525 625
 		// if this is a multipart message with a boundary, we must use the original body
526 626
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
527
-        if ($use_orgbody) {
627
+        if ($use_orgbody)
628
+        {
528 629
     	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
529 630
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
530 631
 			if (($cal_body = $mailObject->findBody('calendar')) &&
@@ -534,15 +635,20 @@  discard block
 block discarded – undo
534 635
 				{
535 636
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
536 637
 				}
537
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
638
+				if ($this->debugLevel)
639
+				{
640
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
641
+				}
538 642
 				$ClientSideMeetingRequest = true;
539 643
 			}
540 644
         }
541 645
 		// now handle the addressee list
542 646
 		$toCount = 0;
543 647
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
544
-		foreach((array)$toMailAddr as $address) {
545
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
648
+		foreach((array)$toMailAddr as $address)
649
+		{
650
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
651
+			{
546 652
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
547 653
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
548 654
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
@@ -556,19 +662,29 @@  discard block
 block discarded – undo
556 662
 			}
557 663
 		}
558 664
 		$ccCount = 0;
559
-		foreach((array)$ccMailAddr as $address) {
560
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
665
+		foreach((array)$ccMailAddr as $address)
666
+		{
667
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
668
+			{
561 669
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
562
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
670
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
671
+				{
672
+					continue;
673
+				}
563 674
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
564 675
 				$ccCount++;
565 676
 			}
566 677
 		}
567 678
 		$bccCount = 0;
568
-		foreach((array)$bccMailAddr as $address) {
569
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
679
+		foreach((array)$bccMailAddr as $address)
680
+		{
681
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
682
+			{
570 683
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
571
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
684
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
685
+				{
686
+					continue;
687
+				}
572 688
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
573 689
 				$bccCount++;
574 690
 			}
@@ -578,7 +694,10 @@  discard block
 block discarded – undo
578 694
 		{
579 695
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
580 696
 		}
581
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
697
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false)
698
+		{
699
+			return true;
700
+		}
582 701
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
583 702
 /*
584 703
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -601,10 +720,17 @@  discard block
 block discarded – undo
601 720
 			$this->mail->reopen($folder);
602 721
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
603 722
 			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
604
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
605
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
723
+			if ($this->debugLevel>3)
724
+			{
725
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
726
+			}
727
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
728
+		    {
606 729
 				// may be html
607
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
730
+				if ($this->debugLevel>0)
731
+				{
732
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
733
+				}
608 734
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
609 735
 				$isreply = true;
610 736
 			}
@@ -613,8 +739,12 @@  discard block
 block discarded – undo
613 739
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
614 740
 			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
615 741
 			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
616
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
617
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
742
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
743
+			{
744
+				if ($this->debugLevel>0)
745
+				{
746
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
747
+				}
618 748
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
619 749
 				$isreply = true;
620 750
 			}
@@ -622,7 +752,10 @@  discard block
 block discarded – undo
622 752
 			{
623 753
 				$isreply = true;
624 754
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
625
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
755
+				if ($this->debugLevel>0)
756
+				{
757
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
758
+				}
626 759
 			}
627 760
 		}
628 761
 
@@ -636,11 +769,17 @@  discard block
 block discarded – undo
636 769
 			(isset($smartdata->replacemime) && $smartdata->replacemime == false)))
637 770
 		{
638 771
 			//force the default for the forwarding -> asmail
639
-			if (is_array($preferencesArray)) {
772
+			if (is_array($preferencesArray))
773
+			{
640 774
 				if (!array_key_exists('message_forwarding',$preferencesArray)
641 775
 					|| !isset($preferencesArray['message_forwarding'])
642
-					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
643
-			} else {
776
+					|| empty($preferencesArray['message_forwarding']))
777
+				{
778
+					$preferencesArray['message_forwarding'] = 'asmail';
779
+				}
780
+			}
781
+			else
782
+			{
644 783
 				$preferencesArray['message_forwarding'] = 'asmail';
645 784
 			}
646 785
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
@@ -672,27 +811,44 @@  discard block
 block discarded – undo
672 811
 				$this->mail->reopen($folder);
673 812
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
674 813
 				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
675
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
676
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
814
+				if ($this->debugLevel>0)
815
+				{
816
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
817
+				}
818
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
819
+				{
677 820
 					// may be html
678
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
821
+					if ($this->debugLevel>0)
822
+					{
823
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
824
+					}
679 825
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
680 826
 					$isforward = true;
681 827
 				}
682 828
 				// plain text Message part
683
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
829
+				if ($this->debugLevel>0)
830
+				{
831
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
832
+				}
684 833
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
685 834
 				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
686 835
 				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
687
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
688
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
836
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
837
+				{
838
+					if ($this->debugLevel>0)
839
+					{
840
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
841
+					}
689 842
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
690 843
 					$isforward = true;
691 844
 				}
692 845
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
693 846
 				{
694 847
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
695
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
848
+					if ($this->debugLevel>0)
849
+					{
850
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
851
+					}
696 852
 					$isforward = true;
697 853
 				}
698 854
 				// get all the attachments and add them too.
@@ -705,7 +861,10 @@  discard block
 block discarded – undo
705 861
 					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
706 862
 					foreach((array)$attachments as $key => $attachment)
707 863
 					{
708
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
864
+						if ($this->debugLevel>0)
865
+						{
866
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
867
+						}
709 868
 						$attachmentNames .= $attachment['name']."\n";
710 869
 						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
711 870
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
@@ -724,20 +883,29 @@  discard block
 block discarded – undo
724 883
 		// now set the body
725 884
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
726 885
 		{
727
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
886
+			if ($this->debugLevel>1)
887
+			{
888
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
889
+			}
728 890
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
729 891
 			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
730 892
 		}
731 893
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
732 894
 		{
733
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
895
+			if ($this->debugLevel>1)
896
+			{
897
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
898
+			}
734 899
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
735 900
 			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
736 901
 		}
737 902
 		//advanced debugging
738 903
 		// Horde SMTP Class uses utf-8 by default.
739 904
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
740
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
905
+		if ($this->debugLevel>2)
906
+		{
907
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
908
+		}
741 909
 
742 910
 		// set a higher timeout for big messages
743 911
 		@set_time_limit(120);
@@ -764,7 +932,9 @@  discard block
 block discarded – undo
764 932
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
765 933
 			{
766 934
 				$this->mail->deleteMessages(array($uid),$folder);
767
-			} else {
935
+			}
936
+			else
937
+			{
768 938
 				$this->mail->flagMessages("answered", array($uid),$folder);
769 939
 				if ($smartdata_task== "forward")
770 940
 				{
@@ -778,7 +948,8 @@  discard block
 block discarded – undo
778 948
 		{
779 949
 			$asf = false;
780 950
 			$sentFolder = $this->mail->getSentFolder();
781
-			if ($this->_sentID) {
951
+			if ($this->_sentID)
952
+			{
782 953
 				$folderArray[] = $this->_sentID;
783 954
 			}
784 955
 			else if(isset($sentFolder) && $sentFolder != 'none')
@@ -792,28 +963,41 @@  discard block
 block discarded – undo
792 963
 				// we dont try guessing
793 964
 				$asf = true;
794 965
 			}
795
-			if (count($folderArray) > 0) {
796
-				foreach((array)$bccMailAddr as $address) {
797
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
966
+			if (count($folderArray) > 0)
967
+			{
968
+				foreach((array)$bccMailAddr as $address)
969
+				{
970
+					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
971
+					{
798 972
 						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
799 973
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
800 974
 					}
801 975
 				}
802 976
 				//$BCCmail='';
803
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
977
+				if (count($mailAddr)>0)
978
+				{
979
+					$mailObject->forceBccHeader();
980
+				}
804 981
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
805
-				foreach($folderArray as $folderName) {
806
-					if($this->mail->isSentFolder($folderName)) {
982
+				foreach($folderArray as $folderName)
983
+				{
984
+					if($this->mail->isSentFolder($folderName))
985
+					{
807 986
 						$flags = '\\Seen';
808
-					} elseif($this->mail->isDraftFolder($folderName)) {
987
+					}
988
+					elseif($this->mail->isDraftFolder($folderName))
989
+					{
809 990
 						$flags = '\\Draft';
810
-					} else {
991
+					}
992
+					else
993
+					{
811 994
 						$flags = '';
812 995
 					}
813 996
 					$asf = true;
814 997
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
815 998
 					$this->mail->openConnection(self::$profileID,false);
816
-					if ($this->mail->folderExists($folderName)) {
999
+					if ($this->mail->folderExists($folderName))
1000
+					{
817 1001
 						try
818 1002
 						{
819 1003
 							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
@@ -871,17 +1055,26 @@  discard block
 block discarded – undo
871 1055
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
872 1056
 
873 1057
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
874
-		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
1058
+		if (!$mimesupport && ($key = array_search('4', $bodypreference)))
1059
+		{
1060
+			unset($bodypreference[$key]);
1061
+		}
875 1062
 
876 1063
 		//$this->debugLevel=4;
877
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1064
+		if (!isset($this->mail))
1065
+		{
1066
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1067
+		}
878 1068
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
879 1069
 		$account = $_folderName = $xid = null;
880 1070
 		$this->splitID($folderid,$account,$_folderName,$xid);
881 1071
 		$this->mail->reopen($_folderName);
882 1072
 		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
883 1073
 		$headers = $messages[$id];
884
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1074
+		if ($this->debugLevel>3)
1075
+		{
1076
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1077
+		}
885 1078
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
886 1079
 		if ($headers)
887 1080
 		{
@@ -891,16 +1084,25 @@  discard block
 block discarded – undo
891 1084
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
892 1085
 			// simple style
893 1086
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
894
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1087
+			if ($this->debugLevel>0)
1088
+			{
1089
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1090
+			}
895 1091
 
896
-			if ($bodypreference === false) {
1092
+			if ($bodypreference === false)
1093
+			{
897 1094
 				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
898 1095
 				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
899 1096
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
900
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
1097
+				if (stripos($raw_body,'<style')!==false)
1098
+				{
1099
+					$body = preg_replace("/<style.*?<\/style>/is", "", $raw_body);
1100
+				}
1101
+				// in case there is only a html part
901 1102
 				// remove all other html
902 1103
 				$body = strip_tags($raw_body);
903
-				if(strlen($body) > $truncsize) {
1104
+				if(strlen($body) > $truncsize)
1105
+				{
904 1106
 					$body = Utils::Utf8_truncate($body, $truncsize);
905 1107
 					$output->bodytruncated = 1;
906 1108
 				}
@@ -915,7 +1117,8 @@  discard block
 block discarded – undo
915 1117
 			{
916 1118
 				//Select body type preference
917 1119
 				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
918
-				if ($bodypreference !== false) {
1120
+				if ($bodypreference !== false)
1121
+				{
919 1122
 					// bodypreference can occur multiple times
920 1123
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
921 1124
 					$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -949,25 +1152,49 @@  discard block
 block discarded – undo
949 1152
 					// fetch the body (try to gather data only once)
950 1153
 					$css ='';
951 1154
 					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
952
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1155
+					if ($this->debugLevel>2)
1156
+					{
1157
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1158
+					}
953 1159
 					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
955
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
1160
+					if ($this->debugLevel>3)
1161
+					{
1162
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
1163
+					}
1164
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
1165
+					{
956 1166
 						// may be html
957
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1167
+						if ($this->debugLevel>0)
1168
+						{
1169
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1170
+						}
958 1171
 						$css = $this->mail->getStyles($bodyStruct);
959 1172
 						$output->nativebodytype=2;
960
-					} else {
1173
+					}
1174
+					else
1175
+					{
961 1176
 						// plain text Message
962
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1177
+						if ($this->debugLevel>0)
1178
+						{
1179
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1180
+						}
963 1181
 						$output->nativebodytype=1;
964 1182
 						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
965
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1183
+						if ($this->debugLevel>3)
1184
+						{
1185
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1186
+						}
966 1187
 						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
967
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1188
+						if ($this->debugLevel>3)
1189
+						{
1190
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1191
+						}
968 1192
 					}
969 1193
 					// whatever format decode (using the correct encoding)
970
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1194
+					if ($this->debugLevel>3)
1195
+					{
1196
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1197
+					}
971 1198
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
972 1199
 					// prepare plaintextbody
973 1200
 					$plainBody='';
@@ -988,12 +1215,18 @@  discard block
 block discarded – undo
988 1215
 					// remove all other html
989 1216
 					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
990 1217
 					$plainBody = strip_tags($plainBody);
991
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1218
+					if ($this->debugLevel>3 && $output->nativebodytype==1)
1219
+					{
1220
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1221
+					}
992 1222
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
993 1223
 
994
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
1224
+					if ($bpReturnType==2)
1225
+					{
1226
+						//SYNC_BODYPREFERENCE_HTML
995 1227
 					{
996 1228
 						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
1229
+					}
997 1230
 						// Send HTML if requested and native type was html
998 1231
 						$output->asbody->type = 2;
999 1232
 						$htmlbody = '<html>'.
@@ -1005,7 +1238,10 @@  discard block
 block discarded – undo
1005 1238
 							'<body>';
1006 1239
 						if ($output->nativebodytype==2)
1007 1240
 						{
1008
-							if ($css) Api\Mail\Html::replaceTagsCompletley($body,'style');
1241
+							if ($css)
1242
+							{
1243
+								Api\Mail\Html::replaceTagsCompletley($body,'style');
1244
+							}
1009 1245
 							// as we fetch html, and body is HTML, we may not need to handle this
1010 1246
 							$htmlbody .= $body;
1011 1247
 						}
@@ -1030,7 +1266,10 @@  discard block
 block discarded – undo
1030 1266
 					else
1031 1267
 					{
1032 1268
 						// Send Plaintext as Fallback or if original body is plainttext
1033
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1269
+						if ($this->debugLevel>0)
1270
+						{
1271
+							ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1272
+						}
1034 1273
 						/* we use plainBody (set above) instead
1035 1274
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1036 1275
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1067,7 +1306,9 @@  discard block
 block discarded – undo
1067 1306
 			{
1068 1307
 				$output->flag->flagstatus = 2;
1069 1308
 				//$output->flag->flagtype = "Flag for Follow up";
1070
-			} else {
1309
+			}
1310
+			else
1311
+			{
1071 1312
 				$output->flag->flagstatus = 0;
1072 1313
 			}
1073 1314
 			if ($headers['answered'])
@@ -1083,10 +1324,20 @@  discard block
 block discarded – undo
1083 1324
 				($headers['priority'] < 3 ? 2 : 1) ;
1084 1325
 			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1085 1326
 			$output->to = $headers['to_address'];
1086
-			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1327
+			if ($headers['to'])
1328
+			{
1329
+				$output->displayto = $headers['to_address'];
1330
+			}
1331
+			//$headers['FETCHED_HEADER']['to_name']
1087 1332
 			$output->from = $headers['sender_address'];
1088
-			if (isset($headers['cc_addresses']) && $headers['cc_addresses']) $output->cc = $headers['cc_addresses'];
1089
-			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1333
+			if (isset($headers['cc_addresses']) && $headers['cc_addresses'])
1334
+			{
1335
+				$output->cc = $headers['cc_addresses'];
1336
+			}
1337
+			if (isset($headers['reply_to_address']) && $headers['reply_to_address'])
1338
+			{
1339
+				$output->reply_to = $headers['reply_to_address'];
1340
+			}
1090 1341
 
1091 1342
 			$output->messageclass = "IPM.Note";
1092 1343
 			if (stripos($headers['mimetype'],'multipart')!== false &&
@@ -1094,7 +1345,8 @@  discard block
 block discarded – undo
1094 1345
 			{
1095 1346
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1096 1347
 			}
1097
-			if (Request::GetProtocolVersion() >= 12.0) {
1348
+			if (Request::GetProtocolVersion() >= 12.0)
1349
+			{
1098 1350
 				$output->contentclass = "urn:content-classes:message";
1099 1351
 			}
1100 1352
 
@@ -1107,7 +1359,10 @@  discard block
 block discarded – undo
1107 1359
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1108 1360
 				foreach ($attachments as $key => $attach)
1109 1361
 				{
1110
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1362
+					if ($this->debugLevel>0)
1363
+					{
1364
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1365
+					}
1111 1366
 
1112 1367
 					// pass meeting requests to calendar plugin
1113 1368
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
@@ -1124,17 +1379,24 @@  discard block
 block discarded – undo
1124 1379
 						unset($attachment);
1125 1380
 						continue;	// do NOT add attachment as attachment
1126 1381
 					}
1127
-					if (Request::GetProtocolVersion() >= 12.0) {
1382
+					if (Request::GetProtocolVersion() >= 12.0)
1383
+					{
1128 1384
 						$attachment = new SyncBaseAttachment();
1129 1385
 						if (!isset($output->asattachments) || !is_array($output->asattachments))
1130
-							$output->asattachments = array();
1386
+						{
1387
+													$output->asattachments = array();
1388
+						}
1131 1389
 						$attachment->estimatedDataSize = $attach['size'];
1132 1390
 						$attachment->method = 1;
1133 1391
 						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1134
-					} else {
1392
+					}
1393
+					else
1394
+					{
1135 1395
 						$attachment = new SyncAttachment();
1136 1396
 						if (!isset($output->attachments) || !is_array($output->attachments))
1137
-							$output->attachments = array();
1397
+						{
1398
+													$output->attachments = array();
1399
+						}
1138 1400
 						$attachment->attsize = $attach['size'];
1139 1401
 						$attachment->attmethod = 1;
1140 1402
 						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
@@ -1151,10 +1413,13 @@  discard block
 block discarded – undo
1151 1413
 						{
1152 1414
 							$attachment->isinline = true;
1153 1415
 						}
1154
-						if (Request::GetProtocolVersion() >= 12.0) {
1416
+						if (Request::GetProtocolVersion() >= 12.0)
1417
+						{
1155 1418
 							$attachment->method=1;
1156 1419
 							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1157
-						} else {
1420
+						}
1421
+						else
1422
+						{
1158 1423
 							$attachment->attmethod=6;
1159 1424
 							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1160 1425
 						}
@@ -1162,9 +1427,12 @@  discard block
 block discarded – undo
1162 1427
 						$attachment->contenttype = trim($attach['mimeType']);
1163 1428
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."'  ".$attachment->contentid);
1164 1429
 					}
1165
-					if (Request::GetProtocolVersion() >= 12.0) {
1430
+					if (Request::GetProtocolVersion() >= 12.0)
1431
+					{
1166 1432
 						array_push($output->asattachments, $attachment);
1167
-					} else {
1433
+					}
1434
+					else
1435
+					{
1168 1436
 						array_push($output->attachments, $attachment);
1169 1437
 					}
1170 1438
 					unset($attachment);
@@ -1177,8 +1445,11 @@  discard block
 block discarded – undo
1177 1445
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1178 1446
             $output->internetcpid = INTERNET_CPID_UTF8;
1179 1447
 
1180
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1181
-//$this->debugLevel=0;
1448
+			if ($this->debugLevel>3)
1449
+			{
1450
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1451
+			}
1452
+			//$this->debugLevel=0;
1182 1453
 			return $output;
1183 1454
 		}
1184 1455
 //$this->debugLevel=0;
@@ -1237,7 +1508,8 @@  discard block
 block discarded – undo
1237 1508
      * @param string $attname - should contain (folder)id
1238 1509
 	 * @return SyncItemOperationsAttachment-object
1239 1510
 	 */
1240
-	function GetAttachmentData($fid,$attname) {
1511
+	function GetAttachmentData($fid,$attname)
1512
+	{
1241 1513
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1242 1514
 		return $this->_GetAttachmentData($fid,$attname);
1243 1515
 	}
@@ -1252,7 +1524,8 @@  discard block
 block discarded – undo
1252 1524
      * @param string $attname - should contain (folder)id
1253 1525
 	 * @return SyncItemOperationsAttachment-object
1254 1526
 	 */
1255
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1527
+	function ItemOperationsGetAttachmentData($fid,$attname)
1528
+	{
1256 1529
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1257 1530
 		return $this->_GetAttachmentData($fid,$attname);
1258 1531
 	}
@@ -1274,7 +1547,10 @@  discard block
 block discarded – undo
1274 1547
 
1275 1548
 		$this->splitID($folderid, $account, $folder);
1276 1549
 
1277
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1550
+		if (!isset($this->mail))
1551
+		{
1552
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1553
+		}
1278 1554
 
1279 1555
 		$this->mail->reopen($folder);
1280 1556
 		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
@@ -1283,7 +1559,9 @@  discard block
 block discarded – undo
1283 1559
 		$SIOattachment->data = $attachment['attachment'];
1284 1560
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1285 1561
 		if (isset($attachment['type']) )
1286
-			$SIOattachment->contenttype = $attachment['type'];
1562
+		{
1563
+					$SIOattachment->contenttype = $attachment['type'];
1564
+		}
1287 1565
 
1288 1566
 		unset($attachment);
1289 1567
 
@@ -1329,11 +1607,15 @@  discard block
 block discarded – undo
1329 1607
 		//unset($folderid, $id, $message, $contentParameters);
1330 1608
 		$account = $folder = null;
1331 1609
 		$this->splitID($folderid, $account, $folder);
1332
-		if (isset($message->flag)) {
1333
-			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1610
+		if (isset($message->flag))
1611
+		{
1612
+			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2)
1613
+			{
1334 1614
 				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1335 1615
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1336
-			} else {
1616
+			}
1617
+			else
1618
+			{
1337 1619
 				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1338 1620
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1339 1621
 			}
@@ -1363,7 +1645,10 @@  discard block
 block discarded – undo
1363 1645
 		$this->splitID($folderid, $account, $srcFolder);
1364 1646
 		$this->splitID($newfolderid, $account, $destFolder);
1365 1647
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1366
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1648
+		if (!isset($this->mail))
1649
+		{
1650
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1651
+		}
1367 1652
 		$this->mail->reopen($destFolder);
1368 1653
 		$status = $this->mail->getFolderStatus($destFolder);
1369 1654
 		$uidNext = $status['uidnext'];
@@ -1395,11 +1680,15 @@  discard block
 block discarded – undo
1395 1680
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1396 1681
 			}
1397 1682
 			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1398
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1683
+			if (is_numeric($maximumSyncRangeInDays))
1684
+			{
1685
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1686
+			}
1399 1687
 		}
1400 1688
 		try {
1401 1689
 			return $this->fetchMessages($folderid, $cutoffdate);
1402
-		} catch (Exception $e)
1690
+		}
1691
+		catch (Exception $e)
1403 1692
 		{
1404 1693
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details?$e->details:''));
1405 1694
 			return array();
@@ -1423,7 +1712,10 @@  discard block
 block discarded – undo
1423 1712
 	{
1424 1713
 		static $headers = array();
1425 1714
 
1426
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1715
+		if ($this->debugLevel>1)
1716
+		{
1717
+			$gstarttime = microtime (true);
1718
+		}
1427 1719
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1428 1720
 		$rv_messages = array();
1429 1721
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1436,7 +1728,10 @@  discard block
 block discarded – undo
1436 1728
 		{
1437 1729
 			$headers = array();	// clear cache to not use too much memory
1438 1730
 
1439
-			if ($this->debugLevel>1) $starttime = microtime (true);
1731
+			if ($this->debugLevel>1)
1732
+			{
1733
+				$starttime = microtime (true);
1734
+			}
1440 1735
 			$this->_connect($this->account);
1441 1736
 			if ($this->debugLevel>1)
1442 1737
 			{
@@ -1445,8 +1740,14 @@  discard block
 block discarded – undo
1445 1740
 			}
1446 1741
 			$messagelist = $_filter = array();
1447 1742
 			// if not connected, any further action must fail
1448
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1449
-			if ($this->debugLevel>1) $starttime = microtime (true);
1743
+			if (!empty($cutoffdate))
1744
+			{
1745
+				$_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1746
+			}
1747
+			if ($this->debugLevel>1)
1748
+			{
1749
+				$starttime = microtime (true);
1750
+			}
1450 1751
 			$account = $_folderName = $id = null;
1451 1752
 			$this->splitID($folderid,$account,$_folderName,$id);
1452 1753
 			if ($this->debugLevel>1)
@@ -1454,8 +1755,14 @@  discard block
 block discarded – undo
1454 1755
 				$endtime = microtime(true) - $starttime;
1455 1756
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1456 1757
 			}
1457
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1458
-			if ($this->debugLevel>1) $starttime = microtime (true);
1758
+			if ($this->debugLevel>1)
1759
+			{
1760
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1761
+			}
1762
+			if ($this->debugLevel>1)
1763
+			{
1764
+				$starttime = microtime (true);
1765
+			}
1459 1766
 			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1460 1767
 			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1461 1768
 			if ($this->debugLevel>1)
@@ -1464,27 +1771,56 @@  discard block
 block discarded – undo
1464 1771
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1465 1772
 			}
1466 1773
 		}
1467
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1774
+		if ($_id == NULL && $this->debugLevel>1)
1775
+		{
1776
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1777
+		}
1468 1778
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1469 1779
 		$messagelist = array();
1470
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1780
+		if (!isset($rv_messages['header'])||empty($rv_messages['header']))
1781
+		{
1782
+			return $messagelist;
1783
+		}
1471 1784
 		//if ($_returnModHash) $messageFolderHash = array();
1472 1785
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1473 1786
 		{
1474
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1787
+			if ($this->debugLevel>3)
1788
+			{
1789
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1790
+			}
1475 1791
 			$headers[$vars['uid']] = $vars;
1476
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1477
-			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1478
-			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1479
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1792
+			if ($this->debugLevel>3)
1793
+			{
1794
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1795
+			}
1796
+			if (!empty($vars['deleted']))
1797
+			{
1798
+				continue;
1799
+			}
1800
+			// cut of deleted messages
1801
+			if ($cutoffdate && $vars['date'] < $cutoffdate)
1802
+			{
1803
+				continue;
1804
+			}
1805
+			// message is out of range for cutoffdate, ignore it
1806
+			if ($this->debugLevel>0)
1807
+			{
1808
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1809
+			}
1480 1810
 			$mess = $return_all_headers ? $vars : array();
1481 1811
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1482 1812
 			$mess["id"] = $vars['uid'];
1483 1813
 			// 'seen' aka 'read' is the only flag we want to know about
1484 1814
 			$mess["flags"] = 0;
1485 1815
 			// outlook supports additional flags, set them to 0
1486
-			if($vars["seen"]) $mess["flags"] = 1;
1487
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1816
+			if($vars["seen"])
1817
+			{
1818
+				$mess["flags"] = 1;
1819
+			}
1820
+			if ($this->debugLevel>3)
1821
+			{
1822
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1823
+			}
1488 1824
 			$messagelist[$vars['uid']] = $mess;
1489 1825
 			unset($mess);
1490 1826
 		}
@@ -1509,9 +1845,18 @@  discard block
 block discarded – undo
1509 1845
 	static function doFlagsMod($headerFlags)
1510 1846
 	{
1511 1847
 		$flags = 'nnn';
1512
-		if ($headerFlags['flagged']) $flags[0] = 'f';
1513
-		if ($headerFlags['answered']) $flags[1] = 'a';
1514
-		if ($headerFlags['forwarded']) $flags[2] = 'f';
1848
+		if ($headerFlags['flagged'])
1849
+		{
1850
+			$flags[0] = 'f';
1851
+		}
1852
+		if ($headerFlags['answered'])
1853
+		{
1854
+			$flags[1] = 'a';
1855
+		}
1856
+		if ($headerFlags['forwarded'])
1857
+		{
1858
+			$flags[2] = 'f';
1859
+		}
1515 1860
 		//ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags));
1516 1861
 		return $flags;
1517 1862
 	}
@@ -1543,31 +1888,55 @@  discard block
 block discarded – undo
1543 1888
 	{
1544 1889
 		//$this->debugLevel=1;
1545 1890
 		$searchquery=$_searchquery->GetDataArray();
1546
-		if (!is_array($searchquery)) return array();
1547
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1891
+		if (!is_array($searchquery))
1892
+		{
1893
+			return array();
1894
+		}
1895
+		if ($this->debugLevel>0)
1896
+		{
1897
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1898
+		}
1548 1899
 
1549
-		if (isset($searchquery['searchrebuildresults'])) {
1900
+		if (isset($searchquery['searchrebuildresults']))
1901
+		{
1550 1902
 			$rebuildresults = $searchquery['searchrebuildresults'];
1551
-		} else {
1903
+		}
1904
+		else
1905
+		{
1552 1906
 			$rebuildresults = false;
1553 1907
 		}
1554
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1908
+		if ($this->debugLevel>0)
1909
+		{
1910
+			ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1911
+		}
1555 1912
 
1556
-		if (isset($searchquery['deeptraversal'])) {
1913
+		if (isset($searchquery['deeptraversal']))
1914
+		{
1557 1915
 			$deeptraversal = $searchquery['deeptraversal'];
1558
-		} else {
1916
+		}
1917
+		else
1918
+		{
1559 1919
 			$deeptraversal = false;
1560 1920
 		}
1561
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1921
+		if ($this->debugLevel>0)
1922
+		{
1923
+			ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1924
+		}
1562 1925
 
1563
-		if (isset($searchquery['searchrange'])) {
1926
+		if (isset($searchquery['searchrange']))
1927
+		{
1564 1928
 			$range = explode("-",$_searchquery->GetSearchRange());
1565 1929
 			$start =$range[0] + 1;
1566 1930
 			$limit = $range[1] - $range[0] + 1;
1567
-		} else {
1931
+		}
1932
+		else
1933
+		{
1568 1934
 			$range = false;
1569 1935
 		}
1570
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1936
+		if ($this->debugLevel>0)
1937
+		{
1938
+			ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1939
+		}
1571 1940
 
1572 1941
 		//foreach($searchquery['query'] as $k => $value) {
1573 1942
 		//	$query = $value;
@@ -1619,7 +1988,10 @@  discard block
 block discarded – undo
1619 1988
 			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1620 1989
 		}
1621 1990
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1622
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1991
+		if ($this->debugLevel>1)
1992
+		{
1993
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1994
+		}
1623 1995
 		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1624 1996
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1625 1997
 		$list=array();
@@ -1651,17 +2023,26 @@  discard block
 block discarded – undo
1651 2023
 	private function getParentID($account,$folder)
1652 2024
 	{
1653 2025
 		$this->_connect($account);
1654
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2026
+		if (!isset($this->folders))
2027
+		{
2028
+			$this->folders = $this->mail->getFolderObjects(true,false);
2029
+		}
1655 2030
 
1656 2031
 		$mailFolder = $this->folders[$folder];
1657
-		if (!isset($mailFolder)) return false;
2032
+		if (!isset($mailFolder))
2033
+		{
2034
+			return false;
2035
+		}
1658 2036
 		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1659 2037
 		$parent = explode($delimiter,$folder);
1660 2038
 		array_pop($parent);
1661 2039
 		$parent = implode($delimiter,$parent);
1662 2040
 
1663 2041
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1664
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2042
+		if ($this->debugLevel>1)
2043
+		{
2044
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2045
+		}
1665 2046
 		return $id;
1666 2047
 	}
1667 2048
 
@@ -1675,7 +2056,10 @@  discard block
 block discarded – undo
1675 2056
 	{
1676 2057
 		static $last_id = null;
1677 2058
 		static $folderObj = null;
1678
-		if (isset($last_id) && $last_id === $id) return $folderObj;
2059
+		if (isset($last_id) && $last_id === $id)
2060
+		{
2061
+			return $folderObj;
2062
+		}
1679 2063
 
1680 2064
 		try {
1681 2065
 			$account = $folder = null;
@@ -1686,18 +2070,30 @@  discard block
 block discarded – undo
1686 2070
 			return $folderObj=false;
1687 2071
 		}
1688 2072
 		$this->_connect($account);
1689
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2073
+		if (!isset($this->folders))
2074
+		{
2075
+			$this->folders = $this->mail->getFolderObjects(true,false);
2076
+		}
1690 2077
 
1691 2078
 		$mailFolder = $this->folders[$folder];
1692
-		if (!isset($mailFolder)) return $folderObj=false;
2079
+		if (!isset($mailFolder))
2080
+		{
2081
+			return $folderObj=false;
2082
+		}
1693 2083
 
1694 2084
 		$folderObj = new SyncFolder();
1695 2085
 		$folderObj->serverid = $id;
1696 2086
 		$folderObj->parentid = $this->getParentID($account,$folder);
1697 2087
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1698
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2088
+		if ($this->debugLevel>1)
2089
+		{
2090
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2091
+		}
1699 2092
 		// get folder-type
1700
-		foreach($this->folders as $inbox => $mailFolder) break;
2093
+		foreach($this->folders as $inbox => $mailFolder)
2094
+		{
2095
+			break;
2096
+		}
1701 2097
 		if ($folder == $inbox)
1702 2098
 		{
1703 2099
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
@@ -1734,7 +2130,10 @@  discard block
 block discarded – undo
1734 2130
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1735 2131
 		}
1736 2132
 
1737
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2133
+		if ($this->debugLevel>1)
2134
+		{
2135
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2136
+		}
1738 2137
 		return $folderObj;
1739 2138
 	}
1740 2139
 
@@ -1778,11 +2177,20 @@  discard block
 block discarded – undo
1778 2177
 	{
1779 2178
 		$account = $folder = null;
1780 2179
 		$this->splitID($folderid, $account, $folder);
1781
-		if (is_numeric($account)) $type = 'mail';
2180
+		if (is_numeric($account))
2181
+		{
2182
+			$type = 'mail';
2183
+		}
1782 2184
 
1783
-		if ($type != 'mail') return false;
2185
+		if ($type != 'mail')
2186
+		{
2187
+			return false;
2188
+		}
1784 2189
 
1785
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2190
+		if (!isset($this->mail))
2191
+		{
2192
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2193
+		}
1786 2194
 
1787 2195
         $this->mail->reopen($folder);
1788 2196
 
@@ -1827,7 +2235,7 @@  discard block
 block discarded – undo
1827 2235
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1828 2236
      */
1829 2237
     public function DeleteMessage($folderid, $id, $contentParameters)
1830
-	{
2238
+    {
1831 2239
 		unset($contentParameters);	// not used, but required by function signature
1832 2240
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1833 2241
 		/*
@@ -1853,7 +2261,10 @@  discard block
 block discarded – undo
1853 2261
 			$error = $e->getMessage();
1854 2262
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1855 2263
 			// if the server thinks the message does not exist report deletion as success
1856
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
2264
+			if (stripos($error,'[NONEXISTENT]')!==false)
2265
+			{
2266
+				return true;
2267
+			}
1857 2268
 			return false;
1858 2269
 		}
1859 2270
 
@@ -1886,7 +2297,7 @@  discard block
 block discarded – undo
1886 2297
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1887 2298
      */
1888 2299
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1889
-	{
2300
+    {
1890 2301
 		unset($contentParameters);	// not used, but required by function signature
1891 2302
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1892 2303
 		$account = $folder = null;
@@ -1970,10 +2381,16 @@  discard block
 block discarded – undo
1970 2381
 		$account = $parent_id = $app = null;
1971 2382
 		$this->splitID($id, $account, $folder, $app);
1972 2383
 		$old_hash = $this->folder2hash($account, $folder);
1973
-		if ($parentid) $this->splitID($parentid, $account, $parentfolder, $app);
2384
+		if ($parentid)
2385
+		{
2386
+			$this->splitID($parentid, $account, $parentfolder, $app);
2387
+		}
1974 2388
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."( '$id (-> $folder)','$parentid ".($parentid?'(->'.$parentfolder.')':'')."') called!");
1975 2389
 		$ret = $this->mail->deleteFolder($folder);
1976
-		if ($ret) $newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##");
2390
+		if ($ret)
2391
+		{
2392
+			$newHash = $this->rename_folder_hash($account, $old_hash, "##Dele#edFolder#$folder##");
2393
+		}
1977 2394
 		return $ret;
1978 2395
 	}
1979 2396
 
@@ -2018,7 +2435,10 @@  discard block
 block discarded – undo
2018 2435
 
2019 2436
 		$str = $this->backend->createID($account, $folder, $id);
2020 2437
 
2021
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2438
+		if ($this->debugLevel>1)
2439
+		{
2440
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2441
+		}
2022 2442
 
2023 2443
 		return $str;
2024 2444
 	}
@@ -2039,7 +2459,10 @@  discard block
 block discarded – undo
2039 2459
 		// convert numeric folder-id back to folder name
2040 2460
 		$folder = $this->hash2folder($account,$f=$folder);
2041 2461
 
2042
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)");
2462
+		if ($this->debugLevel>1)
2463
+		{
2464
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$appid)");
2465
+		}
2043 2466
 	}
2044 2467
 
2045 2468
 	/**
@@ -2058,7 +2481,10 @@  discard block
 block discarded – undo
2058 2481
 	 */
2059 2482
 	private function folder2hash($account,$folder)
2060 2483
 	{
2061
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2484
+		if(!isset($this->folderHashes))
2485
+		{
2486
+			$this->readFolderHashes();
2487
+		}
2062 2488
 
2063 2489
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2064 2490
 		{
@@ -2081,7 +2507,10 @@  discard block
 block discarded – undo
2081 2507
 	 */
2082 2508
 	private function hash2folder($account,$index)
2083 2509
 	{
2084
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2510
+		if(!isset($this->folderHashes))
2511
+		{
2512
+			$this->readFolderHashes();
2513
+		}
2085 2514
 
2086 2515
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2087 2516
 	}
Please login to merge, or discard this patch.