Fixed nasty bug in finding the language argument (arg3 in multipart
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 19 Jul 2002 18:27:59 +0000 (18:27 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 19 Jul 2002 18:27:59 +0000 (18:27 +0000)
entities)

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3103 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime.class

index a62efaf1dbea2b6b4696c090451d5850e494c031..39654fe80a716b12a9800f5aad28c6df402b8f29 100644 (file)
@@ -192,12 +192,13 @@ class message {
                $msg = $msg->entities[0];
              }
           }
                $msg = $msg->entities[0];
              }
           }
-          if ($msg->type0 == 'message') { 
+          if ($msg->type0 == 'message' && $msg->type1 == 'rfc822') { 
              /*this is a header for a message/rfc822 entity */
              $msg = $msg->entities[0];
           }
        }
              /*this is a header for a message/rfc822 entity */
              $msg = $msg->entities[0];
           }
        }
-       if ($msg->type0 == 'message') { 
+
+       if ($msg->type0 == 'message' && $msg->type1 == 'rfc822') { 
           /*this is a header for a message/rfc822 entity */
           $msg = $msg->entities[0];
        }
           /*this is a header for a message/rfc822 entity */
           $msg = $msg->entities[0];
        }
@@ -205,6 +206,7 @@ class message {
        if (isset($msg->entities[($ent_a[$cnt-1])-1])) {
            $msg = $msg->entities[($ent_a[$cnt-1]-1)];
         }
        if (isset($msg->entities[($ent_a[$cnt-1])-1])) {
            $msg = $msg->entities[($ent_a[$cnt-1]-1)];
         }
+
         return $msg;
     }
     
         return $msg;
     }
     
