Added BASIC mime support.
[squirrelmail.git] / src / read_body.php
index 053bcb3f3385261c780fe249217b3cc06a6504a2..4c751686cd423de2d70a8424c49ba7d2be34a167 100644 (file)
@@ -3,6 +3,7 @@
    include("../functions/strings.php");
    include("../functions/page_header.php");
    include("../functions/imap.php");
+   include("../functions/mime.php");
    include("../functions/mailbox.php");
    include("../functions/date.php");
 
 
    echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">\n";
    displayPageHeader($mailbox);
-   $body = fetchBody($imapConnection, $passed_id);
-   getMessageHeaders($imapConnection, $passed_id, $passed_id, $f, $s, $d);
 
-   $subject = $s[0];
-   $url_subj = urlencode(trim($subject));
+   // $message contains all information about the message
+   // including header and body
+   $message = fetchMessage($imapConnection, $passed_id);
 
-   $d[0] = ereg_replace("  ", " ", $d[0]);
-   $date = $d[0];
-   $from_name = getSenderName($f[0]);
+   /** translate the subject and mailbox into url-able text **/
+   $url_subj = urlencode(trim($message["HEADER"]["SUBJECT"]));
    $urlMailbox = urlencode($mailbox);
+   $url_from = urlencode($message["HEADER"]["FROM"]);
 
-   $url_from = trim(decodeEmailAddr($f[0]));
-   $url_from = urlencode($url_from);
+   $dateString = getLongDateString($message["HEADER"]["DATE"]);
+
+   /** FORMAT THE TO STRING **/
+   $i = 0;
+   $to_string = "";
+   $to_ary = $message["HEADER"]["TO"];
+   while ($i < count($to_ary)) {
+      $to_ary[$i] = htmlspecialchars($to_ary[$i]);
+      if ($to_string)
+         $to_string = "$to_string<BR>$to_ary[$i]";
+      else
+         $to_string = "$to_ary[$i]";
+
+      $i++;
+      if (count($to_ary) > 1) {
+         if ($show_more == false) {
+            if ($i == 1) {
+               $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">more</A>)";
+               $i = count($to_ary);
+            }
+         } else if ($i == 1) {
+            $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">less</A>)";
+         }
+      }
+   }
+
+   /** FORMAT THE CC STRING **/
+   $i = 0;
+   $cc_string = "";
+   $cc_ary = $message["HEADER"]["CC"];
+   while ($i < count($cc_ary)) {
+      $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
+      if ($cc_string)
+         $cc_string = "$cc_string<BR>$cc_ary[$i]";
+      else
+         $cc_string = "$cc_ary[$i]";
+
+      $i++;
+      if (count($cc_ary) > 1) {
+         if ($show_more_cc == false) {
+            if ($i == 1) {
+               $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">more</A>)";
+               $i = count($cc_ary);
+            }
+         } else if ($i == 1) {
+            $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">less</A>)";
+         }
+      }
+   }
+
+   /** make sure everything will display in HTML format **/
+   $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
+   $subject = htmlspecialchars($message["HEADER"]["SUBJECT"]);
 
    echo "<BR>";
    echo "<TABLE COLS=1 WIDTH=95% BORDER=0 ALIGN=CENTER CELLPADDING=2>\n";
    echo "         <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT>\n";
    echo "            <FONT FACE=\"Arial,Helvetica\">Date:</FONT>\n";
    echo "         </TD><TD BGCOLOR=FFFFFF WIDTH=85%>\n";
-   echo "            <FONT FACE=\"Arial,Helvetica\"><B>$date</B></FONT>\n";
+   echo "            <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
    echo "         </TD>\n";
    echo "      </TR>\n";
-
+   /** to **/
+   echo "      <TR>\n";
+   echo "         <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
+   echo "            <FONT FACE=\"Arial,Helvetica\">To:</FONT>\n";
+   echo "         </TD><TD BGCOLOR=FFFFFF WIDTH=85% VALIGN=TOP>\n";
+   echo "            <FONT FACE=\"Arial,Helvetica\"><B>$to_string</B></FONT>\n";
+   echo "         </TD>\n";
+   echo "      </TR>\n";
+   /** cc **/
+   if ($message["HEADER"]["CC"][0]) {
+      echo "      <TR>\n";
+      echo "         <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
+      echo "            <FONT FACE=\"Arial,Helvetica\">Cc:</FONT>\n";
+      echo "         </TD><TD BGCOLOR=FFFFFF WIDTH=85% VALIGN=TOP>\n";
+      echo "            <FONT FACE=\"Arial,Helvetica\"><B>$cc_string</B></FONT>\n";
+      echo "         </TD>\n";
+      echo "      </TR>\n";
+   }
    echo "   </TABLE></TD></TR>\n";
 
    echo "   <TR><TD BGCOLOR=FFFFFF WIDTH=100%><BR>\n";
-   $i = 0;
-   while ($i < count($body)) {
-      echo "$body[$i]";
-      $i++;
+   if (count($message["ENTITIES"]) > 1) {
+      echo "<B>This is a multipart MIME encoded message.<BR></B>";
+      $i = 0;
+      while ($i < count($message["ENTITIES"])) {
+         echo "<B>--(PART $i)--</B><BR>";
+         for ($p = 0; $p < count($message["ENTITIES"][$i][0]["BODY"]); $p++) {
+            echo $message["ENTITIES"][$i][0]["BODY"][$p];
+         }
+         $i++;
+      }
+   } else {
+      echo "<FONT COLOR=DD0000><B>This is a single part mime encoded message</B></FONT><BR>";
+      for ($p = 0; $p < count($message["ENTITIES"][0]["BODY"]); $p++) {
+         echo $message["ENTITIES"][0]["BODY"][$p];
+      }
    }
    echo "   <BR></TD></TR>\n";
    echo "   <TR><TD BGCOLOR=DCDCDC>&nbsp;</TD></TR>";