updated documentation
[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
15 $message = fetchMessage($imapConnection, $passed_id);
31f3d7c0 16
d4467150 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
f7fb20fe 22 /** translate the subject and mailbox into url-able text **/
23 $url_subj = urlencode(trim($message["HEADER"]["SUBJECT"]));
8467bf00 24 $urlMailbox = urlencode($mailbox);
f7fb20fe 25 $url_from = urlencode($message["HEADER"]["FROM"]);
be69e508 26
f7fb20fe 27 $dateString = getLongDateString($message["HEADER"]["DATE"]);
31f3d7c0 28
078a40a4 29 /** FORMAT THE TO STRING **/
2844086d 30 $i = 0;
31 $to_string = "";
f7fb20fe 32 $to_ary = $message["HEADER"]["TO"];
2844086d 33 while ($i < count($to_ary)) {
f7fb20fe 34 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
2844086d 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) {
078a40a4 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>)";
2844086d 45 $i = count($to_ary);
46 }
47 } else if ($i == 1) {
078a40a4 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>)";
2844086d 49 }
50 }
51 }
52
078a40a4 53 /** FORMAT THE CC STRING **/
54 $i = 0;
55 $cc_string = "";
f7fb20fe 56 $cc_ary = $message["HEADER"]["CC"];
078a40a4 57 while ($i < count($cc_ary)) {
f7fb20fe 58 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 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
f7fb20fe 77 /** make sure everything will display in HTML format **/
78 $from_name = htmlspecialchars($message["HEADER"]["FROM"]);
79 $subject = htmlspecialchars($message["HEADER"]["SUBJECT"]);
078a40a4 80
8467bf00 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%>";
31f3d7c0 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>";
8467bf00 99 echo " </TD></TR>";
100 echo " <TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
be69e508 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";
9774bdef 123 echo " <FONT FACE=\"Arial,Helvetica\"><B>$dateString</B></FONT>\n";
be69e508 124 echo " </TD>\n";
125 echo " </TR>\n";
2844086d 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";
078a40a4 134 /** cc **/
f7fb20fe 135 if ($message["HEADER"]["CC"][0]) {
078a40a4 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 }
be69e508 144 echo " </TABLE></TD></TR>\n";
145
d4467150 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
f7fb20fe 156 $i = 0;
d4467150 157 $q = 0;
158 $entity[0] = $i;
f7fb20fe 159 while ($i < count($message["ENTITIES"])) {
d4467150 160 $b = $i + 1;
161 echo "</TD></TR><TR><TD BGCOLOR=DCDCDC><CENTER>Part $b</CENTER></TD></TR><TR><TD BGCOLOR=FFFFFF WIDTH=100%>";
f7fb20fe 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 {
d4467150 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%>";
f7fb20fe 169 for ($p = 0; $p < count($message["ENTITIES"][0]["BODY"]); $p++) {
170 echo $message["ENTITIES"][0]["BODY"][$p];
171 }
be69e508 172 }
d4467150 173*/
e550d551 174 echo " <BR></TD></TR>\n";
be69e508 175 echo " <TR><TD BGCOLOR=DCDCDC>&nbsp;</TD></TR>";
176 echo "</TABLE>\n";
177
178?>