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