Stop using curly braces
[squirrelmail.git] / class / mime / Message.class.php
index 2bc35c623689e2bd93f535575a88fa6858cfe954..bc2545c4ba3f310bbb715fa085361c7a80221c96 100644 (file)
@@ -5,7 +5,7 @@
  *
  * This file contains functions needed to handle mime messages.
  *
- * @copyright 2003-2011 The SquirrelMail Project Team
+ * @copyright 2003-2021 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -292,7 +292,7 @@ class Message {
      * @return object Message object
      * @todo define argument and return types
      */
-    function parseStructure($read, &$i, $sub_msg = '') {
+    static function parseStructure($read, &$i, $sub_msg = '') {
         $msg = Message::parseBodyStructure($read, $i, $sub_msg);
         if($msg) $msg->setEntIds($msg,false,0);
         return $msg;
@@ -342,7 +342,7 @@ class Message {
      * @todo document me
      * @since 1.4.0 (code was part of parseStructure() in 1.3.x)
      */
-    function parseBodyStructure($read, &$i, $sub_msg = '') {
+    static function parseBodyStructure($read, &$i, $sub_msg = '') {
         $arg_no = 0;
         $arg_a  = array();
         if ($sub_msg) {
@@ -352,7 +352,7 @@ class Message {
         }
 
         for ($cnt = strlen($read); $i < $cnt; ++$i) {
-            $char = strtoupper($read{$i});
+            $char = strtoupper($read[$i]);
             switch ($char) {
                 case '(':
                     switch($arg_no) {
@@ -363,10 +363,11 @@ class Message {
                                 $hdr->type0 = 'text';
                                 $hdr->type1 = 'plain';
                                 $hdr->encoding = '7bit';
+                                $msg->header = $hdr;
                             } else {
                                 $msg->header->type0 = 'multipart';
                                 $msg->type0 = 'multipart';
-                                while ($read{$i} == '(') {
+                                while ($read[$i] == '(') {
                                     $msg->addEntity($msg->parseBodyStructure($read, $i, $msg));
                                 }
                             }
@@ -399,7 +400,7 @@ class Message {
                                 $msg->type1 = $arg_a[1];
                                 $rfc822_hdr = new Rfc822Header();
                                 $msg->rfc822_header = $msg->parseEnvelope($read, $i, $rfc822_hdr);
-                                while (($i < $cnt) && ($read{$i} != '(')) {
+                                while (($i < $cnt) && ($read[$i] != '(')) {
                                     ++$i;
                                 }
                                 $msg->addEntity($msg->parseBodyStructure($read, $i,$msg));
@@ -461,17 +462,17 @@ class Message {
                     $arg_a[] = $msg->parseLiteral($read, $i);
                     ++$arg_no;
                     break;
-        case '0':
-                case is_numeric($read{$i}):
+                case '0':
+                case is_numeric($read[$i]):
                     /* process integers */
-                    if ($read{$i} == ' ') { break; }
-            ++$arg_no;
-            if (preg_match('/^([0-9]+).*/',substr($read,$i), $regs)) {
-                $i += strlen($regs[1])-1;
-                $arg_a[] = $regs[1];
-            } else {
-                $arg_a[] = 0;
-            }
+                    if ($read[$i] == ' ') { break; }
+                    ++$arg_no;
+                    if (preg_match('/^([0-9]+).*/',substr($read,$i), $regs)) {
+                        $i += strlen($regs[1])-1;
+                        $arg_a[] = $regs[1];
+                    } else {
+                        $arg_a[] = 0;
+                    }
                     break;
                 case ')':
                     $multipart = (isset($msg->type0) && ($msg->type0 == 'multipart'));
@@ -526,11 +527,11 @@ class Message {
         $properties = array();
         $prop_name = '';
 
-        for (; $read{$i} != ')'; ++$i) {
+        for (; $read[$i] != ')'; ++$i) {
             $arg_s = '';
-            if ($read{$i} == '"') {
+            if ($read[$i] == '"') {
                 $arg_s = $this->parseQuote($read, $i);
-            } else if ($read{$i} == '{') {
+            } else if ($read[$i] == '{') {
                 $arg_s = $this->parseLiteral($read, $i);
             }
 
@@ -621,8 +622,8 @@ class Message {
         $arg_no = 0;
         $arg_a = array();
         ++$i;
-        for ($cnt = strlen($read); ($i < $cnt) && ($read{$i} != ')'); ++$i) {
-            $char = strtoupper($read{$i});
+        for ($cnt = strlen($read); ($i < $cnt) && ($read[$i] != ')'); ++$i) {
+            $char = strtoupper($read[$i]);
             switch ($char) {
                 case '"':
                     $arg_a[] = $this->parseQuote($read, $i);
@@ -651,8 +652,8 @@ class Message {
                     $addr_a = array();
                     $group = '';
                     $a=0;
-                    for (; $i < $cnt && $read{$i} != ')'; ++$i) {
-                        if ($read{$i} == '(') {
+                    for (; $i < $cnt && $read[$i] != ')'; ++$i) {
+                        if ($read[$i] == '(') {
                             $addr = $this->parseAddress($read, $i);
                             if (($addr->host == '') && ($addr->mailbox != '')) {
                                 /* start of group */
@@ -750,11 +751,11 @@ class Message {
         while (true) {
             $iPos = strpos($read,'"',$iPos);
             if (!$iPos) break;
-            if ($iPos && $read{$iPos -1} != '\\') {
+            if ($iPos && $read[$iPos -1] != '\\') {
                 $s = substr($read,$i,($iPos-$i));
                 $i = $iPos;
                 break;
-            } else if ($iPos > 1 && $read{$iPos -1} == '\\' && $read{$iPos-2} == '\\') {
+            } else if ($iPos > 1 && $read[$iPos -1] == '\\' && $read[$iPos-2] == '\\') {
                 // This is an unique situation where the fast detection of the string
                 // fails. If the quote string ends with \\ then we need to iterate
                 // through the entire string to make sure we detect the unexcaped
@@ -763,7 +764,7 @@ class Message {
                 $bEscaped = false;
                 $k = 0;
                  for ($j=$iPosStart,$iCnt=strlen($read);$j<$iCnt;++$j) {
-                    $cChar = $read{$j};
+                    $cChar = $read[$j];
                     switch ($cChar) {
                         case '\\':
                            $bEscaped = !$bEscaped;
@@ -802,8 +803,8 @@ class Message {
      */
     function parseAddress($read, &$i) {
         $arg_a = array();
-        for (; $read{$i} != ')'; ++$i) {
-            $char = strtoupper($read{$i});
+        for (; $read[$i] != ')'; ++$i) {
+            $char = strtoupper($read[$i]);
             switch ($char) {
                 case '"': $arg_a[] = $this->parseQuote($read, $i); break;
                 case '{': $arg_a[] = $this->parseLiteral($read, $i); break;
@@ -837,8 +838,8 @@ class Message {
      */
     function parseDisposition($read, &$i) {
         $arg_a = array();
-        for (; $read{$i} != ')'; ++$i) {
-            switch ($read{$i}) {
+        for (; $read[$i] != ')'; ++$i) {
+            switch ($read[$i]) {
                 case '"': $arg_a[] = $this->parseQuote($read, $i); break;
                 case '{': $arg_a[] = $this->parseLiteral($read, $i); break;
                 case '(': $arg_a[] = $this->parseProperties($read, $i); break;
@@ -864,8 +865,8 @@ class Message {
         /* no idea how to process this one without examples */
         $arg_a = array();
 
-        for (; $read{$i} != ')'; ++$i) {
-            switch ($read{$i}) {
+        for (; $read[$i] != ')'; ++$i) {
+            switch ($read[$i]) {
                 case '"': $arg_a[] = $this->parseQuote($read, $i); break;
                 case '{': $arg_a[] = $this->parseLiteral($read, $i); break;
                 case '(': $arg_a[] = $this->parseProperties($read, $i); break;
@@ -889,8 +890,8 @@ class Message {
      * @return integer
      */
     function parseParenthesis($read, $i) {
-        for ($i++; $read{$i} != ')'; ++$i) {
-            switch ($read{$i}) {
+        for ($i++; $read[$i] != ')'; ++$i) {
+            switch ($read[$i]) {
                 case '"': $this->parseQuote($read, $i); break;
                 case '{': $this->parseLiteral($read, $i); break;
                 case '(': $this->parseProperties($read, $i); break;
@@ -943,7 +944,7 @@ class Message {
                 }
             }
 
-            if ((($line{0} == '-') || $rfc822_header)  && isset($boundaries[0])) {
+            if ((($line[0] == '-') || $rfc822_header)  && isset($boundaries[0])) {
                 $cnt = count($boundaries)-1;
                 $bnd = $boundaries[$cnt]['bnd'];
                 $bndreg = $boundaries[$cnt]['bndreg'];
@@ -953,7 +954,7 @@ class Message {
                     $bndlen = strlen($reg[1]);
                     $bndend = false;
                     if (strlen($line) > ($bndlen + 3)) {
-                        if (($line{$bndlen+2} == '-') && ($line{$bndlen+3} == '-')) {
+                        if (($line[$bndlen+2] == '-') && ($line[$bndlen+3] == '-')) {
                             $bndend = true;
                         }
                     }