7e98d1a599bd275a64e0433297859a4cdb2d8abc
[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);
16
17 echo "<HTML>";
18 echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"" . $message["HEADER"]["TYPE"][0] . "/" . $message["HEADER"]["TYPE"][1] . "; charset=" . $message["HEADER"]["CHARSET"] . "\">";
19 echo "<BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">\n";
20 displayPageHeader($mailbox);
21
22 /** translate the subject and mailbox into url-able text **/
23 $url_subj = urlencode(trim($message["HEADER"]["SUBJECT"]));
24 $urlMailbox = urlencode($mailbox);
25 $url_from = urlencode($message["HEADER"]["FROM"]);
26
27 $dateString = getLongDateString($message["HEADER"]["DATE"]);
28
29 /** FORMAT THE TO STRING **/
30 $i = 0;
31 $to_string = "";
32 $to_ary = $message["HEADER"]["TO"];
33 while ($i < count($to_ary)) {
34 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
35 if ($to_string)
36 $to_string = "$to_string<BR>$to_ary[$i]";
37 else
38 $to_string = "$to_ary[$i]";
39
40 $i++;
41 if (count($to_ary) > 1) {
42 if ($show_more == false) {
43 if ($i == 1) {
44 $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>)";
45 $i = count($to_ary);
46 }
47 } else if ($i == 1) {
48 $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>)";
49 }
50 }
51 }
52
53 /** FORMAT THE CC STRING **/
54 $i = 0;
55 $cc_string = "";
56 $cc_ary = $message["HEADER"]["CC"];
57 while ($i < count($cc_ary)) {
58 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
59 if ($cc_string)
60 $cc_string = "$cc_string<BR>$cc_ary[$i]";
61 else
62 $cc_string = "$cc_ary[$i]";
63
64 $i++;
65 if (count($cc_ary) > 1) {
66 if ($show_more_cc == false) {
67 if ($i == 1) {
68 $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>)";
69 $i = count($cc_ary);
70 }
71 } else if ($i == 1) {
72 $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>)";
73 }
74 }
75 }
76
77 /** make sure everything will display in HTML format **/
78 $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
79 $subject = htmlspecialchars($message["HEADER"]["SUBJECT"]);
80
81 echo "<BR>";
82 echo "<TABLE COLS=1 WIDTH=95% BORDER=0 ALIGN=CENTER CELLPADDING=2>\n";
83 echo " <TR><TD BGCOLOR=DCDCDC WIDTH=100%>";
84 echo " <TABLE WIDTH=100% BORDER=0 COLS=2>";
85 echo " <TR>";
86 echo " <TD ALIGN=LEFT WIDTH=50%>";
87 echo " <FONT FACE=\"Arial,Helvetica\" SIZE=2>";
88 echo " <A HREF=\"right_main.php?sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">Message List</A>&nbsp;&nbsp;";
89 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">Delete</A>&nbsp;&nbsp;";
90 echo " </FONT>";
91 echo " </TD><TD WIDTH=50% ALIGN=RIGHT>";
92 echo " <FONT FACE=\"Arial,Helvetica\" SIZE=2>";
93 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">Forward</A>&nbsp;&nbsp;";
94 echo " <A HREF=\"compose.php?send_to=$url_from&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">Reply</A>&nbsp;&nbsp;";
95 echo " </FONT>";
96 echo " </TD>";
97 echo " </TR>";
98 echo " </TABLE>";
99 echo " </TD></TR>";
100 echo " <TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
101 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=2>\n";
102 echo " <TR>\n";
103 /** subject **/
104 echo " <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT>\n";
105 echo " <FONT FACE=\"Arial,Helvetica\">Subject:</FONT>\n";
106 echo " </TD><TD BGCOLOR=FFFFFF WIDTH=85%>\n";
107 echo " <FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT>\n";
108 echo " </TD>\n";
109 echo " </TR>\n";
110 /** from **/
111 echo " <TR>\n";
112 echo " <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT>\n";
113 echo " <FONT FACE=\"Arial,Helvetica\">From:</FONT>\n";
114 echo " </TD><TD BGCOLOR=FFFFFF WIDTH=85%>\n";
115 echo " <FONT FACE=\"Arial,Helvetica\"><B>$from_name</B></FONT>\n";
116 echo " </TD>\n";
117 echo " </TR>\n";
118 /** date **/
119 echo " <TR>\n";
120 echo " <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT>\n";
121 echo " <FONT FACE=\"Arial,Helvetica\">Date:</FONT>\n";
122 echo " </TD><TD BGCOLOR=FFFFFF WIDTH=85%>\n";
123 echo " <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
124 echo " </TD>\n";
125 echo " </TR>\n";
126 /** to **/
127 echo " <TR>\n";
128 echo " <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
129 echo " <FONT FACE=\"Arial,Helvetica\">To:</FONT>\n";
130 echo " </TD><TD BGCOLOR=FFFFFF WIDTH=85% VALIGN=TOP>\n";
131 echo " <FONT FACE=\"Arial,Helvetica\"><B>$to_string</B></FONT>\n";
132 echo " </TD>\n";
133 echo " </TR>\n";
134 /** cc **/
135 if ($message["HEADER"]["CC"][0]) {
136 echo " <TR>\n";
137 echo " <TD BGCOLOR=FFFFFF WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
138 echo " <FONT FACE=\"Arial,Helvetica\">Cc:</FONT>\n";
139 echo " </TD><TD BGCOLOR=FFFFFF WIDTH=85% VALIGN=TOP>\n";
140 echo " <FONT FACE=\"Arial,Helvetica\"><B>$cc_string</B></FONT>\n";
141 echo " </TD>\n";
142 echo " </TR>\n";
143 }
144 echo " </TABLE></TD></TR>\n";
145
146 echo " <TR><TD BGCOLOR=FFFFFF WIDTH=100%>\n";
147 $body = formatBody($message);
148 for ($i = 0; $i < count($body); $i++) {
149 echo "$body[$i]";
150 }
151
152 /* if (count($message["ENTITIES"]) > 1) {
153 echo "</TD></TR><TR><TD BGCOLOR=DCDCDC><CENTER><B><FONT COLOR=DD0000>This is a multipart MIME encoded message.</FONT></B></CENTER></TD></TR><TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
154 echo "";
155
156 $i = 0;
157 $q = 0;
158 $entity[0] = $i;
159 while ($i < count($message["ENTITIES"])) {
160 $b = $i + 1;
161 echo "</TD></TR><TR><TD BGCOLOR=DCDCDC><CENTER>Part $b</CENTER></TD></TR><TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
162 for ($p = 0; $p < count($message["ENTITIES"][$i][0]["BODY"]); $p++) {
163 echo $message["ENTITIES"][$i][0]["BODY"][$p];
164 }
165 $i++;
166 }
167 } else {
168 echo "</TD></TR><TR><TD BGCOLOR=DCDCDC><CENTER><B><FONT COLOR=DD0000>This is a single part MIME encoded message.</FONT></B></CENTER></TD></TR><TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
169 for ($p = 0; $p < count($message["ENTITIES"][0]["BODY"]); $p++) {
170 echo $message["ENTITIES"][0]["BODY"][$p];
171 }
172 }
173 */
174 echo " <BR></TD></TR>\n";
175 echo " <TR><TD BGCOLOR=DCDCDC>&nbsp;</TD></TR>";
176 echo "</TABLE>\n";
177
178 ?>