added attachment support
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 2 Jan 2000 02:36:56 +0000 (02:36 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 2 Jan 2000 02:36:56 +0000 (02:36 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@94 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/mailbox.php
functions/mime.php
src/read_body.php

index 5e63213..056abb2 100644 (file)
                $header["CHARSET"] = "us-ascii";
             }
 
+            /** Detects filename if any **/
+            if (strpos(strtolower(trim($line)), "name=")) {
+               $pos = strpos($line, "name=") + 5;
+               $name = trim($line);
+               if (strpos($line, " ", $pos) > 0) {
+                  $name = substr($name, $pos, strpos($line, " ", $pos));
+               } else {
+                  $name = substr($name, $pos);
+               }
+               $name = str_replace("\"", "", $name);
+               $header["FILENAME"] = $name;
+            }
          }
 
          /** REPLY-TO **/
       return decodeMime($body, $bound, $type0, $type1);
    }
 
-   function fetchEntityHeader($imapConnection, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset) {
+   function fetchEntityHeader($imapConnection, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) {
       /** defaults... if the don't get overwritten, it will display text **/
       $type0 = "text";
       $type1 = "plain";
                $type0 = $cont;
             }
 
+            $read[$i] = trim($read[$i]);
             $line = $read[$i];
+            $i++;
             while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
                str_replace("\n", "", $line);
                str_replace("\n", "", $read[$i]);
                $line = "$line $read[$i]";
                $i++;
+               $read[$i] = trim($read[$i]);
             }
 
             /** Detect the boundary of a multipart message **/
                }
                $charset = str_replace("\"", "", $charset);
             }
+
+            /** Detects filename if any **/
+            if (strpos(strtolower(trim($line)), "name=")) {
+               $pos = strpos($line, "name=") + 5;
+               $name = trim($line);
+               if (strpos($line, " ", $pos) > 0) {
+                  $name = substr($name, $pos, strpos($line, " ", $pos));
+               } else {
+                  $name = substr($name, $pos);
+               }
+               $name = str_replace("\"", "", $name);
+               $filename = $name;
+            }
          }
          $i++;
       }
index 2db2032..7054b41 100644 (file)
@@ -6,7 +6,6 @@
 
 
    function decodeMime($body, $bound, $type0, $type1) {
-//      echo "<TT>decodeMime: $type0/$type1</TT><BR>";
       if ($type0 == "multipart") {
          if ($body[0] == "")
             $i = 1;
@@ -26,7 +25,7 @@
                   $p++;
                }
 
-               fetchEntityHeader($imapConnection, $entity_header, $ent_type0, $ent_type1, $ent_bound, $encoding, $charset);
+               fetchEntityHeader($imapConnection, $entity_header, $ent_type0, $ent_type1, $ent_bound, $encoding, $charset, $filename);
 
                if ($ent_type0 == "text") {
                   while (substr(trim($body[$j]), 0, strlen($bound)) != $bound) {
                      $p++;
                   }
                } else {
-                  if (trim($body[$j]) == "")
-                     $j++;
+                  $j++;
+                  $entity_body = "";
                   while (substr(trim($body[$j]), 0, strlen($bound)) != $bound) {
                      $entity_body .= $body[$j];
                      $j++;
                   }
                }
-               $entity = getEntity($entity_body, $ent_bound, $ent_type0, $ent_type1, $encoding, $charset);
+               $entity = getEntity($entity_body, $ent_bound, $ent_type0, $ent_type1, $encoding, $charset, $filename);
 
                $q = count($full_message);
                $full_message[$q] = $entity[0];
    }
 
    /** This gets one entity's properties **/
-   function getEntity($body, $bound, $type0, $type1, $encoding, $charset) {
-//      echo "<TT>getEntity: $type0/$type1</TT><BR>";
+   function getEntity($body, $bound, $type0, $type1, $encoding, $charset, $filename) {
       $msg[0]["TYPE0"] = $type0;
       $msg[0]["TYPE1"] = $type1;
       $msg[0]["ENCODING"] = $encoding;
       $msg[0]["CHARSET"] = $charset;
+      $msg[0]["FILENAME"] = $filename;
 
+      echo "$type0 / $type1<BR>";
       if ($type0 == "text") {
          // error correcting if they didn't follow RFC standards
          if (trim($type1) == "")
                $msg[0]["BODY"][$p] = $body[$q];
             }
          }
-      } else if ($type0 == "image") {
+      } else {
          $msg[0]["PRIORITY"] == 5;
          $msg[0]["BODY"][0] = $body;
-      } else {
-         $msg[0]["BODY"][0] = "<B><FONT COLOR=DD0000>This attachment is of an unknown format:  $type0/$type1</FONT></B>";
       }
 
       return $msg;
          $pos = count($body);
          if ($message["ENTITIES"][$i]["TYPE0"] != "text") {
             $body[$pos] = "<BR><TT><U><B>ATTACHMENTS:</B></U></TT><BR>";
+            $i = count($message["ENTITIES"]);
          }
       }
 
       for ($i = 0; $i < count($message["ENTITIES"]); $i++) {
          $pos = count($body);
-         if ($message["ENTITIES"][$i]["TYPE0"] != "text") {
-            if ($message["ENTITIES"][$i]["TYPE0"] == "image") {
-               $body[$pos] = "<TT>&nbsp;&nbsp;&nbsp;Image: " . $message["ENTITIES"][$i]["TYPE0"] . "/" . $message["ENTITIES"][$i]["TYPE1"] . "</TT><BR>";
-
-/*               $file = fopen("../data/tmp.png", "w");
-               fwrite($file, base64_decode($message["ENTITIES"][$i]["BODY"][0]));
-               fclose($file);
-*/
-            } else {
-               $body[$pos] = "<TT>&nbsp;&nbsp;&nbsp;Unknown Type: " . $message["ENTITIES"][$i]["TYPE0"] . "/" . $message["ENTITIES"][$i]["TYPE1"] . "</TT><BR>";
-            }
+         if (($message["ENTITIES"][$i]["TYPE0"] == "image") || ($message["ENTITIES"][$i]["TYPE0"] == "application")){
+            $filename = $message["ENTITIES"][$i]["FILENAME"];
+            $body[$pos] = "<TT>&nbsp;&nbsp;&nbsp;<A HREF=\"../data/$filename\">" . $filename . "</A></TT><BR>";
+
+            $file = fopen("../data/$filename", "w");
+            $image = base64_decode($message["ENTITIES"][$i]["BODY"][0]);
+            fwrite($file, $image);
+            fclose($file);
          }
       }
 
index 4580489..256a05a 100644 (file)
@@ -79,7 +79,7 @@
    $subject = htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"]));
 
    echo "<BR>";
-   echo "<TABLE COLS=1 WIDTH=95% BORDER=0 ALIGN=CENTER CELLPADDING=2>\n";
+   echo "<TABLE COLS=1 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=2>\n";
    echo "   <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
    echo "      <TABLE WIDTH=100% BORDER=0 COLS=2>";
    echo "         <TR>";