- added a view header option
[squirrelmail.git] / src / read_body.php
1 <?php
2 /**
3 ** read_body.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** This file is used for reading the msgs array and displaying
9 ** the resulting emails in the right frame.
10 **/
11
12
13
14
15
16
17 session_start();
18
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($page_header_php))
24 include("../functions/page_header.php");
25 if (!isset($imap_php))
26 include("../functions/imap.php");
27 if (!isset($mime_php))
28 include("../functions/mime.php");
29 if (!isset($date_php))
30 include("../functions/date.php");
31
32 include("../src/load_prefs.php");
33 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
34 sqimap_mailbox_select($imapConnection, $mailbox);
35 displayPageHeader($color, $mailbox);
36
37 if ($view_hdr) {
38 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
39 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
40
41 echo "<br>";
42 echo "<table width=95% cellpadding=2 cellspacing=0 border=0 align=center>\n";
43 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - ";
44 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
45 echo ""._("View message") . "</a></b></center></td></tr>\n";
46 echo "<tr><td><pre>";
47 for ($i=1; $i < count($read)-1; $i++) {
48 $read[$i] = htmlspecialchars($read[$i]);
49 if (substr($read[$i], 0, 1) != "\t" &&
50 substr($read[$i], 0, 1) != " " &&
51 substr($read[$i], 0, 1) != "&" &&
52 trim($read[$i])) {
53 $pre = substr($read[$i], 0, strpos($read[$i], ":"));
54 $read[$i] = str_replace("$pre", "<b>$pre</b>", $read[$i]);
55 }
56 echo "$read[$i]";
57 }
58 echo "</pre></td></tr></table>\n";
59 echo "</body></html>";
60 exit;
61 }
62
63 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
64 // return the index. used for finding the next and previous messages
65
66 // returns the index of the next valid message from the array
67 function findNextMessage() {
68 global $msort, $currentArrayIndex, $msgs;
69 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
70 if ($currentArrayIndex == $msgs[$key]["ID"]) {
71 next($msort);
72 $key = key($msort);
73 if (isset($key))
74 return $msgs[$key]["ID"];
75 }
76 }
77 return -1;
78 }
79
80 // returns the index of the previous message from the array
81 function findPreviousMessage() {
82 global $msort, $currentArrayIndex, $msgs;
83 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
84 if ($currentArrayIndex == $msgs[$key]["ID"]) {
85 prev($msort);
86 $key = key($msort);
87 if (isset($key))
88 return $msgs[$key]["ID"];
89 }
90 }
91 return -1;
92 }
93
94 if (isset($msgs)) {
95 $currentArrayIndex = $passed_id;
96 /*
97 for ($i=0; $i < count($msgs); $i++) {
98 if ($msgs[$i]["ID"] == $passed_id) {
99 $currentArrayIndex = $i;
100 break;
101 }
102 }
103 */
104 } else {
105 $currentArrayIndex = -1;
106 }
107
108 for ($i = 0; $i < count($msgs); $i++) {
109 if ($msgs[$i]["ID"] == $passed_id)
110 $msgs[$i]["FLAG_SEEN"] = true;
111 }
112
113 // $message contains all information about the message
114 // including header and body
115 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
116
117 /** translate the subject and mailbox into url-able text **/
118 $url_subj = urlencode(trim(stripslashes($message->header->subject)));
119 $urlMailbox = urlencode($mailbox);
120 $url_replyto = urlencode($message->header->replyto);
121
122 $url_replytoall = urlencode($message->header->replyto);
123 $url_replytoallcc = urlencode(getLineOfAddrs($message->header->to) . ", " . getLineOfAddrs($message->header->cc));
124
125 $dateString = getLongDateString($message->header->date);
126 $ent_num = findDisplayEntity($message);
127
128 /** TEXT STRINGS DEFINITIONS **/
129 $echo_more = _("more");
130 $echo_less = _("less");
131
132 /** FORMAT THE TO STRING **/
133 $i = 0;
134 $to_string = "";
135 $to_ary = $message->header->to;
136 while ($i < count($to_ary)) {
137 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
138
139 if ($to_string)
140 $to_string = "$to_string<BR>$to_ary[$i]";
141 else
142 $to_string = "$to_ary[$i]";
143
144 $i++;
145 if (count($to_ary) > 1) {
146 if ($show_more == false) {
147 if ($i == 1) {
148 $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\">$echo_more</A>)";
149 $i = count($to_ary);
150 }
151 } else if ($i == 1) {
152 $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\">$echo_less</A>)";
153 }
154 }
155 }
156
157 /** FORMAT THE CC STRING **/
158 $i = 0;
159 $cc_string = "";
160 $cc_ary = $message->header->cc;
161 while ($i < count($cc_ary)) {
162 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
163 if ($cc_string)
164 $cc_string = "$cc_string<BR>$cc_ary[$i]";
165 else
166 $cc_string = "$cc_ary[$i]";
167
168 $i++;
169 if (count($cc_ary) > 1) {
170 if ($show_more_cc == false) {
171 if ($i == 1) {
172 $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\">$echo_more</A>)";
173 $i = count($cc_ary);
174 }
175 } else if ($i == 1) {
176 $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\">$echo_less</A>)";
177 }
178 }
179 }
180
181 /** make sure everything will display in HTML format **/
182 $from_name = decodeHeader(htmlspecialchars($message->header->from));
183 $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject)));
184
185 echo "<BR>";
186 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
187 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
188 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
189 echo " <TR>";
190 echo " <TD ALIGN=LEFT WIDTH=33%>";
191 echo " <SMALL>";
192 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
193 echo _("Message List");
194 echo "</A>&nbsp;|&nbsp;";
195 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
196 echo _("Delete");
197 echo "</A>&nbsp;&nbsp;";
198 echo " </SMALL>";
199 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
200 echo " <SMALL>\n";
201 if ($currentArrayIndex == -1) {
202 echo "Previous&nbsp;|&nbsp;Next";
203 } else {
204 $prev = findPreviousMessage();
205 $next = findNextMessage();
206 if ($prev != -1)
207 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
208 else
209 echo _("Previous") . "&nbsp;|&nbsp;";
210 if ($next != -1)
211 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
212 else
213 echo _("Next");
214 }
215 echo " </SMALL>\n";
216 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
217 echo " <SMALL>";
218 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
219 echo _("Forward");
220 echo "</A>&nbsp;|&nbsp;";
221 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
222 echo _("Reply");
223 echo "</A>&nbsp;|&nbsp;";
224 echo " <A HREF=\"compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
225 echo _("Reply All");
226 echo "</A>&nbsp;&nbsp;";
227 echo " </SMALL>";
228 echo " </TD>";
229 echo " </TR>";
230 echo " </TABLE>";
231 echo " </TD></TR>";
232 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
233 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
234 echo " <TR>\n";
235 /** subject **/
236 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
237 echo _("Subject:");
238 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
239 echo " <B>$subject</B>\n";
240 echo " </TD>\n";
241 echo " <TD WIDTH=1% bgcolor=\"$color[0]\" nowrap align=right><small><a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" . _("View full header") . "</a></small>&nbsp;&nbsp;</td>";
242 echo " </TR>\n";
243 /** from **/
244 echo " <TR>\n";
245 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
246 echo _("From:");
247 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
248 echo " <B>$from_name</B>\n";
249 echo " </TD>\n";
250 echo " </TR>\n";
251 /** date **/
252 echo " <TR>\n";
253 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
254 echo _("Date:");
255 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
256 echo " <B>$dateString</B>\n";
257 echo " </TD>\n";
258 echo " </TR>\n";
259 /** to **/
260 echo " <TR>\n";
261 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
262 echo _("To:");
263 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
264 echo " <B>$to_string</B>\n";
265 echo " </TD>\n";
266 echo " </TR>\n";
267 /** cc **/
268 if ($message->header->cc) {
269 echo " <TR>\n";
270 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
271 echo " Cc:\n";
272 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
273 echo " <B>$cc_string</B>\n";
274 echo " </TD>\n";
275 echo " </TR>\n";
276 }
277 echo "</TABLE>";
278 echo " </TD></TR>";
279
280 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
281 $body = formatBody($message, $color, $wrap_at);
282 echo "<BR>";
283
284 echo "$body";
285
286 echo " </TD></TR>\n";
287 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
288 echo "</TABLE>\n";
289
290 ?>