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