made "quoted-printable" work
[squirrelmail.git] / functions / mime.php
index f81d08f07efb21981ff5044b810f0c3ee22084a3..cc00e3c771f94d582e139a6055ce9d77b74cd053 100644 (file)
        as the actual message in the HTML.   It contains everything needed, including
        HTML Tags, Attachments at the bottom, etc.
     **/
-   function formatBody($message) {
-      include ("../config/config.php");
+   function formatBody($message, $color) {
 
       /** this if statement checks for the entity to show as the primary message.  To
           add more of them, just put them in the order that is their priority.
          $body .= decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
       } else if (containsType($message, "text", "plain", $ent_num)) {
          $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
-         $body .= "<TT>" . nl2br($tmpbody) . "</TT>";
+         $body .= "<TT>" . nl2br(trim($tmpbody)) . "</TT>";
       }
       // add other primary displaying message types here
       else {
          // find any type that's displayable
          if (containsType($message, "text", "any_type", $ent_num)) {
             $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
-            $body .= "<TT>" . nl2br($tmpbody) . "</TT>";
+            $body .= "<TT>" . nl2br(trim($tmpbody)) . "</TT>";
          } else if (containsType($message, "message", "any_type", $ent_num)) {
             $tmpbody = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
-            $body .= "<TT>" . nl2br($tmpbody) . "</TT>";
+            $body .= "<TT>" . nl2br(trim($tmpbody)) . "</TT>";
          }
       }
 
          $newbody = $body; // if only they all were this easy
 
       } else if ($encoding == "quoted-printable") {
-         echo "$body";
-         $body = ereg_replace("=3D", "=", $body);
-         $body = ereg_replace("=\n", "", $body);
-         $body = ereg_replace("=20", "\n", $body);
-         $newbody= $body;
+         $body_ary = explode("\n", $body);
+
+         for ($q=0; $q < count($body_ary); $q++) {
+            if (substr(trim($body_ary[$q]), -1) == "=") {
+               $body_ary[$q] = trim($body_ary[$q]);
+               $body_ary[$q] = substr($body_ary[$q], 0, strlen($body_ary[$q])-1);
+            } else if (substr(trim($body_ary[$q]), -3) == "=20") {
+               $body_ary[$q] = trim($body_ary[$q]);
+               $body_ary[$q] = substr($body_ary[$q], 0, strlen($body_ary[$q])-3);
+               $body_ary[$q] = "$body_ary[$q]\n";
+            }
+         }
+
+         for ($q=0;$q < count($body_ary);$q++) {
+            $body_ary[$q] = ereg_replace("=3D", "=", $body_ary[$q]);
+         }
 
+         $body = "";
+         for ($i = 0; $i < count($body_ary); $i++) {
+            $body .= "$body_ary[$i]\n";
+         }
+
+         $newbody = $body;
       } else if ($encoding == "base64") {
          $newbody = base64_decode($body);