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