added gettext support.
[squirrelmail.git] / functions / mime.php
index f81d08f07efb21981ff5044b810f0c3ee22084a3..417f89873163b00aefc8971c636d0191ae4d627e 100644 (file)
@@ -11,6 +11,7 @@
    function decodeMime($body, $bound, $type0, $type1, &$entities) {
       if ($type0 == "multipart") {
          $bound = trim($bound);
+         $i = 0;
          while (($i < count($body)) && (substr($body[$i], 0, strlen("--$bound--")) != "--$bound--")) {
             if (trim($body[$i]) == "--$bound") {
                $j = $i+1;
        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, $wrap_at) {
 
       /** 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.
        **/
       $id = $message["INFO"]["ID"];
       $urlmailbox = urlencode($message["INFO"]["MAILBOX"]);
-      $body = "";
 
       if (containsType($message, "text", "html", $ent_num)) {
-         $body .= decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
+         $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 = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
       }
       // 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 = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
          } 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 = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
          }
       }
 
       /** If there are other types that shouldn't be formatted, add them here **/
       if ($message["ENTITIES"][$ent_num]["TYPE1"] != "html")
-         $body = translateText($body);
+         $body = translateText($body, $wrap_at);
 
-      $body .= "<BR><SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">Download this as a file</A></CENTER><BR></SMALL>";
+
+      $body .= "<BR><SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">". _("Download this as a file") ."</A></CENTER><BR></SMALL>";
 
       /** Display the ATTACHMENTS: message if there's more than one part **/
       if (count($message["ENTITIES"]) > 1) {
          $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);
 
       }
       return $newbody;
    }
-?>
\ No newline at end of file
+?>