Completed
Push — 16.1 ( b5b1ff...6fee3b )
by Klaus
29:58 queued 15:55
created
api/src/Mailer.php 3 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -489,10 +489,10 @@  discard block
 block discarded – undo
489 489
 	 * Log mails to log file specified in $GLOBALS['egw_info']['server']['log_mail']
490 490
 	 * or regular error_log for true (can be set either in DB or header.inc.php).
491 491
 	 *
492
-     * @param Horde_Mail_Transport $transport =null using transport from mail-account
492
+	 * @param Horde_Mail_Transport $transport =null using transport from mail-account
493 493
 	 *		specified in construct, or default one, if not specified
494
-     * @param boolean $resend =true allways true in EGroupware!
495
-     * @param boolean $flowed =null send message in flowed text format,
494
+	 * @param boolean $resend =true allways true in EGroupware!
495
+	 * @param boolean $flowed =null send message in flowed text format,
496 496
 	 *		default null used flowed by default for everything but multipart/encrypted,
497 497
 	 *		unless disabled in site configuration ("disable_rfc3676_flowed")
498 498
 	 *
@@ -650,15 +650,15 @@  discard block
 block discarded – undo
650 650
 	}
651 651
 
652 652
 	/**
653
-     * Get the raw email data sent by this object.
654
-     *
653
+	 * Get the raw email data sent by this object.
654
+	 *
655 655
 	 * Reimplement to be able to call it for saveAsDraft by calling
656 656
 	 * $this->send(new Horde_Mail_Transport_Null()),
657 657
 	 * if no base-part is set, because send is not called before.
658 658
 	 *
659
-     * @param  boolean $stream  If true, return a stream resource, otherwise
660
-     * @return stream|string  The raw email data.
661
-     */
659
+	 * @param  boolean $stream  If true, return a stream resource, otherwise
660
+	 * @return stream|string  The raw email data.
661
+	 */
662 662
 	function getRaw($stream=true)
