Rewrote multipart/* algorithm to be recursive
[squirrelmail.git] / src / read_body.php
CommitLineData
be69e508 1<?
2 include("../config/config.php");
3 include("../functions/strings.php");
4 include("../functions/page_header.php");
5 include("../functions/imap.php");
f7fb20fe 6 include("../functions/mime.php");
be69e508 7 include("../functions/mailbox.php");
8 include("../functions/date.php");
9
10 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
11 selectMailbox($imapConnection, $mailbox, $numMessages);
12
f7fb20fe 13 // $message contains all information about the message
14 // including header and body
97be2168 15 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
31f3d7c0 16
d4467150 17 echo "<HTML>";
f8f9bed9 18 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
19 displayPageHeader($color, $mailbox);
d4467150 20
f7fb20fe 21 /** translate the subject and mailbox into url-able text **/
e39d73e5 22 $url_subj = urlencode(trim(stripslashes($message["HEADER"]["SUBJECT"])));
8467bf00 23 $urlMailbox = urlencode($mailbox);
5c55c295 24 $url_replyto = urlencode($message["HEADER"]["REPLYTO"]);
be69e508 25
f7fb20fe 26 $dateString = getLongDateString($message["HEADER"]["DATE"]);
31f3d7c0 27
078a40a4 28 /** FORMAT THE TO STRING **/
2844086d 29 $i = 0;
30 $to_string = "";
f7fb20fe 31 $to_ary = $message["HEADER"]["TO"];
2844086d 32 while ($i < count($to_ary)) {
f7fb20fe 33 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
2844086d 34 if ($to_string)
35 $to_string = "$to_string<BR>$to_ary[$i]";
36 else
37 $to_string = "$to_ary[$i]";
38
39 $i++;
40 if (count($to_ary) > 1) {
41 if ($show_more == false) {
42 if ($i == 1) {
078a40a4 43 $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>)";
2844086d 44 $i = count($to_ary);
45 }
46 } else if ($i == 1) {
078a40a4 47 $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>)";
2844086d 48 }
49 }
50 }
51
078a40a4 52 /** FORMAT THE CC STRING **/
53 $i = 0;
54 $cc_string = "";
f7fb20fe 55 $cc_ary = $message["HEADER"]["CC"];
078a40a4 56 while ($i < count($cc_ary)) {
f7fb20fe 57 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 58 if ($cc_string)
59 $cc_string = "$cc_string<BR>$cc_ary[$i]";
60 else
61 $cc_string = "$cc_ary[$i]";
62
63 $i++;
64 if (count($cc_ary) > 1) {
65 if ($show_more_cc == false) {
66 if ($i == 1) {
67 $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>)";
68 $i = count($cc_ary);
69 }
70 } else if ($i == 1) {
71 $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>)";
72 }
73 }
74 }
75
f7fb20fe 76 /** make sure everything will display in HTML format **/
77 $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
e39d73e5 78 $subject = htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"]));
078a40a4 79
8467bf00 80 echo "<BR>";
4809f489 81 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
f8f9bed9 82 echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
4809f489 83 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
31f3d7c0 84 echo " <TR>";
85 echo " <TD ALIGN=LEFT WIDTH=50%>";
86 echo " <FONT FACE=\"Arial,Helvetica\" SIZE=2>";
87 echo " <A HREF=\"right_main.php?sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">Message List</A>&nbsp;&nbsp;";
88 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">Delete</A>&nbsp;&nbsp;";
89 echo " </FONT>";
90 echo " </TD><TD WIDTH=50% ALIGN=RIGHT>";
91 echo " <FONT FACE=\"Arial,Helvetica\" SIZE=2>";
92 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">Forward</A>&nbsp;&nbsp;";
5c55c295 93 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">Reply</A>&nbsp;&nbsp;";
31f3d7c0 94 echo " </FONT>";
95 echo " </TD>";
96 echo " </TR>";
97 echo " </TABLE>";
8467bf00 98 echo " </TD></TR>";
4809f489 99 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
97afcee9 100 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
be69e508 101 echo " <TR>\n";
102 /** subject **/
4809f489 103 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
be69e508 104 echo " <FONT FACE=\"Arial,Helvetica\">Subject:</FONT>\n";
f8f9bed9 105 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
be69e508 106 echo " <FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT>\n";
107 echo " </TD>\n";
108 echo " </TR>\n";
109 /** from **/
110 echo " <TR>\n";
4809f489 111 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
be69e508 112 echo " <FONT FACE=\"Arial,Helvetica\">From:</FONT>\n";
f8f9bed9 113 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
be69e508 114 echo " <FONT FACE=\"Arial,Helvetica\"><B>$from_name</B></FONT>\n";
115 echo " </TD>\n";
116 echo " </TR>\n";
117 /** date **/
118 echo " <TR>\n";
4809f489 119 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
be69e508 120 echo " <FONT FACE=\"Arial,Helvetica\">Date:</FONT>\n";
f8f9bed9 121 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
9774bdef 122 echo " <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
be69e508 123 echo " </TD>\n";
124 echo " </TR>\n";
2844086d 125 /** to **/
126 echo " <TR>\n";
4809f489 127 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
2844086d 128 echo " <FONT FACE=\"Arial,Helvetica\">To:</FONT>\n";
f8f9bed9 129 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
2844086d 130 echo " <FONT FACE=\"Arial,Helvetica\"><B>$to_string</B></FONT>\n";
131 echo " </TD>\n";
132 echo " </TR>\n";
078a40a4 133 /** cc **/
f7fb20fe 134 if ($message["HEADER"]["CC"][0]) {
078a40a4 135 echo " <TR>\n";
4809f489 136 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
078a40a4 137 echo " <FONT FACE=\"Arial,Helvetica\">Cc:</FONT>\n";
f8f9bed9 138 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
078a40a4 139 echo " <FONT FACE=\"Arial,Helvetica\"><B>$cc_string</B></FONT>\n";
140 echo " </TD>\n";
141 echo " </TR>\n";
142 }
4809f489 143 echo "</TABLE>";
144 echo " </TD></TR>";
be69e508 145
f8f9bed9 146 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
d4467150 147 $body = formatBody($message);
4809f489 148 echo "<BR>";
5c55c295 149
d4467150 150 for ($i = 0; $i < count($body); $i++) {
151 echo "$body[$i]";
152 }
153
e550d551 154 echo " <BR></TD></TR>\n";
f8f9bed9 155 echo " <TR><TD BGCOLOR=\"$color[0]\">&nbsp;</TD></TR>";
be69e508 156 echo "</TABLE>\n";
157
158?>