From 7c9499e1836d574fc0b398e45d912f6c2d032aac Mon Sep 17 00:00:00 2001 From: lkehresman Date: Sun, 2 Jan 2000 02:36:56 +0000 Subject: [PATCH] added attachment support git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@94 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mailbox.php | 30 +++++++++++++++++++++++++++++- functions/mime.php | 38 +++++++++++++++++--------------------- src/read_body.php | 2 +- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/functions/mailbox.php b/functions/mailbox.php index 5e632131..056abb2f 100644 --- a/functions/mailbox.php +++ b/functions/mailbox.php @@ -317,6 +317,18 @@ $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 **/ @@ -420,7 +432,7 @@ 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"; @@ -442,12 +454,15 @@ $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 **/ @@ -473,6 +488,19 @@ } $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++; } diff --git a/functions/mime.php b/functions/mime.php index 2db2032c..7054b41f 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -6,7 +6,6 @@ function decodeMime($body, $bound, $type0, $type1) { -// echo "decodeMime: $type0/$type1
"; 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) { @@ -35,14 +34,14 @@ $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]; @@ -57,13 +56,14 @@ } /** This gets one entity's properties **/ - function getEntity($body, $bound, $type0, $type1, $encoding, $charset) { -// echo "getEntity: $type0/$type1
"; + 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
"; if ($type0 == "text") { // error correcting if they didn't follow RFC standards if (trim($type1) == "") @@ -85,11 +85,9 @@ $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] = "This attachment is of an unknown format: $type0/$type1"; } return $msg; @@ -137,22 +135,20 @@ $pos = count($body); if ($message["ENTITIES"][$i]["TYPE0"] != "text") { $body[$pos] = "
ATTACHMENTS:
"; + $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] = "   Image: " . $message["ENTITIES"][$i]["TYPE0"] . "/" . $message["ENTITIES"][$i]["TYPE1"] . "
"; - -/* $file = fopen("../data/tmp.png", "w"); - fwrite($file, base64_decode($message["ENTITIES"][$i]["BODY"][0])); - fclose($file); -*/ - } else { - $body[$pos] = "   Unknown Type: " . $message["ENTITIES"][$i]["TYPE0"] . "/" . $message["ENTITIES"][$i]["TYPE1"] . "
"; - } + if (($message["ENTITIES"][$i]["TYPE0"] == "image") || ($message["ENTITIES"][$i]["TYPE0"] == "application")){ + $filename = $message["ENTITIES"][$i]["FILENAME"]; + $body[$pos] = "   " . $filename . "
"; + + $file = fopen("../data/$filename", "w"); + $image = base64_decode($message["ENTITIES"][$i]["BODY"][0]); + fwrite($file, $image); + fclose($file); } } diff --git a/src/read_body.php b/src/read_body.php index 4580489f..256a05ae 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -79,7 +79,7 @@ $subject = htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"])); echo "
"; - echo "\n"; + echo "
\n"; echo "
"; echo " "; echo " "; -- 2.25.1