663 663
 	{
664 664
 		try {
@@ -671,20 +671,20 @@  discard block
 block discarded – undo
671 671
 		}
672 672
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
673 673
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
674
-        if ($stream) {
675
-            $hdr = new Horde_Stream();
676
-            $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
677
-            return Horde_Stream_Wrapper_Combine::getStream(
678
-                array($hdr->stream,
679
-                      $this->getBasePart()->toString(
680
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
681
-                )
682
-            );
683
-        }
684
-
685
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
674
+		if ($stream) {
675
+			$hdr = new Horde_Stream();
676
+			$hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
677
+			return Horde_Stream_Wrapper_Combine::getStream(
678
+				array($hdr->stream,
679
+					  $this->getBasePart()->toString(
680
+						array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
681
+				)
682
+			);
683
+		}
684
+
685
+		return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
686 686
 			$this->getBasePart()->toString(array('canonical' => true));
687
-    }
687
+	}
688 688
 
689 689
 	/**
690 690
 	 * Convert charset of text-parts of message to utf-8. non static AND include Bcc
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 	 * @return string|stream
697 697
 	 */
698 698
 	function convertMessageTextParts($message, $stream=false, $charset='utf-8', &$converted=false)
699
-        {
699
+		{
700 700
 		$headers = Horde_Mime_Headers::parseHeaders($message);
701 701
 		$this->addHeaders($headers);
702 702
 		$base = Horde_Mime_Part::parseMessage($message);
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	 *	false: no NOT initialise account and set other EGroupware specific headers, used to parse mails (not sending them!)
68 68
 	 *	initbasic: return $this
69 69
 	 */
70
-	function __construct($account=null)
70
+	function __construct($account = null)
71 71
 	{
72 72
 		// Horde use locale for translation of error messages
73 73
 		Preferences::setlocale(LC_MESSAGES);
74 74
 
75 75
 		parent::__construct();
76
-		if ($account ==='initbasic')
76
+		if ($account === 'initbasic')
77 77
 		{
78 78
 			$this->_headers = new Horde_Mime_Headers();
79 79
 			$this->clearAllRecipients();
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param int|Mail\Account $account =null mail account to use, default use Mail\Account::get_default($smtp=true)
114 114
 	 * @throws Exception\NotFound if account was not found (or not valid for current user)
115 115
 	 */
116
-	function  setAccount($account=null)
116
+	function  setAccount($account = null)
117 117
 	{
118 118
 		if ($account instanceof Mail\Account)
119 119
 		{
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		{
136 136
 			$identity = Mail\Account::read_identity($this->account->ident_id, true, null, $this->account);
137 137
 		}
138
-		catch(Exception $e)
138
+		catch (Exception $e)
139 139
 		{
140 140
 			unset($e);
141 141
 			error_log(__METHOD__.__LINE__.' Could not read_identity for account:'.$account['acc_id'].' with IdentID:'.$account['ident_id']);
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param string $address
158 158
 	 * @param string $personal =''
159 159
 	 */
160
-	public function setFrom($address, $personal='')
160
+	public function setFrom($address, $personal = '')
161 161
 	{
162 162
 		$this->addHeader('From', self::add_personal($address, $personal));
163 163
 	}
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
 	 * @param string $personal ='' only used if $address is a string
170 170
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
171 171
 	 */
172
-	function addAddress($address, $personal='', $type='to')
172
+	function addAddress($address, $personal = '', $type = 'to')
173 173
 	{
174 174
 		if (!isset(self::$type2header[$type]))
175 175
 		{
176 176
 			throw new Exception\WrongParameter("Unknown type '$type'!");
177 177
 		}
178
-		if ($personal) $address = self::add_personal ($address, $personal);
178
+		if ($personal) $address = self::add_personal($address, $personal);
179 179
 
180 180
 		// add to our local list
181 181
 		$this->$type->add($address);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 *
190 190
 	 * @param string $type ='to' type of address to add "to", "cc", "bcc" or "replyto"
191 191
 	 */
192
-	function clearAddresses($type='to')
192
+	function clearAddresses($type = 'to')
193 193
 	{
194 194
 		$this->$type = new Horde_Mail_Rfc822_List();
195 195
 
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
 	 * @param boolean $return_array =false true: return array of string, false: Horde_Mail_Rfc822_List
204 204
 	 * @return array|Horde_Mail_Rfc822_List supporting arrayAccess and Iterable
205 205
 	 */
206
-	function getAddresses($type='to', $return_array=false)
206
+	function getAddresses($type = 'to', $return_array = false)
207 207
 	{
208 208
 		if ($return_array)
209 209
 		{
210 210
 			$addresses = array();
211
-			foreach($this->$type as $addr)
211
+			foreach ($this->$type as $addr)
212 212
 			{
213 213
 				$addresses[] = (string)$addr;
214 214
 			}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
250 250
 			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
251 251
 			{
252
-				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
252
+				$personal = '"'.str_replace(array('\\', '"'), array('\\\\', '\\"'), $personal).'"';
253 253
 			}
254 254
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
255 255
 		}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @param string|array|Horde_Mail_Rfc822_List $address
263 263
 	 * @param string $personal ='' only used if $address is a string
264 264
 	 */
265
-	function addCc($address, $personal=null)
265
+	function addCc($address, $personal = null)
266 266
 	{
267 267
 		$this->addAddress($address, $personal, 'cc');
268 268
 	}
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @param string|array|Horde_Mail_Rfc822_List $address
282 282
 	 * @param string $personal ='' only used if $address is a string
283 283
 	 */
284
-	function addBcc($address, $personal=null)
284
+	function addBcc($address, $personal = null)
285 285
 	{
286 286
 		$this->addAddress($address, $personal, 'bcc');
287 287
 	}
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 	 * @param string|array|Horde_Mail_Rfc822_List $address
301 301
 	 * @param string $personal ='' only used if $address is a string
302 302
 	 */
303
-	function addReplyTo($address, $personal=null)
303
+	function addReplyTo($address, $personal = null)
304 304
 	{
305 305
 		$this->addAddress($address, $personal, 'replyto');
306 306
 	}
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	 * @return integer part-number
336 336
 	 * @throws Exception\NotFound if $file could not be opened for reading
337 337
 	 */
338
-	public function addAttachment($data, $name = null, $type = null, $old_type=null)
338
+	public function addAttachment($data, $name = null, $type = null, $old_type = null)
339 339
 	{
340 340
 		// deprecated PHPMailer::AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') call
341 341
 		if ($type === 'base64')
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 		// set content-type parameters, which get ignored by setType
369 369
 		if (preg_match_all('/;\s*([^=]+)=([^;]*)/', $type, $matches))
370 370
 		{
371
-			foreach($matches[1] as $n => $label)
371
+			foreach ($matches[1] as $n => $label)
372 372
 			{
373 373
 				$part->setContentTypeParameter($label, $matches[2][$n]);
374 374
 			}
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 	 * @param array $parameters =array() eg. array('method' => 'REQUEST')
471 471
 	 * @param string $charset =null default to $this->_charset="utf-8"
472 472
 	 */
473
-	function setAlternativBody($content, $type, $parameters=array(), $charset=null)
473
+	function setAlternativBody($content, $type, $parameters = array(), $charset = null)
474 474
 	{
475 475
 		$this->_alternativBody = new Horde_Mime_Part();
476 476
 		$this->_alternativBody->setType($type);
477
-		foreach($parameters as $label => $data)
477
+		foreach ($parameters as $label => $data)
478 478
 		{
479 479
 			$this->_alternativBody->setContentTypeParameter($label, $data);
480 480
 		}
@@ -499,9 +499,9 @@  discard block
 block discarded – undo
499 499
 	 * @throws Exception\NotFound for no smtp account available
500 500
 	 * @throws Horde_Mime_Exception
501 501
 	 */
502
-	function send(Horde_Mail_Transport $transport=null, $resend=true, $flowed=null)
502
+	function send(Horde_Mail_Transport $transport = null, $resend = true, $flowed = null)
503 503
 	{
504
-		unset($resend);	// parameter is not used, but required by function signature
504
+		unset($resend); // parameter is not used, but required by function signature
505 505
 
506 506
 		if (!($message_id = $this->getHeader('Message-ID')) &&
507 507
 			class_exists('Horde_Mime_Headers_MessageId'))	// since 2.5.0
@@ -509,24 +509,24 @@  discard block
 block discarded – undo
509 509
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
510 510
 			$this->addHeader('Message-ID', $message_id);
511 511
 		}
512
-		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
512
+		$body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now
513 513
 
514 514
 		$mail_id = Hooks::process(array(
515 515
 			'location' => 'send_mail',
516
-			'subject' => $subject=$this->getHeader('Subject'),
516
+			'subject' => $subject = $this->getHeader('Subject'),
517 517
 			'from' => $this->getHeader('Return-Path') ? $this->getHeader('Return-Path') : $this->getHeader('From'),
518
-			'to' => $to=$this->getAddresses('to', true),
519
-			'cc' => $cc=$this->getAddresses('cc', true),
520
-			'bcc' => $bcc=$this->getAddresses('bcc', true),
518
+			'to' => $to = $this->getAddresses('to', true),
519
+			'cc' => $cc = $this->getAddresses('cc', true),
520
+			'bcc' => $bcc = $this->getAddresses('bcc', true),
521 521
 			'body_sha1' => $body_sha1,
522 522
 			'message_id' => (string)$message_id,
523
-		), array(), true);	// true = call all apps
523
+		), array(), true); // true = call all apps
524 524
 
525 525
 		// check if we are sending an html mail with inline images
526 526
 		if (!empty($this->_htmlBody) && count($this->_parts))
527 527
 		{
528 528
 			$related = null;
529
-			foreach($this->_parts as $n => $part)
529
+			foreach ($this->_parts as $n => $part)
530 530
 			{
531 531
 				if ($part->getDisposition() == 'inline' && $part->getContentId())
532 532
 				{
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 				$this->_body = $body;
583 583
 				$flowed = false;
584 584
 			}
585
-			parent::send($transport ? $transport : $this->account->smtpTransport(), true,	$flowed);	// true: keep Message-ID
585
+			parent::send($transport ? $transport : $this->account->smtpTransport(), true, $flowed); // true: keep Message-ID
586 586
 		}
587 587
 		catch (\Exception $e) {
588 588
 			// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 				'message_id' => (string)$message_id,
598 598
 				'mail_id' => $mail_id,
599 599
 				'error' => $e->getMessage(),
600
-			), array(), true);	// true = call all apps
600
+			), array(), true); // true = call all apps
601 601
 		}
602 602
 
603 603
 		// log mails to file specified in $GLOBALS['egw_info']['server']['log_mail'] or error_log for true
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 			$msg .= ' from instance '.$GLOBALS['egw_info']['user']['domain'].' and IP '.Session::getuser_ip();
611 611
 			$msg .= ' from user #'.$GLOBALS['egw_info']['user']['account_id'];
612 612
 
613
-			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts',false))
613
+			if ($GLOBALS['egw_info']['user']['account_id'] && class_exists(__NAMESPACE__.'\\Accounts', false))
614 614
 			{
615 615
 				$msg .= ' ('.Accounts::username($GLOBALS['egw_info']['user']['account_id']).')';
616 616
 			}
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
623 623
 			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
624 624
 
625
-			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
625
+			error_log($msg, $GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
626 626
 				$GLOBALS['egw_info']['server']['log_mail']);
627 627
 		}
628 628
 		// rethrow error
@@ -659,15 +659,15 @@  discard block
 block discarded – undo
659 659
      * @param  boolean $stream  If true, return a stream resource, otherwise
660 660
      * @return stream|string  The raw email data.
661 661
      */
662
-	function getRaw($stream=true)
662
+	function getRaw($stream = true)
663 663
 	{
664 664
 		try {
665 665
 			$this->getBasePart();
666 666
 		}
667
-		catch(Horde_Mail_Exception $e)
667
+		catch (Horde_Mail_Exception $e)
668 668
 		{
669 669
 			unset($e);
670
-			parent::send(new Horde_Mail_Transport_Null(), true);	// true: keep Message-ID
670
+			parent::send(new Horde_Mail_Transport_Null(), true); // true: keep Message-ID
671 671
 		}
672 672
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
673 673
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
@@ -677,12 +677,12 @@  discard block
 block discarded – undo
677 677
             return Horde_Stream_Wrapper_Combine::getStream(
678 678
                 array($hdr->stream,
679 679
                       $this->getBasePart()->toString(
680
-                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY))
680
+                        array('stream' => true, 'canonical' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT|Horde_Mime_Part::ENCODE_8BIT|Horde_Mime_Part::ENCODE_BINARY))
681 681
                 )
682 682
             );
683 683
         }
684 684
 
685
-        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)) .
685
+        return $this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)).
686 686
 			$this->getBasePart()->toString(array('canonical' => true));
687 687
     }
688 688
 
@@ -695,16 +695,16 @@  discard block
 block discarded – undo
695 695
 	 * @param boolean &$converted =false on return if conversation was necessary
696 696
 	 * @return string|stream
697 697
 	 */
698
-	function convertMessageTextParts($message, $stream=false, $charset='utf-8', &$converted=false)
698
+	function convertMessageTextParts($message, $stream = false, $charset = 'utf-8', &$converted = false)
699 699
         {
700 700
 		$headers = Horde_Mime_Headers::parseHeaders($message);
701 701
 		$this->addHeaders($headers);
702 702
 		$base = Horde_Mime_Part::parseMessage($message);
703
-		foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
703
+		foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
704 704
 		{
705
-			foreach((array)$value as $n => $val)
705
+			foreach ((array)$value as $n => $val)
706 706
 			{
707
-				switch($header)
707
+				switch ($header)
708 708
 				{
709 709
 					case 'Bcc':
710 710
 					case 'bcc':
@@ -714,18 +714,18 @@  discard block
 block discarded – undo
714 714
 				}
715 715
 			}
716 716
 		}
717
-		foreach($base->partIterator() as $part)
717
+		foreach ($base->partIterator() as $part)
718 718
 		{
719
-			if ($part->getPrimaryType()== 'text')
719
+			if ($part->getPrimaryType() == 'text')
720 720
 			{
721 721
 				$charset = $part->getContentTypeParameter('charset');
722 722
 				if ($charset && $charset != 'utf-8')
723 723
 				{
724 724
 					$content = Translation::convert($part->toString(array(
725
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,     // otherwise we cant recode charset
725
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
726 726
 						)), $charset, 'utf-8');
727 727
 					$part->setContents($content, array(
728
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,     // $content is NOT encoded
728
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // $content is NOT encoded
729 729
 						));
730 730
 					$part->setContentTypeParameter('charset', 'utf-8');
731 731
 					if ($part === $base)
@@ -761,23 +761,23 @@  discard block
 block discarded – undo
761 761
 	 * @param boolean &$converted =false on return if conversation was necessary
762 762
 	 * @return string|stream
763 763
 	 */
764
-	static function convert($message, $stream=false, $charset='utf-8', &$converted=false)
764
+	static function convert($message, $stream = false, $charset = 'utf-8', &$converted = false)
765 765
 	{
766
-		$mailer = new Mailer(false);	// false = no default headers and mail account
766
+		$mailer = new Mailer(false); // false = no default headers and mail account
767 767
 		$mailer->addHeaders(Horde_Mime_Headers::parseHeaders($message));
768 768
 		$base = Horde_Mime_Part::parseMessage($message);
769
-		foreach($base->partIterator() as $part)
769
+		foreach ($base->partIterator() as $part)
770 770
 		{
771
-			if ($part->getPrimaryType()== 'text')
771
+			if ($part->getPrimaryType() == 'text')
772 772
 			{
773 773
 				$charset = $part->getContentTypeParameter('charset');
774 774
 				if ($charset && $charset != 'utf-8')
775 775
 				{
776 776
 					$content = Translation::convert($part->toString(array(
777
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
777
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
778 778
 					)), $charset, 'utf-8');
779 779
 					$part->setContents($content, array(
780
-						'encode' => Horde_Mime_Part::ENCODE_BINARY,	// $content is NOT encoded
780
+						'encode' => Horde_Mime_Part::ENCODE_BINARY, // $content is NOT encoded
781 781
 					));
782 782
 					$part->setContentTypeParameter('charset', 'utf-8');
783 783
 					if ($part === $base)
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 * @param string $subtype =null
811 811
 	 * @return Horde_Mime_Part part with body or null
812 812
 	 */
813
-	function findBody($subtype=null)
813
+	function findBody($subtype = null)
814 814
 	{
815 815
 		try {
816 816
 			$base = $this->getBasePart();
@@ -842,11 +842,11 @@  discard block
 block discarded – undo
842 842
 			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
843 843
 			$this->clearParts();
844 844
 
845
-			foreach($base->partIterator() as $part)
845
+			foreach ($base->partIterator() as $part)
846 846
 			{
847 847
 				$id = $part->getMimeId();
848 848
 				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
849
-				switch($id)
849
+				switch ($id)
850 850
 				{
851 851
 					case '0':	// base-part itself
852 852
 						continue 2;
@@ -890,11 +890,11 @@  discard block
 block discarded – undo
890 890
 			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
891 891
 			$this->clearParts();
892 892
 
893
-			foreach($base->partIterator() as $part)
893
+			foreach ($base->partIterator() as $part)
894 894
 			{
895 895
 				$id = $part->getMimeId();
896 896
 				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
897
-				switch($id)
897
+				switch ($id)
898 898
 				{
899 899
 					case '0':	// base-part itself
900 900
 						continue 2;
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
 	 */
967 967
 	function clearCustomHeaders()
968 968
 	{
969
-		foreach($this->_headers->toArray() as $header => $value)
969
+		foreach ($this->_headers->toArray() as $header => $value)
970 970
 		{
971 971
 			if (stripos($header, 'x-') === 0 || $header == 'Received')
972 972
 			{
Please login to merge, or discard this patch.
Braces   +51 added lines, -14 removed lines patch added patch discarded remove patch
@@ -125,10 +125,13 @@  discard block
 block discarded – undo
125 125
 		}
126 126
 		else
127 127
 		{
128
-			if (!($this->account = Mail\Account::get_default(true)))	// true = need an SMTP (not just IMAP) account
128
+			if (!($this->account = Mail\Account::get_default(true)))
129
+			{
130
+				// true = need an SMTP (not just IMAP) account
129 131
 			{
130 132
 				throw new Exception\NotFound('SMTP: '.lang('Account not found!'));
131 133
 			}
134
+			}
132 135
 		}
133 136
 
134 137
 		try
@@ -175,7 +178,10 @@  discard block
 block discarded – undo
175 178
 		{
176 179
 			throw new Exception\WrongParameter("Unknown type '$type'!");
177 180
 		}
178
-		if ($personal) $address = self::add_personal ($address, $personal);
181
+		if ($personal)
182
+		{
183
+			$address = self::add_personal ($address, $personal);
184
+		}
179 185
 
180 186
 		// add to our local list
181 187
 		$this->$type->add($address);
@@ -247,10 +253,13 @@  discard block
 block discarded – undo
247 253
 		if (is_string($address) && !empty($personal))
248 254
 		{
249 255
 			//if (!preg_match('/^[!#$%&\'*+/0-9=?A-Z^_`a-z{|}~-]+$/u', $personal))	// that's how I read the rfc(2)822
250
-			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))	// but quoting is never wrong, so quote more then necessary
256
+			if ($personal && !preg_match('/^[0-9A-Z -]*$/iu', $personal))
257
+			{
258
+				// but quoting is never wrong, so quote more then necessary
251 259
 			{
252 260
 				$personal = '"'.str_replace(array('\\', '"'),array('\\\\', '\\"'), $personal).'"';
253 261
 			}
262
+			}
254 263
 			$address = ($personal ? $personal.' <' : '').$address.($personal ? '>' : '');
255 264
 		}
256 265
 		return $address;
@@ -353,7 +362,10 @@  discard block
 block discarded – undo
353 362
 			throw new Exception\NotFound("File '$data' not found!");
354 363
 		}
355 364
 
356
-		if (empty($type) && !is_resource($data)) $type = Vfs::mime_content_type($data);
365
+		if (empty($type) && !is_resource($data))
366
+		{
367
+			$type = Vfs::mime_content_type($data);
368
+		}
357 369
 
358 370
 		// set "text/calendar; method=*" as alternativ body
359 371
 		$matches = null;
@@ -376,11 +388,17 @@  discard block
 block discarded – undo
376 388
 		$part->setContents($resource);
377 389
 
378 390
 		// setting name, also sets content-disposition attachment (!), therefore we have to do it after "text/calendar; method=" handling
379
-		if ($name || !is_resource($data)) $part->setName($name ? $name : Vfs::basename($data));
391
+		if ($name || !is_resource($data))
392
+		{
393
+			$part->setName($name ? $name : Vfs::basename($data));
394
+		}
380 395
 
381 396
 		// this should not be necessary, because binary data get detected by mime-type,
382 397
 		// but at least Cyrus complains about NUL characters
383
-		if (substr($type, 0, 5) != 'text/') $part->setTransferEncoding('base64', array('send' => true));
398
+		if (substr($type, 0, 5) != 'text/')
399
+		{
400
+			$part->setTransferEncoding('base64', array('send' => true));
401
+		}
384 402
 		$part->setDisposition('attachment');
385 403
 
386 404
 		return $this->addMimePart($part);
@@ -504,9 +522,12 @@  discard block
 block discarded – undo
504 522
 		unset($resend);	// parameter is not used, but required by function signature
505 523
 
506 524
 		if (!($message_id = $this->getHeader('Message-ID')) &&
507
-			class_exists('Horde_Mime_Headers_MessageId'))	// since 2.5.0
525
+			class_exists('Horde_Mime_Headers_MessageId'))
526
+		{
527
+			// since 2.5.0
508 528
 		{
509 529
 			$message_id = Horde_Mime_Headers_MessageId::create('EGroupware');
530
+		}
510 531
 			$this->addHeader('Message-ID', $message_id);
511 532
 		}
512 533
 		$body_sha1 = null;	// skip sha1, it requires whole mail in memory, which we traing to avoid now
@@ -546,7 +567,10 @@  discard block
 block discarded – undo
546 567
 
547 568
 		try {
548 569
 			// no flowed for encrypted messages
549
-			if (!isset($flowed)) $flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted';
570
+			if (!isset($flowed))
571
+			{
572
+				$flowed = $this->_body && $this->_body->getType() != 'multipart/encrypted';
573
+			}
550 574
 
551 575
 			// check if flowed is disabled in mail site configuration
552 576
 			if (($config = Config::read('mail')) && $config['disable_rfc3676_flowed'])
@@ -620,13 +644,19 @@  discard block
 block discarded – undo
620 644
 				$msg .= 'ERROR '.$e->getMessage();
621 645
 			}
622 646
 			$msg .= ' cc='.implode(', ', $cc).', bcc='.implode(', ', $bcc);
623
-			if ($GLOBALS['egw_info']['server']['log_mail'] !== true) $msg .= "\n\n";
647
+			if ($GLOBALS['egw_info']['server']['log_mail'] !== true)
648
+			{
649
+				$msg .= "\n\n";
650
+			}
624 651
 
625 652
 			error_log($msg,$GLOBALS['egw_info']['server']['log_mail'] === true ? 0 : 3,
626 653
 				$GLOBALS['egw_info']['server']['log_mail']);
627 654
 		}
628 655
 		// rethrow error
629
-		if (isset($e)) throw $e;
656
+		if (isset($e))
657
+		{
658
+			throw $e;
659
+		}
630 660
 	}
631 661
 
632 662
 
@@ -671,7 +701,8 @@  discard block
 block discarded – undo
671 701
 		}
672 702
 		// code copied from Horde_Mime_Mail::getRaw(), as there is no way to inject charset in
673 703
 		// _headers->toString(), which is required to encode headers containing non-ascii chars correct
674
-        if ($stream) {
704
+        if ($stream)
705
+        {
675 706
             $hdr = new Horde_Stream();
676 707
             $hdr->add($this->_headers->toString(array('charset' => 'utf-8', 'canonical' => true)), true);
677 708
             return Horde_Stream_Wrapper_Combine::getStream(
@@ -696,7 +727,7 @@  discard block
 block discarded – undo
696 727
 	 * @return string|stream
697 728
 	 */
698 729
 	function convertMessageTextParts($message, $stream=false, $charset='utf-8', &$converted=false)
699
-        {
730
+	{
700 731
 		$headers = Horde_Mime_Headers::parseHeaders($message);
701 732
 		$this->addHeaders($headers);
702 733
 		$base = Horde_Mime_Part::parseMessage($message);
@@ -814,7 +845,10 @@  discard block
 block discarded – undo
814 845
 	{
815 846
 		try {
816 847
 			$base = $this->getBasePart();
817
-			if (!($part_id = $base->findBody($subtype))) return null;
848
+			if (!($part_id = $base->findBody($subtype)))
849
+			{
850
+				return null;
851
+			}
818 852
 			return $base->getPart($part_id);
819 853
 		}
820 854
 		catch (Exception $e) {
@@ -928,7 +962,10 @@  discard block
 block discarded – undo
928 962
 	 */
929 963
 	public function addMimePart($part)
930 964
 	{
931
-		if ($this->_base) $this->parseBasePart();
965
+		if ($this->_base)
966
+		{
967
+			$this->parseBasePart();
968
+		}
932 969
 
933 970
 		return parent::addMimePart($part);
934 971
 	}
Please login to merge, or discard this patch.
mail/inc/class.mail_zpush.inc.php 1 patch
Spacing   +346 added lines, -347 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,90 +368,90 @@  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
 		// beware. the section below might cause trouble regarding bcc and attachments, so maybe this is to be handeled differently
422 422
 		if ($force8bit)
423 423
 		{
424
-			$converterObj =  new Api\Mailer('initbasic');
425
-			$smartdata->mime = $converterObj->convertMessageTextParts($smartdata->mime,false,'utf-8');
424
+			$converterObj = new Api\Mailer('initbasic');
425
+			$smartdata->mime = $converterObj->convertMessageTextParts($smartdata->mime, false, 'utf-8');
426 426
 		}
427 427
 		// initialize the new Api\Mailer object for sending
428 428
 		$mailObject = new Api\Mailer(self::$profileID);
429 429
 
430
-		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
430
+		$this->mail->parseRawMessageIntoMailObject($mailObject, $smartdata->mime, $force8bit);
431 431
 		// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
432
-		$mailObject->Sender  = $activeMailProfile['ident_email'];
433
-		$mailObject->setFrom($activeMailProfile['ident_email'],Mail::generateIdentityString($activeMailProfile,false));
432
+		$mailObject->Sender = $activeMailProfile['ident_email'];
433
+		$mailObject->setFrom($activeMailProfile['ident_email'], Mail::generateIdentityString($activeMailProfile, false));
434 434
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
435 435
 
436 436
 		// prepare addressee list; moved the adding of addresses to the mailobject down
437 437
 		// to
438
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
438
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
439 439
 			if (!$addressObject->valid) continue;
440
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
440
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
441 441
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
442 442
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
443 443
 		}
444 444
 		// CC
445
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
445
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
446 446
 			if (!$addressObject->valid) continue;
447
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
447
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
448 448
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
449 449
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
450 450
 		}
451 451
 		// BCC
452
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
452
+		foreach ($mailObject->getAddresses('bcc') as $addressObject) {
453 453
 			if (!$addressObject->valid) continue;
454
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
454
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
455 455
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
456 456
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
457 457
 		}
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		$use_orgbody = false;
461 461
 
462 462
 		$k = 'Content-Type';
463
-		$ContentType =$mailObject->getHeader('Content-Type');
463
+		$ContentType = $mailObject->getHeader('Content-Type');
464 464
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
465 465
 		// if the message is a multipart message, then we should use the sent body
466 466
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -480,43 +480,43 @@  discard block
 block discarded – undo
480 480
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
481 481
 			$use_orgbody = true;
482 482
 		}
483
-		$Body =  $AltBody = "";
483
+		$Body = $AltBody = "";
484 484
 		// get body of the transmitted message
485 485
 		// if this is a simple message, no structure at all
486 486
 		if (preg_match("/text/i", $ContentType))
487 487
 		{
488
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
488
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
489 489
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
490
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
491
-			if  ($simpleBodyType == "text/plain")
490
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
491
+			if ($simpleBodyType == "text/plain")
492 492
 			{
493 493
 				$Body = $body;
494 494
 				$AltBody = "<pre>".nl2br($body)."</pre>";
495
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
495
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
496 496
 			}
497 497
 			else
498 498
 			{
499 499
 				$AltBody = $body;
500
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
501
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
500
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
501
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
502 502
 			}
503 503
 		}
504 504
 		else
505 505
 		{
506 506
 			// if this is a structured message
507 507
 			// prefer plain over html
508
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
508
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
509 509
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
510
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
510
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
511 511
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
512 512
 		}
513
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
514
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
513
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
514
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
515 515
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
516 516
 		// if this is a multipart message with a boundary, we must use the original body
517 517
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
518 518
         if ($use_orgbody) {
519
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
519
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
520 520
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
521 521
 			if (($cal_body = $mailObject->findBody('calendar')) &&
522 522
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -525,21 +525,21 @@  discard block
 block discarded – undo
525 525
 				{
526 526
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
527 527
 				}
528
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
528
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
529 529
 				$ClientSideMeetingRequest = true;
530 530
 			}
531 531
         }
532 532
 		// now handle the addressee list
533 533
 		$toCount = 0;
534 534
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
535
-		foreach((array)$toMailAddr as $address) {
536
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
537
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
535
+		foreach ((array)$toMailAddr as $address) {
536
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
537
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
538 538
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
539 539
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
540 540
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
541 541
 				{
542
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
542
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
543 543
 					continue;
544 544
 				}
545 545
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -547,29 +547,29 @@  discard block
 block discarded – undo
547 547
 			}
548 548
 		}
549 549
 		$ccCount = 0;
550
-		foreach((array)$ccMailAddr as $address) {
551
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
552
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
550
+		foreach ((array)$ccMailAddr as $address) {
551
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
552
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
553 553
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
554 554
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
555 555
 				$ccCount++;
556 556
 			}
557 557
 		}
558 558
 		$bccCount = 0;
559
-		foreach((array)$bccMailAddr as $address) {
560
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
561
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
559
+		foreach ((array)$bccMailAddr as $address) {
560
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
561
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
562 562
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
563 563
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
564 564
 				$bccCount++;
565 565
 			}
566 566
 		}
567 567
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
568
-		if ($toCount+$ccCount+$bccCount == 0)
568
+		if ($toCount + $ccCount + $bccCount == 0)
569 569
 		{
570 570
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
571 571
 		}
572
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
572
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
573 573
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
574 574
 /*
575 575
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -586,26 +586,26 @@  discard block
 block discarded – undo
586 586
 		{
587 587
 			// now get on, and fetch the original mail
588 588
 			$uid = $smartdata->source->itemid;
589
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
589
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
590 590
 			$this->splitID($smartdata->source->folderid, $account, $folder);
591 591
 
592 592
 			$this->mail->reopen($folder);
593 593
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
594
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
595
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
596
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
594
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
595
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
596
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
597 597
 				// may be html
598
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
598
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
599 599
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
600 600
 				$isreply = true;
601 601
 			}
602 602
 			// plain text Message part
603
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
603
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
604 604
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
605
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
606
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
607
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
608
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
605
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
606
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
607
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
608
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
609 609
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
610 610
 				$isreply = true;
611 611
 			}
@@ -613,12 +613,12 @@  discard block
 block discarded – undo
613 613
 			{
614 614
 				$isreply = true;
615 615
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
616
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
616
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
617 617
 			}
618 618
 		}
619 619
 
620 620
 		// how to forward and other prefs
621
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
621
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
622 622
 
623 623
 		// forward -------------------------------------------------------------------------
624 624
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 		{
629 629
 			//force the default for the forwarding -> asmail
630 630
 			if (is_array($preferencesArray)) {
631
-				if (!array_key_exists('message_forwarding',$preferencesArray)
631
+				if (!array_key_exists('message_forwarding', $preferencesArray)
632 632
 					|| !isset($preferencesArray['message_forwarding'])
633 633
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
634 634
 			} else {
@@ -636,18 +636,18 @@  discard block
 block discarded – undo
636 636
 			}
637 637
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
638 638
 			$uid = $smartdata->source->itemid;
639
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
639
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
640 640
 			$this->splitID($smartdata->source->folderid, $account, $folder);
641 641
 
642 642
 			$this->mail->reopen($folder);
643 643
             // receive entire mail (header + body)
644 644
 			// get message headers for specified message
645
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
645
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
646 646
 			// build a new mime message, forward entire old mail as file
647 647
 			if ($preferencesArray['message_forwarding'] == 'asmail')
648 648
 			{
649
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
650
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
649
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
650
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
651 651
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
652 652
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
653 653
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -657,50 +657,50 @@  discard block
 block discarded – undo
657 657
 			{
658 658
 				// now get on, and fetch the original mail
659 659
 				$uid = $smartdata->source->itemid;
660
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
660
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
661 661
 				$this->splitID($smartdata->source->folderid, $account, $folder);
662 662
 
663 663
 				$this->mail->reopen($folder);
664 664
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
665
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
666
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
667
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
665
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
666
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
667
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
668 668
 					// may be html
669
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
669
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
670 670
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
671 671
 					$isforward = true;
672 672
 				}
673 673
 				// plain text Message part
674
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
674
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
675 675
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
676
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
677
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
678
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
679
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
676
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
677
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
678
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
679
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
680 680
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
681 681
 					$isforward = true;
682 682
 				}
683 683
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
684 684
 				{
685 685
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
686
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
686
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
687 687
 					$isforward = true;
688 688
 				}
689 689
 				// get all the attachments and add them too.
690 690
 				// start handle Attachments
691 691
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
692
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
692
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
693 693
 				$attachmentNames = false;
694
-				if (is_array($attachments) && count($attachments)>0)
694
+				if (is_array($attachments) && count($attachments) > 0)
695 695
 				{
696
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
697
-					foreach((array)$attachments as $key => $attachment)
696
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
697
+					foreach ((array)$attachments as $key => $attachment)
698 698
 					{
699
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
699
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
700 700
 						$attachmentNames .= $attachment['name']."\n";
701
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
701
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
702 702
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
703
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
703
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
704 704
 					}
705 705
 				}
706 706
 			}
@@ -715,38 +715,38 @@  discard block
 block discarded – undo
715 715
 		// now set the body
716 716
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
717 717
 		{
718
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
718
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
719 719
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
720
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
720
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
721 721
 		}
722 722
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
723 723
 		{
724
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
724
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
725 725
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
726
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
726
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
727 727
 		}
728 728
 		//advanced debugging
729 729
 		// Horde SMTP Class uses utf-8 by default.
730 730
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
731
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
731
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
732 732
 
733 733
 		// set a higher timeout for big messages
734 734
 		@set_time_limit(120);
735
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
735
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
736 736
 		// send
737 737
 		$send = true;
738 738
 		try {
739 739
 			$mailObject->Send();
740 740
 		}
741
-		catch(Exception $e) {
742
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
741
+		catch (Exception $e) {
742
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
743 743
 			$send = false;
744 744
 		}
745 745
 
746
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
746
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
747 747
 		{
748 748
 			$uid = $smartdata->source->itemid;
749
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
749
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
750 750
 			$this->splitID($smartdata->source->folderid, $account, $folder);
751 751
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
752 752
 			$this->mail->reopen($folder);
@@ -754,90 +754,90 @@  discard block
 block discarded – undo
754 754
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
755 755
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
756 756
 			{
757
-				$this->mail->deleteMessages(array($uid),$folder);
757
+				$this->mail->deleteMessages(array($uid), $folder);
758 758
 			} else {
759
-				$this->mail->flagMessages("answered", array($uid),$folder);
760
-				if ($smartdata_task== "forward")
759
+				$this->mail->flagMessages("answered", array($uid), $folder);
760
+				if ($smartdata_task == "forward")
761 761
 				{
762
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
762
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
763 763
 				}
764 764
 			}
765 765
 		}
766 766
 
767
-		$asf = ($send ? true:false); // initalize accordingly
768
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
767
+		$asf = ($send ? true : false); // initalize accordingly
768
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
769 769
 		{
770 770
 			$asf = false;
771 771
 			$sentFolder = $this->mail->getSentFolder();
772 772
 			if ($this->_sentID) {
773 773
 				$folderArray[] = $this->_sentID;
774 774
 			}
775
-			else if(isset($sentFolder) && $sentFolder != 'none')
775
+			else if (isset($sentFolder) && $sentFolder != 'none')
776 776
 			{
777 777
 				$folderArray[] = $sentFolder;
778 778
 			}
779 779
 			// No Sent folder set, try defaults
780 780
 			else
781 781
 			{
782
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
782
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
783 783
 				// we dont try guessing
784 784
 				$asf = true;
785 785
 			}
786 786
 			if (count($folderArray) > 0) {
787
-				foreach((array)$bccMailAddr as $address) {
788
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
789
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
787
+				foreach ((array)$bccMailAddr as $address) {
788
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
789
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
790 790
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
791 791
 					}
792 792
 				}
793 793
 				//$BCCmail='';
794
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
794
+				if (count($mailAddr) > 0) $mailObject->forceBccHeader();
795 795
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
796
-				foreach($folderArray as $folderName) {
797
-					if($this->mail->isSentFolder($folderName)) {
796
+				foreach ($folderArray as $folderName) {
797
+					if ($this->mail->isSentFolder($folderName)) {
798 798
 						$flags = '\\Seen';
799
-					} elseif($this->mail->isDraftFolder($folderName)) {
799
+					} elseif ($this->mail->isDraftFolder($folderName)) {
800 800
 						$flags = '\\Draft';
801 801
 					} else {
802 802
 						$flags = '';
803 803
 					}
804 804
 					$asf = true;
805 805
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
806
-					$this->mail->openConnection(self::$profileID,false);
806
+					$this->mail->openConnection(self::$profileID, false);
807 807
 					if ($this->mail->folderExists($folderName)) {
808 808
 						try
809 809
 						{
810
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
810
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
811 811
 									$flags);
812 812
 						}
813 813
 						catch (Api\Exception\WrongUserinput $e)
814 814
 						{
815 815
 							//$asf = false;
816
-							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()));
816
+							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()));
817 817
 						}
818 818
 					}
819 819
 					else
820 820
 					{
821 821
 						//$asf = false;
822
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
822
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
823 823
 					}
824
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
824
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
825 825
 				}
826 826
 				//$this->mail->closeConnection();
827 827
 			}
828 828
 		}
829 829
 
830
-		$this->debugLevel=0;
830
+		$this->debugLevel = 0;
831 831
 
832 832
 		if ($send && $asf)
833 833
 		{
834
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
834
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
835 835
 			return true;
836 836
 		}
837 837
 		else
838 838
 		{
839
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
840
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
839
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
840
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
841 841
 		}
842 842
 	}
843 843
 
@@ -855,43 +855,43 @@  discard block
 block discarded – undo
855 855
 	public function GetMessage($folderid, $id, $contentparameters)
856 856
 	{
857 857
 		//$this->debugLevel=4;
858
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
858
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
859 859
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
860 860
 		$mimesupport = $contentparameters->GetMimeSupport();
861
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
861
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
862 862
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
863 863
 
864 864
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
865 865
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
866 866
 
867 867
 		//$this->debugLevel=4;
868
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
869
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
868
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
869
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
870 870
 		$account = $_folderName = $xid = null;
871
-		$this->splitID($folderid,$account,$_folderName,$xid);
871
+		$this->splitID($folderid, $account, $_folderName, $xid);
872 872
 		$this->mail->reopen($_folderName);
873
-		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
873
+		$messages = $this->fetchMessages($folderid, NULL, $id, true); // true: return all headers
874 874
 		$headers = $messages[$id];
875
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
875
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($headers));
876 876
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
877 877
 		if ($headers)
878 878
 		{
879
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($headers));
879
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($headers));
880 880
 			// initialize the object
881 881
 			$output = new SyncMail();
882 882
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
883 883
 			// simple style
884 884
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
885
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
885
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
886 886
 
887 887
 			if ($bodypreference === false) {
888
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
889
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
888
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
889
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
890 890
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
891
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
891
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
892 892
 				// remove all other html
893 893
 				$body = strip_tags($raw_body);
894
-				if(strlen($body) > $truncsize) {
894
+				if (strlen($body) > $truncsize) {
895 895
 					$body = Utils::Utf8_truncate($body, $truncsize);
896 896
 					$output->bodytruncated = 1;
897 897
 				}
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
 			else // style with bodypreferences
906 906
 			{
907 907
 				//Select body type preference
908
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
908
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
909 909
 				if ($bodypreference !== false) {
910 910
 					// bodypreference can occur multiple times
911 911
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -919,12 +919,12 @@  discard block
 block discarded – undo
919 919
 					}
920 920
 */
921 921
 				}
922
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
922
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
923 923
 				// set the protocoll class
924 924
 				$output->asbody = new SyncBaseBody();
925 925
 
926 926
 				// return full mime-message without any (charset) conversation directly as stream
927
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
927
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)
928 928
 				{
929 929
 					//SYNC_BODYPREFERENCE_MIME
930 930
 					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
@@ -933,58 +933,58 @@  discard block
 block discarded – undo
933 933
 					fseek($stream, 0, SEEK_SET);
934 934
 					$output->asbody->data = $stream;
935 935
 					$output->asbody->estimatedDataSize = $fstat['size'];
936
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
936
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
937 937
 				}
938 938
 				else
939 939
 				{
940 940
 					// fetch the body (try to gather data only once)
941
-					$css ='';
942
-					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
943
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
944
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
945
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
946
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
941
+					$css = '';
942
+					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
943
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
944
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
945
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
946
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
947 947
 						// may be html
948
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
948
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
949 949
 						$css = $this->mail->getStyles($bodyStruct);
950
-						$output->nativebodytype=2;
950
+						$output->nativebodytype = 2;
951 951
 					} else {
952 952
 						// plain text Message
953
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
954
-						$output->nativebodytype=1;
955
-						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
956
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
957
-						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
958
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
953
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
954
+						$output->nativebodytype = 1;
955
+						$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
956
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
957
+						$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
958
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
959 959
 					}
960 960
 					// whatever format decode (using the correct encoding)
961
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
961
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
962 962
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
963 963
 					// prepare plaintextbody
964
-					$plainBody='';
964
+					$plainBody = '';
965 965
 					if ($output->nativebodytype == 2)
966 966
 					{
967
-						$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
968
-						if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
967
+						$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
968
+						if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
969 969
 						{
970 970
 							$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
971 971
 						}
972 972
 						else
973 973
 						{
974
-							$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
974
+							$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
975 975
 						}
976 976
 					}
977 977
 					//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
978
-					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
978
+					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
979 979
 					// remove all other html
980
-					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
980
+					$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
981 981
 					$plainBody = strip_tags($plainBody);
982
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
982
+					if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
983 983
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
984 984
 
985
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
985
+					if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
986 986
 					{
987
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
987
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
988 988
 						// Send HTML if requested and native type was html
989 989
 						$output->asbody->type = 2;
990 990
 						$htmlbody = '<html>'.
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 							$css.
995 995
 							'</head>'.
996 996
 							'<body>';
997
-						if ($output->nativebodytype==2)
997
+						if ($output->nativebodytype == 2)
998 998
 						{
999 999
 							// as we fetch html, and body is HTML, we may not need to handle this
1000 1000
 							$htmlbody .= $body;
@@ -1002,14 +1002,14 @@  discard block
 block discarded – undo
1002 1002
 						else
1003 1003
 						{
1004 1004
 							// html requested but got only plaintext, so fake html
1005
-							$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
1005
+							$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
1006 1006
 						}
1007 1007
 						$htmlbody .= '</body>'.
1008 1008
 								'</html>';
1009 1009
 
1010
-						if(isset($truncsize) && strlen($htmlbody) > $truncsize)
1010
+						if (isset($truncsize) && strlen($htmlbody) > $truncsize)
1011 1011
 						{
1012
-							$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
1012
+							$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
1013 1013
 							$output->asbody->truncated = 1;
1014 1014
 						}
1015 1015
 						// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 					else
1021 1021
 					{
1022 1022
 						// Send Plaintext as Fallback or if original body is plainttext
1023
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1023
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1024 1024
 						/* we use plainBody (set above) instead
1025 1025
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1026 1026
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 						*/
1031 1031
 						$output->asbody->type = 1;
1032 1032
 						$output->nativebodytype = 1;
1033
-						if(isset($truncsize) &&
1033
+						if (isset($truncsize) &&
1034 1034
 							strlen($plainBody) > $truncsize)
1035 1035
 						{
1036 1036
 							$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 				}
1050 1050
 			}
1051 1051
 			// end AS12 Stuff
1052
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1052
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1053 1053
 			$output->read = $headers["flags"];
1054 1054
 
1055 1055
 			$output->flag = new SyncMailFlags();
@@ -1069,9 +1069,8 @@  discard block
 block discarded – undo
1069 1069
 				$output->lastverexecuted = AS_FORWARD;
1070 1070
 			}
1071 1071
 			$output->subject = $headers['subject'];
1072
-			$output->importance = $headers['priority'] > 3 ? 0 :
1073
-				($headers['priority'] < 3 ? 2 : 1) ;
1074
-			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1072
+			$output->importance = $headers['priority'] > 3 ? 0 : ($headers['priority'] < 3 ? 2 : 1);
1073
+			$output->datereceived = $this->mail->_strtotime($headers['date'], 'ts', true);
1075 1074
 			$output->to = $headers['to_address'];
1076 1075
 			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1077 1076
 			$output->from = $headers['sender_address'];
@@ -1079,8 +1078,8 @@  discard block
 block discarded – undo
1079 1078
 			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1080 1079
 
1081 1080
 			$output->messageclass = "IPM.Note";
1082
-			if (stripos($headers['mimetype'],'multipart')!== false &&
1083
-				stripos($headers['mimetype'],'signed')!== false)
1081
+			if (stripos($headers['mimetype'], 'multipart') !== false &&
1082
+				stripos($headers['mimetype'], 'signed') !== false)
1084 1083
 			{
1085 1084
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1086 1085
 			}
@@ -1089,20 +1088,20 @@  discard block
 block discarded – undo
1089 1088
 			}
1090 1089
 
1091 1090
 			// start handle Attachments (include text/calendar multipart alternative)
1092
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1091
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1093 1092
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1094
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1093
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1095 1094
 			{
1096
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1095
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1097 1096
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1098 1097
 				foreach ($attachments as $key => $attach)
1099 1098
 				{
1100
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1099
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1101 1100
 
1102 1101
 					// pass meeting requests to calendar plugin
1103 1102
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1104 1103
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1105
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1104
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1106 1105
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1107 1106
 					{
1108 1107
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1112,7 +1111,7 @@  discard block
 block discarded – undo
1112 1111
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1113 1112
 						//$output->messageclass = "IPM.Schedule.Meeting";
1114 1113
 						unset($attachment);
1115
-						continue;	// do NOT add attachment as attachment
1114
+						continue; // do NOT add attachment as attachment
1116 1115
 					}
1117 1116
 					if (Request::GetProtocolVersion() >= 12.0) {
1118 1117
 						$attachment = new SyncBaseAttachment();
@@ -1120,33 +1119,33 @@  discard block
 block discarded – undo
1120 1119
 							$output->asattachments = array();
1121 1120
 						$attachment->estimatedDataSize = $attach['size'];
1122 1121
 						$attachment->method = 1;
1123
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1122
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1124 1123
 					} else {
1125 1124
 						$attachment = new SyncAttachment();
1126 1125
 						if (!isset($output->attachments) || !is_array($output->attachments))
1127 1126
 							$output->attachments = array();
1128 1127
 						$attachment->attsize = $attach['size'];
1129 1128
 						$attachment->attmethod = 1;
1130
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1129
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1131 1130
 					}
1132 1131
 
1133 1132
 					$attachment->displayname = $attach['name'];
1134 1133
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1135 1134
 
1136
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1135
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1137 1136
 					//$attachment->isinline=0; // if not inline, do not use isinline
1138
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1137
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1139 1138
 					{
1140 1139
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1141 1140
 						{
1142 1141
 							$attachment->isinline = true;
1143 1142
 						}
1144 1143
 						if (Request::GetProtocolVersion() >= 12.0) {
1145
-							$attachment->method=1;
1146
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1144
+							$attachment->method = 1;
1145
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1147 1146
 						} else {
1148
-							$attachment->attmethod=6;
1149
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1147
+							$attachment->attmethod = 6;
1148
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1150 1149
 						}
1151 1150
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1152 1151
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1167,7 +1166,7 @@  discard block
 block discarded – undo
1167 1166
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1168 1167
             $output->internetcpid = INTERNET_CPID_UTF8;
1169 1168
 
1170
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1169
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1171 1170
 //$this->debugLevel=0;
1172 1171
 			return $output;
1173 1172
 		}
@@ -1190,30 +1189,30 @@  discard block
 block discarded – undo
1190 1189
 	{
1191 1190
 		if (!class_exists('calendar_zpush'))
1192 1191
 		{
1193
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1192
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1194 1193
 			return null;
1195 1194
 		}
1196 1195
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1197 1196
 		{
1198
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1197
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1199 1198
 			return false;
1200 1199
 		}
1201 1200
 		$ret = false;
1202
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1201
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1203 1202
 		{
1204 1203
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1205
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1204
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1206 1205
 			{
1207
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1206
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1208 1207
 
1209 1208
 				// calling backend again with iCal attachment, to let calendar add the event
1210 1209
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1211
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1210
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1212 1211
 					$response);
1213 1212
 				break;
1214 1213
 			}
1215 1214
 		}
1216
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1215
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1217 1216
 		return $ret;
1218 1217
 	}
1219 1218
 
@@ -1227,9 +1226,9 @@  discard block
 block discarded – undo
1227 1226
      * @param string $attname - should contain (folder)id
1228 1227
 	 * @return SyncItemOperationsAttachment-object
1229 1228
 	 */
1230
-	function GetAttachmentData($fid,$attname) {
1231
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1232
-		return $this->_GetAttachmentData($fid,$attname);
1229
+	function GetAttachmentData($fid, $attname) {
1230
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1231
+		return $this->_GetAttachmentData($fid, $attname);
1233 1232
 	}
1234 1233
 
1235 1234
 	/**
@@ -1242,9 +1241,9 @@  discard block
 block discarded – undo
1242 1241
      * @param string $attname - should contain (folder)id
1243 1242
 	 * @return SyncItemOperationsAttachment-object
1244 1243
 	 */
1245
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1246
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1247
-		return $this->_GetAttachmentData($fid,$attname);
1244
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1245
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1246
+		return $this->_GetAttachmentData($fid, $attname);
1248 1247
 	}
1249 1248
 
1250 1249
 	/**
@@ -1256,23 +1255,23 @@  discard block
 block discarded – undo
1256 1255
      * @param string $attname - should contain (folder)id
1257 1256
 	 * @return SyncItemOperationsAttachment-object
1258 1257
 	 */
1259
-	private function _GetAttachmentData($fid,$attname)
1258
+	private function _GetAttachmentData($fid, $attname)
1260 1259
 	{
1261
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1260
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1262 1261
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1263 1262
 		list($folderid, $id, $part) = explode(":", $attname);
1264 1263
 
1265 1264
 		$this->splitID($folderid, $account, $folder);
1266 1265
 
1267
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1266
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1268 1267
 
1269 1268
 		$this->mail->reopen($folder);
1270
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1269
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1271 1270
 		$SIOattachment = new SyncItemOperationsAttachment();
1272
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1271
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1273 1272
 		$SIOattachment->data = $attachment['attachment'];
1274 1273
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1275
-		if (isset($attachment['type']) )
1274
+		if (isset($attachment['type']))
1276 1275
 			$SIOattachment->contenttype = $attachment['type'];
1277 1276
 
1278 1277
 		unset($attachment);
@@ -1315,17 +1314,17 @@  discard block
 block discarded – undo
1315 1314
 	 */
1316 1315
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1317 1316
 	{
1318
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1317
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1319 1318
 		//unset($folderid, $id, $message, $contentParameters);
1320 1319
 		$account = $folder = null;
1321 1320
 		$this->splitID($folderid, $account, $folder);
1322 1321
 		if (isset($message->flag)) {
1323 1322
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1324
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1325
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1323
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1324
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1326 1325
 			} else {
1327
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1328
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1326
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1327
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1329 1328
 			}
1330 1329
 		}
1331 1330
 		return $this->StatMessage($folderid, $id);
@@ -1347,23 +1346,23 @@  discard block
 block discarded – undo
1347 1346
 	 */
1348 1347
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1349 1348
 	{
1350
-		unset($contentParameters);	// not used, but required by function signature
1349
+		unset($contentParameters); // not used, but required by function signature
1351 1350
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1352 1351
 		$account = $srcFolder = $destFolder = null;
1353 1352
 		$this->splitID($folderid, $account, $srcFolder);
1354 1353
 		$this->splitID($newfolderid, $account, $destFolder);
1355 1354
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1356
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1355
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1357 1356
 		$this->mail->reopen($destFolder);
1358 1357
 		$status = $this->mail->getFolderStatus($destFolder);
1359 1358
 		$uidNext = $status['uidnext'];
1360 1359
 		$this->mail->reopen($srcFolder);
1361 1360
 
1362 1361
 		// move message
1363
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1364
-		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
1362
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1363
+		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
1365 1364
 		// return the new id "as string"
1366
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1365
+		return ($rv === true ? $uidNext : $rv[$id])."";
1367 1366
 	}
1368 1367
 
1369 1368
 	/**
@@ -1371,7 +1370,7 @@  discard block
 block discarded – undo
1371 1370
 	 *
1372 1371
 	 *  @param int $cutoffdate =null timestamp with cutoffdate, default 12 weeks
1373 1372
 	 */
1374
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1373
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1375 1374
 	{
1376 1375
 		if ($cutoffdate > 0)
1377 1376
 		{
@@ -1384,14 +1383,14 @@  discard block
 block discarded – undo
1384 1383
 			{
1385 1384
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1386 1385
 			}
1387
-			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1388
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1386
+			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now', 'ts') - (3600 * 24 * $maximumSyncRangeInDays) : null);
1387
+			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1389 1388
 		}
1390 1389
 		try {
1391 1390
 			return $this->fetchMessages($folderid, $cutoffdate);
1392 1391
 		} catch (Exception $e)
1393 1392
 		{
1394
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details?$e->details:''));
1393
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details ? $e->details : ''));
1395 1394
 			return array();
1396 1395
 		}
1397 1396
 	}
@@ -1409,11 +1408,11 @@  discard block
 block discarded – undo
1409 1408
 	 * @param boolean $return_all_headers =false true: additinal contain all headers eg. "subject"
1410 1409
 	 * @return array uid => array StatMessage($folderid, $_id)
1411 1410
 	 */
1412
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL, $return_all_headers=false)
1411
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL, $return_all_headers = false)
1413 1412
 	{
1414 1413
 		static $headers = array();
1415 1414
 
1416
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1415
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1417 1416
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1418 1417
 		$rv_messages = array();
1419 1418
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1424,64 +1423,64 @@  discard block
 block discarded – undo
1424 1423
 		}
1425 1424
 		else
1426 1425
 		{
1427
-			$headers = array();	// clear cache to not use too much memory
1426
+			$headers = array(); // clear cache to not use too much memory
1428 1427
 
1429
-			if ($this->debugLevel>1) $starttime = microtime (true);
1428
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1430 1429
 			$this->_connect($this->account);
1431
-			if ($this->debugLevel>1)
1430
+			if ($this->debugLevel > 1)
1432 1431
 			{
1433 1432
 				$endtime = microtime(true) - $starttime;
1434
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1433
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1435 1434
 			}
1436 1435
 			$messagelist = $_filter = array();
1437 1436
 			// if not connected, any further action must fail
1438
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1439
-			if ($this->debugLevel>1) $starttime = microtime (true);
1437
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1438
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1440 1439
 			$account = $_folderName = $id = null;
1441
-			$this->splitID($folderid,$account,$_folderName,$id);
1442
-			if ($this->debugLevel>1)
1440
+			$this->splitID($folderid, $account, $_folderName, $id);
1441
+			if ($this->debugLevel > 1)
1443 1442
 			{
1444 1443
 				$endtime = microtime(true) - $starttime;
1445
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1444
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1446 1445
 			}
1447
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1448
-			if ($this->debugLevel>1) $starttime = microtime (true);
1449
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1450
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1451
-			if ($this->debugLevel>1)
1446
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1447
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1448
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1449
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1450
+			if ($this->debugLevel > 1)
1452 1451
 			{
1453 1452
 				$endtime = microtime(true) - $starttime;
1454
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1453
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1455 1454
 			}
1456 1455
 		}
1457
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1456
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1458 1457
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1459 1458
 		$messagelist = array();
1460
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1459
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1461 1460
 		//if ($_returnModHash) $messageFolderHash = array();
1462 1461
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1463 1462
 		{
1464
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1463
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1465 1464
 			$headers[$vars['uid']] = $vars;
1466
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1465
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1467 1466
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1468 1467
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1469
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1468
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1470 1469
 			$mess = $return_all_headers ? $vars : array();
1471 1470
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1472 1471
 			$mess["id"] = $vars['uid'];
1473 1472
 			// 'seen' aka 'read' is the only flag we want to know about
1474 1473
 			$mess["flags"] = 0;
1475 1474
 			// outlook supports additional flags, set them to 0
1476
-			if($vars["seen"]) $mess["flags"] = 1;
1477
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1475
+			if ($vars["seen"]) $mess["flags"] = 1;
1476
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1478 1477
 			$messagelist[$vars['uid']] = $mess;
1479 1478
 			unset($mess);
1480 1479
 		}
1481
-		if ($this->debugLevel>1)
1480
+		if ($this->debugLevel > 1)
1482 1481
 		{
1483 1482
 			$endtime = microtime(true) - $gstarttime;
1484
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1483
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1485 1484
 		}
1486 1485
 		return $messagelist;
1487 1486
 	}
@@ -1532,32 +1531,32 @@  discard block
 block discarded – undo
1532 1531
 	public function getSearchResultsMailbox($_searchquery)
1533 1532
 	{
1534 1533
 		//$this->debugLevel=1;
1535
-		$searchquery=$_searchquery->GetDataArray();
1534
+		$searchquery = $_searchquery->GetDataArray();
1536 1535
 		if (!is_array($searchquery)) return array();
1537
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1536
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1538 1537
 
1539 1538
 		if (isset($searchquery['searchrebuildresults'])) {
1540 1539
 			$rebuildresults = $searchquery['searchrebuildresults'];
1541 1540
 		} else {
1542 1541
 			$rebuildresults = false;
1543 1542
 		}
1544
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1543
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1545 1544
 
1546 1545
 		if (isset($searchquery['deeptraversal'])) {
1547 1546
 			$deeptraversal = $searchquery['deeptraversal'];
1548 1547
 		} else {
1549 1548
 			$deeptraversal = false;
1550 1549
 		}
1551
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1550
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1552 1551
 
1553 1552
 		if (isset($searchquery['searchrange'])) {
1554
-			$range = explode("-",$_searchquery->GetSearchRange());
1555
-			$start =$range[0] + 1;
1553
+			$range = explode("-", $_searchquery->GetSearchRange());
1554
+			$start = $range[0] + 1;
1556 1555
 			$limit = $range[1] - $range[0] + 1;
1557 1556
 		} else {
1558 1557
 			$range = false;
1559 1558
 		}
1560
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1559
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1561 1560
 
1562 1561
 		//foreach($searchquery['query'] as $k => $value) {
1563 1562
 		//	$query = $value;
@@ -1580,15 +1579,15 @@  discard block
 block discarded – undo
1580 1579
 		}
1581 1580
 		if (!$folderid)
1582 1581
 		{
1583
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1584
-			$folderid = $this->createID($account=0,$_folderName);
1582
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1583
+			$folderid = $this->createID($account = 0, $_folderName);
1585 1584
 		}
1586
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1587
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1585
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1586
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1588 1587
 		$this->_connect($account);
1589 1588
 		// this should not be needed ???
1590
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1591
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1589
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1590
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1592 1591
 						 'string'=> $searchText,
1593 1592
 						 'status'=>'any'
1594 1593
 						);
@@ -1603,22 +1602,22 @@  discard block
 block discarded – undo
1603 1602
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1604 1603
 		 */
1605 1604
 			$_filter['range'] = "BETWEEN";
1606
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1607
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1608
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1609
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1605
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1606
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1607
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1608
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1610 1609
 		}
1611 1610
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1612
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1613
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1611
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1612
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1614 1613
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1615
-		$list=array();
1614
+		$list = array();
1616 1615
 
1617 1616
 		$cnt = count($rv_messages['header']);
1618 1617
 		//$list['status'] = 1;
1619 1618
 		$list['searchtotal'] = $cnt;
1620 1619
 		$list["range"] = $_searchquery->GetSearchRange();
1621
-		foreach((array)$rv_messages['header'] as $i => $vars)
1620
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1622 1621
 		{
1623 1622
 			$list[] = array(
1624 1623
 				"class" => "Email",
@@ -1638,20 +1637,20 @@  discard block
 block discarded – undo
1638 1637
 	 * @param string $folder
1639 1638
 	 * @return string
1640 1639
 	 */
1641
-	private function getParentID($account,$folder)
1640
+	private function getParentID($account, $folder)
1642 1641
 	{
1643 1642
 		$this->_connect($account);
1644
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1643
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1645 1644
 
1646 1645
 		$mailFolder = $this->folders[$folder];
1647 1646
 		if (!isset($mailFolder)) return false;
1648
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1649
-		$parent = explode($delimiter,$folder);
1647
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1648
+		$parent = explode($delimiter, $folder);
1650 1649
 		array_pop($parent);
1651
-		$parent = implode($delimiter,$parent);
1650
+		$parent = implode($delimiter, $parent);
1652 1651
 
1653 1652
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1654
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1653
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1655 1654
 		return $id;
1656 1655
 	}
1657 1656
 
@@ -1671,48 +1670,48 @@  discard block
 block discarded – undo
1671 1670
 			$account = $folder = null;
1672 1671
 			$this->splitID($id, $account, $folder);
1673 1672
 		}
1674
-		catch(Exception $e) {
1675
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1676
-			return $folderObj=false;
1673
+		catch (Exception $e) {
1674
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1675
+			return $folderObj = false;
1677 1676
 		}
1678 1677
 		$this->_connect($account);
1679
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1678
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1680 1679
 
1681 1680
 		$mailFolder = $this->folders[$folder];
1682
-		if (!isset($mailFolder)) return $folderObj=false;
1681
+		if (!isset($mailFolder)) return $folderObj = false;
1683 1682
 
1684 1683
 		$folderObj = new SyncFolder();
1685 1684
 		$folderObj->serverid = $id;
1686
-		$folderObj->parentid = $this->getParentID($account,$folder);
1685
+		$folderObj->parentid = $this->getParentID($account, $folder);
1687 1686
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1688
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1687
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1689 1688
 		// get folder-type
1690
-		foreach($this->folders as $inbox => $mailFolder) break;
1689
+		foreach ($this->folders as $inbox => $mailFolder) break;
1691 1690
 		if ($folder == $inbox)
1692 1691
 		{
1693 1692
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1694 1693
 		}
1695
-		elseif($this->mail->isDraftFolder($folder, false, true))
1694
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1696 1695
 		{
1697 1696
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1698 1697
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1699 1698
 			$folderObj->parentid = 0; // required by devices
1700 1699
 		}
1701
-		elseif($this->mail->isTrashFolder($folder, false, true))
1700
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1702 1701
 		{
1703 1702
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1704 1703
 			$this->_wasteID = $folder;
1705 1704
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1706 1705
 			$folderObj->parentid = 0; // required by devices
1707 1706
 		}
1708
-		elseif($this->mail->isSentFolder($folder, false, true))
1707
+		elseif ($this->mail->isSentFolder($folder, false, true))
1709 1708
 		{
1710 1709
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1711 1710
 			$folderObj->parentid = 0; // required by devices
1712 1711
 			$this->_sentID = $folder;
1713 1712
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1714 1713
 		}
1715
-		elseif($this->mail->isOutbox($folder, false, true))
1714
+		elseif ($this->mail->isOutbox($folder, false, true))
1716 1715
 		{
1717 1716
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1718 1717
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1724,7 +1723,7 @@  discard block
 block discarded – undo
1724 1723
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1725 1724
 		}
1726 1725
 
1727
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1726
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1728 1727
 		return $folderObj;
1729 1728
 	}
1730 1729
 
@@ -1772,24 +1771,24 @@  discard block
 block discarded – undo
1772 1771
 
1773 1772
 		if ($type != 'mail') return false;
1774 1773
 
1775
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1774
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1776 1775
 		if (!$this->mail->folderIsSelectable($folder))
1777 1776
 		{
1778
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not select folder $folder returning fake state");
1777
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not select folder $folder returning fake state");
1779 1778
 			$syncstate = "M:".'0'."-R:".'0'."-U:".'0'."-NUID:".'0'."-UIDV:".'0';
1780 1779
 			return array();
1781 1780
 		}
1782 1781
 
1783 1782
 		$this->mail->reopen($folder);
1784 1783
 
1785
-		if (!($status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true)))
1784
+		if (!($status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true)))
1786 1785
 		{
1787
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1786
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1788 1787
 			return false;
1789 1788
 		}
1790
-		$syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1789
+		$syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1791 1790
 
1792
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1791
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1793 1792
 		return array();
1794 1793
 	}
1795 1794
 
@@ -1802,8 +1801,8 @@  discard block
 block discarded – undo
1802 1801
 	function GetWasteBasket()
1803 1802
 	{
1804 1803
 		$this->_connect($this->account);
1805
-		$id = $this->createID($account=0, $this->_wasteID);
1806
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1804
+		$id = $this->createID($account = 0, $this->_wasteID);
1805
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1807 1806
 		return $id;
1808 1807
 	}
1809 1808
 
@@ -1824,7 +1823,7 @@  discard block
 block discarded – undo
1824 1823
      */
1825 1824
     public function DeleteMessage($folderid, $id, $contentParameters)
1826 1825
 	{
1827
-		unset($contentParameters);	// not used, but required by function signature
1826
+		unset($contentParameters); // not used, but required by function signature
1828 1827
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1829 1828
 		/*
1830 1829
 		$this->imap_reopenFolder($folderid);
@@ -1835,7 +1834,7 @@  discard block
 block discarded – undo
1835 1834
 		// we may have to split folderid
1836 1835
 		$account = $folder = null;
1837 1836
 		$this->splitID($folderid, $account, $folder);
1838
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1837
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1839 1838
 		$_messageUID = (array)$id;
1840 1839
 
1841 1840
 		$this->_connect($this->account);
@@ -1847,9 +1846,9 @@  discard block
 block discarded – undo
1847 1846
 		catch (Api\Exception $e)
1848 1847
 		{
1849 1848
 			$error = $e->getMessage();
1850
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1849
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1851 1850
 			// if the server thinks the message does not exist report deletion as success
1852
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1851
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1853 1852
 			return false;
1854 1853
 		}
1855 1854
 
@@ -1883,15 +1882,15 @@  discard block
 block discarded – undo
1883 1882
      */
1884 1883
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1885 1884
 	{
1886
-		unset($contentParameters);	// not used, but required by function signature
1885
+		unset($contentParameters); // not used, but required by function signature
1887 1886
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1888 1887
 		$account = $folder = null;
1889 1888
 		$this->splitID($folderid, $account, $folder);
1890 1889
 
1891 1890
 		$_messageUID = (array)$id;
1892 1891
 		$this->_connect($this->account);
1893
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1894
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1892
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1893
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1895 1894
 
1896 1895
 		return $rv;
1897 1896
 	}
@@ -1908,7 +1907,7 @@  discard block
 block discarded – undo
1908 1907
 	 */
1909 1908
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1910 1909
 	{
1911
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1910
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1912 1911
 		return false;
1913 1912
 	}
1914 1913
 
@@ -1923,7 +1922,7 @@  discard block
 block discarded – undo
1923 1922
 	 */
1924 1923
 	public function DeleteFolder($parentid, $id)
1925 1924
 	{
1926
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$parentid', '$id') NOT supported!");
1925
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$parentid', '$id') NOT supported!");
1927 1926
 		return false;
1928 1927
 	}
1929 1928
 
@@ -1943,8 +1942,8 @@  discard block
 block discarded – undo
1943 1942
 		$this->_connect($this->account);
1944 1943
 		$account = $folder = null;
1945 1944
 		$this->splitID($folderid, $account, $folder);
1946
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1947
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1945
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1946
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1948 1947
 
1949 1948
 		return $rv;
1950 1949
 	}
@@ -1958,17 +1957,17 @@  discard block
 block discarded – undo
1958 1957
 	 * @return string
1959 1958
 	 * @throws Api\Exception\WrongParameter
1960 1959
 	 */
1961
-	private function createID($account,$folder,$id=0)
1960
+	private function createID($account, $folder, $id = 0)
1962 1961
 	{
1963 1962
 		if (!is_numeric($folder))
1964 1963
 		{
1965 1964
 			// convert string $folder in numeric id
1966
-			$folder = $this->folder2hash($account,$f=$folder);
1965
+			$folder = $this->folder2hash($account, $f = $folder);
1967 1966
 		}
1968 1967
 
1969 1968
 		$str = $this->backend->createID($account, $folder, $id);
1970 1969
 
1971
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1970
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1972 1971
 
1973 1972
 		return $str;
1974 1973
 	}
@@ -1982,14 +1981,14 @@  discard block
 block discarded – undo
1982 1981
 	 * @param int &$id=null
1983 1982
 	 * @throws Api\Exception\WrongParameter
1984 1983
 	 */
1985
-	private function splitID($str,&$account,&$folder,&$id=null)
1984
+	private function splitID($str, &$account, &$folder, &$id = null)
1986 1985
 	{
1987 1986
 		$this->backend->splitID($str, $account, $folder, $id);
1988 1987
 
1989 1988
 		// convert numeric folder-id back to folder name
1990
-		$folder = $this->hash2folder($account,$f=$folder);
1989
+		$folder = $this->hash2folder($account, $f = $folder);
1991 1990
 
1992
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
1991
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$id)");
1993 1992
 	}
1994 1993
 
1995 1994
 	/**
@@ -2006,9 +2005,9 @@  discard block
 block discarded – undo
2006 2005
 	 * @param string $folder
2007 2006
 	 * @return int
2008 2007
 	 */
2009
-	private function folder2hash($account,$folder)
2008
+	private function folder2hash($account, $folder)
2010 2009
 	{
2011
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2010
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2012 2011
 
2013 2012
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2014 2013
 		{
@@ -2029,9 +2028,9 @@  discard block
 block discarded – undo
2029 2028
 	 * @param int $index
2030 2029
 	 * @return string NULL if not used so far
2031 2030
 	 */
2032
-	private function hash2folder($account,$index)
2031
+	private function hash2folder($account, $index)
2033 2032
 	{
2034
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2033
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2035 2034
 
2036 2035
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2037 2036
 	}
@@ -2068,9 +2067,9 @@  discard block
 block discarded – undo
2068 2067
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2069 2068
 				($hashes = file_get_contents($file)))
2070 2069
 			{
2071
-				$this->folderHashes = json_decode($hashes,true);
2070
+				$this->folderHashes = json_decode($hashes, true);
2072 2071
 				// fallback in case hashes have been serialized instead of being json-encoded
2073
-				if (json_last_error()!=JSON_ERROR_NONE)
2072
+				if (json_last_error() != JSON_ERROR_NONE)
2074 2073
 				{
2075 2074
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2076 2075
 					$this->folderHashes = unserialize($hashes);
@@ -2116,9 +2115,9 @@  discard block
 block discarded – undo
2116 2115
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2117 2116
 	 * @throws Api\Exception\AssertionFailed
2118 2117
 	 */
2119
-	private function hashFile($old=false)
2118
+	private function hashFile($old = false)
2120 2119
 	{
2121
-		if (!($dev_id=Request::GetDeviceID()))
2120
+		if (!($dev_id = Request::GetDeviceID()))
2122 2121
 		{
2123 2122
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2124 2123
 		}
Please login to merge, or discard this patch.