e0777db5f625cb72a169aee92d16958866e18872
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.
16 if (!isset($strings_php))
17 include("../functions/strings.php");
18 if (!isset($config_php))
19 include("../config/config.php");
20 if (!isset($page_header_php))
21 include("../functions/page_header.php");
22 if (!isset($imap_php))
23 include("../functions/imap.php");
24 if (!isset($mime_php))
25 include("../functions/mime.php");
26 if (!isset($date_php))
27 include("../functions/date.php");
28 if (!isset($url_parser_php))
29 include("../functions/url_parser.php");
31 include("../src/load_prefs.php");
32 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
33 sqimap_mailbox_select($imapConnection, $mailbox);
35 displayPageHeader($color, $mailbox);
37 if (isset($view_hdr)) {
38 fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n");
39 $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b);
42 echo "<table width=100% 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 if ($where && $what) {
45 // Got here from a search
46 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
48 echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">";
50 echo ""._("View message") . "</a></b></center></td></tr></table>\n";
51 echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n";
54 for ($i=1; $i < count($read)-1; $i++
) {
55 $line = htmlspecialchars($read[$i]);
56 if (eregi("^>", $line)) {
58 $first[$i] = " ";
60 } else if (eregi("^[ |\t]", $line)) {
63 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
64 $first[$i] = $regs[1] . ":";
65 $second[$i] = $regs[2];
68 $second[$i] = trim($line);
72 for ($i=0; $i < count($second); $i = $j) {
74 $s = nl2br($second[$i]);
76 while ($first[$j] == "" && $j < count($first)) {
77 $s .= " " . nl2br($second[$j]);
81 echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
83 echo "</td></tr></table>\n";
84 echo "</body></html>";
85 sqimap_logout($imapConnection);
89 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
90 // return the index. used for finding the next and previous messages
92 // returns the index of the next valid message from the array
93 function findNextMessage() {
94 global $msort, $currentArrayIndex, $msgs, $sort;
97 if ($currentArrayIndex != 1) {
98 return $currentArrayIndex - 1;
101 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
102 if ($currentArrayIndex == $msgs[$key]["ID"]) {
106 return $msgs[$key]["ID"];
113 // returns the index of the previous message from the array
114 function findPreviousMessage() {
115 global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox;
117 $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
118 if ($currentArrayIndex != $numMessages) {
119 return $currentArrayIndex +
1;
122 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
123 if ($currentArrayIndex == $msgs[$key]["ID"]) {
127 return $msgs[$key]["ID"];
135 $currentArrayIndex = $passed_id;
137 for ($i=0; $i < count($msgs); $i++) {
138 if ($msgs[$i]["ID"] == $passed_id) {
139 $currentArrayIndex = $i;
145 $currentArrayIndex = -1;
148 for ($i = 0; $i < count($msgs); $i++
) {
149 if ($msgs[$i]["ID"] == $passed_id)
150 $msgs[$i]["FLAG_SEEN"] = true;
153 // $message contains all information about the message
154 // including header and body
155 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
157 /** translate the subject and mailbox into url-able text **/
158 $url_subj = urlencode(trim(sqStripSlashes($message->header
->subject
)));
159 $urlMailbox = urlencode($mailbox);
160 $url_replyto = urlencode($message->header
->replyto
);
162 $url_replytoall = urlencode($message->header
->replyto
);
164 // If we are replying to all, then find all other addresses and
165 // add them to the list. Remove duplicates.
166 // This is somewhat messy, so I'll explain:
167 // 1) Take all addresses (from, to, cc) (avoid nasty join errors here)
168 if (!is_array($message->header
->to
)) { $message->header
->cc
= array($message->header
->to
); }
169 if (!is_array($message->header
->cc
)) { $message->header
->cc
= array($message->header
->cc
); }
170 $url_replytoall_extra_addrs = array_merge(array($message->header
->from
),
171 $message->header
->to
, $message->header
->cc
);
173 // 2) Make one big string out of them
174 $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs);
176 // 3) Parse that into an array of addresses
177 $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs);
179 // 4) Make them unique -- weed out duplicates
180 if (function_exists("array_unique")) {
181 $url_replytoall_extra_addrs = array_unique($url_replytoall_extra_addrs);
184 // 5) Remove the addresses we'll be sending the message 'to'
185 $url_replytoall_avoid_addrs = parseAddrs($message->header
->replyto
);
186 foreach ($url_replytoall_avoid_addrs as $addr)
188 foreach (array_keys($url_replytoall_extra_addrs, $addr) as $key_to_delete)
190 unset($url_replytoall_extra_addrs[$key_to_delete]);
194 // 6) Smoosh back into one nice line
195 $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs);
198 $url_replytoallcc = urlencode($url_replytoallcc);
200 $dateString = getLongDateString($message->header
->date
);
201 $ent_num = findDisplayEntity($message);
203 /** TEXT STRINGS DEFINITIONS **/
204 $echo_more = _("more");
205 $echo_less = _("less");
207 /** FORMAT THE TO STRING **/
210 $to_ary = $message->header
->to
;
211 while ($i < count($to_ary)) {
212 $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i]));
215 $to_string = "$to_string<BR>$to_ary[$i]";
217 $to_string = "$to_ary[$i]";
220 if (count($to_ary) > 1) {
221 if ($show_more == false) {
223 if ($where && $what) {
225 $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>)";
227 $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>)";
231 } else if ($i == 1) {
232 if ($where && $what) {
234 $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>)";
236 $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>)";
242 /** FORMAT THE CC STRING **/
245 $cc_ary = $message->header
->cc
;
246 while ($i < count(decodeHeader($cc_ary))) {
247 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
249 $cc_string = "$cc_string<BR>$cc_ary[$i]";
251 $cc_string = "$cc_ary[$i]";
254 if (count($cc_ary) > 1) {
255 if ($show_more_cc == false) {
257 if ($where && $what) {
259 $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>)";
261 $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>)";
265 } else if ($i == 1) {
266 if ($where && $what) {
268 $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>)";
270 $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>)";
276 /** make sure everything will display in HTML format **/
277 $from_name = decodeHeader(htmlspecialchars($message->header
->from
));
278 $subject = decodeHeader(htmlspecialchars($message->header
->subject
));
280 do_hook("read_body_top");
283 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
284 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
285 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
287 echo " <TD ALIGN=LEFT WIDTH=33%>";
289 if ($where && $what) {
290 echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">";
292 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
294 echo _("Message List");
295 echo "</A> | ";
296 if ($where && $what) {
297 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">";
299 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">";
302 echo "</A> ";
304 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
306 if ($where && $what) {
308 if ($currentArrayIndex == -1) {
309 echo "Previous | Next";
311 $prev = findPreviousMessage();
312 $next = findNextMessage();
314 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | ";
316 echo _("Previous") . " | ";
318 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
324 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
326 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
328 echo "</A> | ";
329 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
331 echo "</A> | ";
332 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\">";
334 echo "</A> ";
340 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
341 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
344 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
346 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
347 echo " <B>$subject</B> \n";
349 if ($where && $what) {
350 // Got here from a search
351 echo " <TD WIDTH=1% bgcolor=\"$color[0]\" nowrap align=right><small><a href=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."&view_hdr=1\">" . _("View full header") . "</a></small> </td>";
353 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> </td>";
358 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
360 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
361 echo " <B>$from_name</B> \n";
366 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
368 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
369 echo " <B>$dateString</B> \n";
374 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
376 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
377 echo " <B>$to_string</B> \n";
381 if ($message->header
->cc
) {
383 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
385 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
386 echo " <B>$cc_string</B> \n";
390 do_hook("read_body_header");
394 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
396 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
399 $body = formatBody($imapConnection, $message, $color, $wrap_at);
403 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
404 echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>";
407 do_hook("read_body_bottom");
408 do_hook("html_bottom");
409 sqimap_logout($imapConnection);