@@ -228,7 +230,7 @@ class message {
      * Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net.
      *
      */
      * Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net.
      *
      */
-    function parseStructure($read, $i=0, $message = false) {
+    function &parseStructure($read, $i=0, $message = false) {
       $arg_no = 0;
       $arg_a = array();
       $cnt = strlen($read);
       $arg_no = 0;
       $arg_a = array();
       $cnt = strlen($read);
@@ -297,6 +299,11 @@ class message {
                 }
                 $arg_no++;
                  break;
                 }
                 $arg_no++;
                  break;
+              case 3:
+                if (isset($msg->type0) &&  $msg->type0 == 'multipart') {
+                   $i++;
+                   $arg_a[]= $msg->parseLanguage($read,&$i);
+                }
               case 7:
                 if ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822') {
 
               case 7:
                 if ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822') {
 
@@ -357,7 +364,8 @@ class message {
           break;
        case 'N':
           /* probably NIL argument */
           break;
        case 'N':
           /* probably NIL argument */
-          if (strtolower(substr($read,$i,3)) == 'nil') {
+          if (strtoupper(substr($read,$i,4)) == 'NIL ' || 
+              strtoupper(substr($read,$i,4)) == 'NIL)') {
              $arg_a[] = '';
              $arg_no++;
              $i = $i+2;
              $arg_a[] = '';
              $arg_no++;
              $i = $i+2;
@@ -511,7 +519,7 @@ class message {
               break;
             case 'N':   
               /* probably NIL argument */
               break;
             case 'N':   
               /* probably NIL argument */
-              if (strtolower(substr($read,$i,3)) == 'nil') {
+              if (strtoupper(substr($read,$i,3)) == 'NIL') {
                  $arg_a[] = '';
                  $arg_no++;
                  $i = $i+2;
                  $arg_a[] = '';
                  $arg_no++;
                  $i = $i+2;
@@ -584,7 +592,7 @@ class message {
            $hdr->inreplyto = $arg_a[8];
            /* argument 10: message-id */
            $hdr->message_id = $arg_a[9];
            $hdr->inreplyto = $arg_a[8];
            /* argument 10: message-id */
            $hdr->message_id = $arg_a[9];
-       }
+       } 
     }
     
     function parseLiteral($read, $i) {
     }
     
     function parseLiteral($read, $i) {
@@ -606,8 +614,7 @@ class message {
     function parseQuote($read, $i) {
        $i++;
        $s = '';
     function parseQuote($read, $i) {
        $i++;
        $s = '';
-       $cnt = strlen($read);
-       while ($i < $cnt && $read{$i} != '"') {
+       while ($read{$i} != '"') {
           if ($read{$i} == '\\') {
               $i++;
           } 
           if ($read{$i} == '\\') {
               $i++;
           } 
@@ -619,7 +626,7 @@ class message {
     
     function parseAddress($read, $i) {
        $arg_a = array();
     
     function parseAddress($read, $i) {
        $arg_a = array();
-        while ($read{$i} != ')') {
+        while ($read{$i} != ')' ) { //&& $i < count($read)) {
           $char = strtoupper($read{$i});
           switch ($char) {
             case '"':
           $char = strtoupper($read{$i});
           switch ($char) {
             case '"':
@@ -633,6 +640,7 @@ class message {
                  $arg_a[] = '';
                  $i = $i+2;
               }
                  $arg_a[] = '';
                  $i = $i+2;
               }
+              break;
             default:
               break;
           }
             default:
               break;
           }
@@ -644,11 +652,13 @@ class message {
            $adr->adl = $arg_a[1];
            $adr->mailbox = $arg_a[2];
            $adr->host = $arg_a[3];
            $adr->adl = $arg_a[1];
            $adr->mailbox = $arg_a[2];
            $adr->host = $arg_a[3];
-       } else $adr = '';
+       } else {
+          $adr = '';
+       }
        return $adr;
     }
     
        return $adr;
     }
     
-    function parseDisposition($read,$i) {
+    function parseDisposition($read,&$i) {
         $arg_a = array();
         while ($read{$i} != ')') {
           switch ($read{$i}) {
         $arg_a = array();
         while ($read{$i} != ')') {
           switch ($read{$i}) {
@@ -672,12 +682,31 @@ class message {
              $disp->properties = $arg_a[1];
           }
        }
              $disp->properties = $arg_a[1];
           }
        }
-       if (is_object($disp)) return $disp;
+       if (is_object($disp)) { 
+          return $disp;
+       }
     }
     
     function parseLanguage($read,&$i) {
     }
     
     function parseLanguage($read,&$i) {
-      /* no idea how to process this one without examples */
-      return '';
+        /* no idea how to process this one without examples */
+        $arg = '';
+        while ($read{$i} != ')') {
+          switch ($read{$i}) {
+            case '"':
+              $arg = $this->parseQuote($read,&$i);
+              break;
+            case '{': 
+              $arg = $this->parseLiteral($read,&$i);
+              break;
+            case '(':
+              $arg = $this->parseProperties($read,&$i);
+              break;
+            default:
+              break;
+          }
+          $i++;
+        }
+        return $arg;;
     }
     
     function parseParenthesis($read,&$i) {
     }
     
     function parseParenthesis($read,&$i) {
@@ -700,7 +729,6 @@ class message {
     }
 
     function findDisplayEntity ($entity = array(), $alt_order = array('text/plain','text/html')) {
     }
 
     function findDisplayEntity ($entity = array(), $alt_order = array('text/plain','text/html')) {
-
        $found = false;    
        $type = $this->type0.'/'.$this->type1;
        if ( $type == 'multipart/alternative') {
        $found = false;    
        $type = $this->type0.'/'.$this->type1;
        if ( $type == 'multipart/alternative') {
@@ -724,7 +752,8 @@ class message {
            }
        } else if ( $this->type0 == 'text' &&
              ( $this->type1 == 'plain' ||
            }
        } else if ( $this->type0 == 'text' &&
              ( $this->type1 == 'plain' ||
-               $this->type1 == 'html' ) &&
+               $this->type1 == 'html' ||
+              $this->type1 == 'message') &&
              isset($this->entity_id) ) {
             if (count($this->entities) == 0) {
                if (!$this->header->disposition->name == 'attachment') {
              isset($this->entity_id) ) {
             if (count($this->entities) == 0) {
                if (!$this->header->disposition->name == 'attachment') {