Rewrote multipart/* algorithm to be recursive
[squirrelmail.git] / src / read_body.php
1 <?
2 include("../config/config.php");
3 include("../functions/strings.php");
4 include("../functions/page_header.php");
5 include("../functions/imap.php");
6 include("../functions/mime.php");
7 include("../functions/mailbox.php");
8 include("../functions/date.php");
9
10 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
11 selectMailbox($imapConnection, $mailbox, $numMessages);
12
13 // $message contains all information about the message
14 // including header and body
15 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
16
17 echo "<HTML>";
18 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
19 displayPageHeader($color, $mailbox);
20
21 /** translate the subject and mailbox into url-able text **/
22 $url_subj = urlencode(trim(stripslashes($message["HEADER"]["SUBJECT"])));
23 $urlMailbox = urlencode($mailbox);
24 $url_replyto = urlencode($message["HEADER"]["REPLYTO"]);
25
26 $dateString = getLongDateString($message["HEADER"]["DATE"]);
27
28 /** FORMAT THE TO STRING **/
29 $i = 0;
30 $to_string = "";
31 $to_ary = $message["HEADER"]["TO"];
32 while ($i < count($to_ary)) {
33 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
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) {
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>)";
44 $i = count($to_ary);
45 }
46 } else if ($i == 1) {
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>)";
48 }
49 }
50 }
51
52 /** FORMAT THE CC STRING **/
53 $i = 0;
54 $cc_string = "";
55 $cc_ary = $message["HEADER"]["CC"];
56 while ($i < count($cc_ary)) {
57 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
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
76 /** make sure everything will display in HTML format **/
77 $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
78 $subject = htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"]));
79
80 echo "<BR>";
81 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
82 echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
83 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
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;";
93 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">Reply</A>&nbsp;&nbsp;";
94 echo " </FONT>";
95 echo " </TD>";
96 echo " </TR>";
97 echo " </TABLE>";
98 echo " </TD></TR>";
99 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
100 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
101 echo " <TR>\n";
102 /** subject **/
103 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
104 echo " <FONT FACE=\"Arial,Helvetica\">Subject:</FONT>\n";
105 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
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";
111 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
112 echo " <FONT FACE=\"Arial,Helvetica\">From:</FONT>\n";
113 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
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";
119 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
120 echo " <FONT FACE=\"Arial,Helvetica\">Date:</FONT>\n";
121 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
122 echo " <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
123 echo " </TD>\n";
124 echo " </TR>\n";
125 /** to **/
126 echo " <TR>\n";
127 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
128 echo " <FONT FACE=\"Arial,Helvetica\">To:</FONT>\n";
129 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
130 echo " <FONT FACE=\"Arial,Helvetica\"><B>$to_string</B></FONT>\n";
131 echo " </TD>\n";
132 echo " </TR>\n";
133 /** cc **/
134 if ($message["HEADER"]["CC"][0]) {
135 echo " <TR>\n";
136 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
137 echo " <FONT FACE=\"Arial,Helvetica\">Cc:</FONT>\n";
138 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
139 echo " <FONT FACE=\"Arial,Helvetica\"><B>$cc_string</B></FONT>\n";
140 echo " </TD>\n";
141 echo " </TR>\n";
142 }
143 echo "</TABLE>";
144 echo " </TD></TR>";
145
146 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
147 $body = formatBody($message);
148 echo "<BR>";
149
150 for ($i = 0; $i < count($body); $i++) {
151 echo "$body[$i]";
152 }
153
154 echo " <BR></TD></TR>\n";
155 echo " <TR><TD BGCOLOR=\"$color[0]\">&nbsp;</TD></TR>";
156 echo "</TABLE>\n";
157
158 ?>