5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This file is used for reading the msgs array and displaying
9 ** the resulting emails in the right frame.
14 include("../src/validate.php");
15 include('../functions/imap.php');
16 include('../functions/mime.php');
17 include('../functions/date.php');
18 include('../functions/url_parser.php');
20 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
21 sqimap_mailbox_select($imapConnection, $mailbox);
23 displayPageHeader($color, $mailbox);
25 if (isset($view_hdr)) {
26 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
27 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
30 echo '<table width="100%" cellpadding="2" cellspacing="0" border="0" align="center">' . "\n";
31 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . '</b> - ';
32 if (isset($where) && isset($what)) {
33 // Got here from a search
34 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
36 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
38 echo ''._("View message") . "</a></b></center></td></tr></table>\n";
39 echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
43 for ($i=1; $i < count($read); $i++
) {
44 $line = htmlspecialchars($read[$i]);
45 if (eregi("^>", $line)) {
47 $first[$i] = ' ';
49 } else if (eregi("^[ |\t]", $line)) {
52 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
53 $first[$i] = $regs[1] . ':';
54 $second[$i] = $regs[2];
57 $second[$i] = trim($line);
61 for ($i=0; $i < count($second); $i = $j) {
62 if (isset($first[$i]))
64 if (isset($second[$i]))
65 $s = nl2br($second[$i]);
67 while ($first[$j] == '' && $j < count($first)) {
68 $s .= ' ' . nl2br($second[$j]);
72 if (isset($f)) echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
74 echo "</td></tr></table>\n";
75 echo '</body></html>';
76 sqimap_logout($imapConnection);
80 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
81 // return the index. used for finding the next and previous messages
83 // returns the index of the next valid message from the array
84 function findNextMessage() {
85 global $msort, $currentArrayIndex, $msgs, $sort;
88 if ($currentArrayIndex != 1) {
89 return $currentArrayIndex - 1;
92 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
93 if ($currentArrayIndex == $msgs[$key]['ID']) {
97 return $msgs[$key]['ID'];
104 // Removes just one address from the list of addresses
105 function RemoveAddress(&$addr_list, $addr) {
108 foreach (array_keys($addr_list, $addr) as $key_to_delete)
110 unset($addr_list[$key_to_delete]);
115 // returns the index of the previous message from the array
116 function findPreviousMessage() {
117 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
118 $mailbox, $data_dir, $username;
120 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
121 if ($currentArrayIndex != $numMessages) {
122 return $currentArrayIndex +
1;
125 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
126 if ($currentArrayIndex == $msgs[$key]['ID']) {
130 return $msgs[$key]['ID'];
138 $currentArrayIndex = $passed_id;
140 for ($i=0; $i < count($msgs); $i++) {
141 if ($msgs[$i]["ID"] == $passed_id) {
142 $currentArrayIndex = $i;
148 $currentArrayIndex = -1;
151 for ($i = 0; $i < count($msgs); $i++
) {
152 if ($msgs[$i]['ID'] == $passed_id)
153 $msgs[$i]['FLAG_SEEN'] = true;
156 // $message contains all information about the message
157 // including header and body
158 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
160 /** translate the subject and mailbox into url-able text **/
161 $url_subj = urlencode(trim($message->header
->subject
));
162 $urlMailbox = urlencode($mailbox);
163 $url_replyto = urlencode($message->header
->replyto
);
165 $url_replytoall = urlencode($message->header
->replyto
);
167 // If we are replying to all, then find all other addresses and
168 // add them to the list. Remove duplicates.
169 // This is somewhat messy, so I'll explain:
170 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
171 $url_replytoall_extra_addrs = array_merge(array($message->header
->from
),
172 $message->header
->to
, $message->header
->cc
);
174 // 2) Make one big string out of them
175 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
177 // 3) Parse that into an array of addresses
178 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
180 // 4) Make them unique -- weed out duplicates
181 // (Coded for PHP 4.0.0)
182 $url_replytoall_extra_addrs =
183 array_keys(array_flip($url_replytoall_extra_addrs));
185 // 5) Remove the addresses we'll be sending the message 'to'
186 $url_replytoall_avoid_addrs = parseAddrs($message->header
->replyto
);
187 foreach ($url_replytoall_avoid_addrs as $addr)
189 RemoveAddress($url_replytoall_extra_addrs, $addr);
192 // 6) Remove our identities from the CC list (they still can be in the
193 // TO list) only if $include_self_reply_all isn't set or it is ''.
194 if (getPref($data_dir, $username, 'include_self_reply_all') == '')
196 RemoveAddress($url_replytoall_extra_addrs,
197 getPref($data_dir, $username, 'email_address'));
198 $idents = getPref($data_dir, $username, 'identities');
199 if ($idents != '' && $idents > 1)
201 for ($i = 1; $i < $idents; $i ++
)
203 RemoveAddress($url_replytoall_extra_addrs,
204 getPref($data_dir, $username, 'email_address' .
210 // 7) Smoosh back into one nice line
211 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
214 $url_replytoallcc = urlencode($url_replytoallcc);
216 $dateString = getLongDateString($message->header
->date
);
218 // What do we reply to -- text only, if possible
219 $ent_num = findDisplayEntity($message);
221 /** TEXT STRINGS DEFINITIONS **/
222 $echo_more = _("more");
223 $echo_less = _("less");
225 if (!isset($show_more_cc)) $show_more_cc = false;
227 /** FORMAT THE TO STRING **/
230 $to_ary = $message->header
->to
;
231 while ($i < count($to_ary)) {
232 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
235 $to_string = "$to_string<BR>$to_ary[$i]";
237 $to_string = "$to_ary[$i]";
240 if (count($to_ary) > 1) {
241 if ($show_more == false) {
243 if (isset($where) && isset($what)) {
245 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
247 $to_string = "$to_string (<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>)";
251 } else if ($i == 1) {
252 if (isset($where) && isset($what)) {
254 $to_string = "$to_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
256 $to_string = "$to_string (<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>)";
262 /** FORMAT THE CC STRING **/
264 if (isset ($message->header
->cc
[0]) && trim($message->header
->cc
[0])){
266 $cc_ary = $message->header
->cc
;
267 while ($i < count(decodeHeader($cc_ary))) {
268 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
270 $cc_string = "$cc_string<BR>$cc_ary[$i]";
272 $cc_string = "$cc_ary[$i]";
275 if (count($cc_ary) > 1) {
276 if ($show_more_cc == false) {
278 if (isset($where) && isset($what)) {
280 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
282 $cc_string = "$cc_string (<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>)";
286 } else if ($i == 1) {
287 if (isset($where) && isset($what)) {
289 $cc_string = "$cc_string (<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&what=".urlencode($what)."&where=".urlencode($where)."&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
291 $cc_string = "$cc_string (<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>)";
297 /** make sure everything will display in HTML format **/
298 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
299 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
301 do_hook('read_body_top');
304 echo '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n";
305 echo ' <TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">';
306 echo ' <TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">';
308 echo ' <TD ALIGN="LEFT" WIDTH="33%">';
310 if ($where && $what) {
311 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
313 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
315 echo _("Message List");
316 echo '</A> | ';
317 if ($where && $what) {
318 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what).'">';
320 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
323 echo '</A> ';
325 echo ' </TD><TD WIDTH="33%" ALIGN="CENTER">';
326 echo ' <SMALL>' . "\n";
327 if ($where && $what) {
329 if ($currentArrayIndex == -1) {
330 echo 'Previous | Next';
332 $prev = findPreviousMessage();
333 $next = findNextMessage();
335 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
337 echo _("Previous") . ' | ';
339 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
344 echo ' </SMALL>' . "\n";
345 echo ' </TD><TD WIDTH="33%" ALIGN="RIGHT">';
347 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
349 echo '</A> | ';
350 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
352 echo '</A> | ';
353 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\">";
355 echo '</A> ';
361 echo ' <TR><TD CELLSPACING="0" WIDTH="100%">';
362 echo ' <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n";
365 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n";
367 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n";
368 echo " <B>$subject</B> \n";
370 echo ' <TD ROWSPAN="4" width=10% BGCOLOR="'.$color[0].'" ALIGN=right VALIGN=top NOWRAP><small>' . "\n";
371 if ($where && $what) {
372 // Got here from a search
373 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&view_hdr=1\">" . _("View full header") . "</a>\n";
375 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&view_hdr=1\">" . _("View full header") . "</a>\n";
377 do_hook("read_body_header_right");
378 echo '</small></TD>' . "\n";
382 echo ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n";
384 echo ' </TD><TD BGCOLOR="' . $color[0] . '">' . "\n";
385 echo " <B>$from_name</B> \n";
386 echo ' </TD>' . "\n";
387 echo ' </TR>' . "\n";
390 echo ' <TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n";
392 echo " </TD><TD BGCOLOR=\"$color[0]\">\n";
393 echo " <B>$dateString</B> \n";
394 echo ' </TD>' . "\n";
395 echo ' </TR>' . "\n";
398 echo " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n";
400 echo ' </TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n";
401 echo " <B>$to_string</B> \n";
402 echo ' </TD>' . "\n";
403 echo ' </TR>' . "\n";
405 if (isset($cc_string)) {
407 echo " <TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n";
409 echo " </TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>\n";
410 echo " <B>$cc_string</B> \n";
411 echo ' </TD>' . "\n";
412 echo ' </TR>' . "\n";
414 do_hook("read_body_header");
418 echo "<TABLE CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
420 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
423 $body = formatBody($imapConnection, $message, $color, $wrap_at);
428 echo '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n";
429 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
430 echo '</TABLE>' . "\n";
432 do_hook('read_body_bottom');
433 do_hook('html_bottom');
434 sqimap_logout($imapConnection);