added "reply-to" capabilities
[squirrelmail.git] / src / read_body.php
index c2122833e13feaa3eb4c6f4191faf6d69580170b..88c1093faf8935f3fd0621977b50dfb47bf0a5d4 100644 (file)
@@ -3,46 +3,35 @@
    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");
 
    $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
    selectMailbox($imapConnection, $mailbox, $numMessages);
 
-   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);
-   getMessageHeadersTo($imapConnection, $passed_id, $passed_id, $t);
-
-   $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]);
-   $dateParts = explode(" ", trim($d[0]));
-   $dateString = getLongDateString($dateParts);
+   echo "<HTML>";
+   echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"" . $message["HEADER"]["TYPE"][0] . "/" . $message["HEADER"]["TYPE"][1] . "; charset=" . $message["HEADER"]["CHARSET"] . "\">";
+   echo "<BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">\n";
+   displayPageHeader($mailbox);
 
-   $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_replyto = urlencode($message["HEADER"]["REPLYTO"]);
 
-   $url_from = trim(decodeEmailAddr($f[0]));
-   $url_from = urlencode($url_from);
-
-   $to_left = trim($t[0]);
-   for ($i = 0; $to_left;$i++) {
-      if (strpos($to_left, ",")) {
-         $to_ary[$i] = trim(substr($to_left, 0, strpos($to_left, ",")));
-         $to_left = substr($to_left, strpos($to_left, ",")+1, strlen($to_left));
-      }
-      else {
-         $to_ary[$i] = trim($to_left);
-         $to_left = "";
-      }
-   }
+   $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
       if (count($to_ary) > 1) {
          if ($show_more == false) {
             if ($i == 1) {
-               $to_string = "$to_string&nbsp;&nbsp;&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1\">more</A>)";
+               $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;&nbsp;&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0\">less</A>)";
+            $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 "   <TR><TD BGCOLOR=DCDCDC WIDTH=100%>";
@@ -74,7 +91,7 @@
    echo "            </TD><TD WIDTH=50% ALIGN=RIGHT>";
    echo "               <FONT FACE=\"Arial,Helvetica\" SIZE=2>";
    echo "               <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">Forward</A>&nbsp;&nbsp;";
-   echo "               <A HREF=\"compose.php?send_to=$url_from&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">Reply</A>&nbsp;&nbsp;";
+   echo "               <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">Reply</A>&nbsp;&nbsp;";
    echo "               </FONT>";
    echo "            </TD>";
    echo "         </TR>";
    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 "   <TR><TD BGCOLOR=FFFFFF WIDTH=100%>\n";
+   $body = formatBody($message);
+
+   for ($i = 0; $i < count($body); $i++) {
       echo "$body[$i]";
-      $i++;
    }
+
    echo "   <BR></TD></TR>\n";
    echo "   <TR><TD BGCOLOR=DCDCDC>&nbsp;</TD></TR>";
    echo "</TABLE>\n";