- made the date like Netscape Messenger: if today show time, if this week
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
ef870322 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
2a32fc83 12 session_start();
13
d068c0ec 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");
be69e508 26
c36ed9cf 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>";
e9f8ea4e 37 echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n";
c36ed9cf 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\">";
e9f8ea4e 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";
623332f3 42 echo "<tr><td><pre>";
c36ed9cf 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], ":"));
623332f3 50 $read[$i] = str_replace("$pre", "<b>$pre</b>", decodeHeader($read[$i]));
c36ed9cf 51 }
52 echo "$read[$i]";
53 }
623332f3 54 echo "</pre></td></tr></table>\n";
c36ed9cf 55 echo "</body></html>";
56 exit;
57 }
58
90033b64 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() {
53524fa0 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 }
90033b64 73 return -1;
74 }
75
76 // returns the index of the previous message from the array
77 function findPreviousMessage() {
53524fa0 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 }
90033b64 87 return -1;
88 }
89
90 if (isset($msgs)) {
53524fa0 91 $currentArrayIndex = $passed_id;
92 /*
90033b64 93 for ($i=0; $i < count($msgs); $i++) {
94 if ($msgs[$i]["ID"] == $passed_id) {
95 $currentArrayIndex = $i;
96 break;
97 }
98 }
53524fa0 99 */
90033b64 100 } else {
101 $currentArrayIndex = -1;
102 }
103
1108e8bb 104 for ($i = 0; $i < count($msgs); $i++) {
105 if ($msgs[$i]["ID"] == $passed_id)
106 $msgs[$i]["FLAG_SEEN"] = true;
107 }
108
f7fb20fe 109 // $message contains all information about the message
110 // including header and body
813eba2f 111 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
31f3d7c0 112
f7fb20fe 113 /** translate the subject and mailbox into url-able text **/
8beafbbc 114 $url_subj = urlencode(trim(stripslashes($message->header->subject)));
8467bf00 115 $urlMailbox = urlencode($mailbox);
8beafbbc 116 $url_replyto = urlencode($message->header->replyto);
be69e508 117
8beafbbc 118 $url_replytoall = urlencode($message->header->replyto);
119 $url_replytoallcc = urlencode(getLineOfAddrs($message->header->to) . ", " . getLineOfAddrs($message->header->cc));
4bfed9f3 120
8beafbbc 121 $dateString = getLongDateString($message->header->date);
429f8906 122 $ent_num = findDisplayEntity($message);
31f3d7c0 123
b581fa60 124 /** TEXT STRINGS DEFINITIONS **/
125 $echo_more = _("more");
126 $echo_less = _("less");
127
078a40a4 128 /** FORMAT THE TO STRING **/
2844086d 129 $i = 0;
130 $to_string = "";
8beafbbc 131 $to_ary = $message->header->to;
2844086d 132 while ($i < count($to_ary)) {
f7fb20fe 133 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
be8e07f8 134
2844086d 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) {
9f2215a1 144 $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>)";
2844086d 145 $i = count($to_ary);
146 }
147 } else if ($i == 1) {
9f2215a1 148 $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>)";
2844086d 149 }
150 }
151 }
152
078a40a4 153 /** FORMAT THE CC STRING **/
154 $i = 0;
155 $cc_string = "";
8beafbbc 156 $cc_ary = $message->header->cc;
078a40a4 157 while ($i < count($cc_ary)) {
f7fb20fe 158 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 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) {
9f2215a1 168 $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>)";
078a40a4 169 $i = count($cc_ary);
170 }
171 } else if ($i == 1) {
9f2215a1 172 $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>)";
078a40a4 173 }
174 }
175 }
176
f7fb20fe 177 /** make sure everything will display in HTML format **/
8beafbbc 178 $from_name = decodeHeader(htmlspecialchars($message->header->from));
179 $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject)));
078a40a4 180
8467bf00 181 echo "<BR>";
d68a3926 182 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
c36ed9cf 183 echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>";
4809f489 184 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
31f3d7c0 185 echo " <TR>";
90033b64 186 echo " <TD ALIGN=LEFT WIDTH=33%>";
aae41ae9 187 echo " <SMALL>";
90033b64 188 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
b581fa60 189 echo _("Message List");
190 echo "</A>&nbsp;|&nbsp;";
9f2215a1 191 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
b581fa60 192 echo _("Delete");
193 echo "</A>&nbsp;&nbsp;";
aae41ae9 194 echo " </SMALL>";
90033b64 195 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
196 echo " <SMALL>\n";
197 if ($currentArrayIndex == -1) {
9988d19e 198 echo "Previous&nbsp;|&nbsp;Next";
90033b64 199 } else {
200 $prev = findPreviousMessage();
201 $next = findNextMessage();
202 if ($prev != -1)
d68a3926 203 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
90033b64 204 else
205 echo _("Previous") . "&nbsp;|&nbsp;";
206 if ($next != -1)
d68a3926 207 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
90033b64 208 else
209 echo _("Next");
210 }
211 echo " </SMALL>\n";
212 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
aae41ae9 213 echo " <SMALL>";
429f8906 214 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 215 echo _("Forward");
216 echo "</A>&nbsp;|&nbsp;";
429f8906 217 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">";
b581fa60 218 echo _("Reply");
219 echo "</A>&nbsp;|&nbsp;";
429f8906 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\">";
b581fa60 221 echo _("Reply All");
222 echo "</A>&nbsp;&nbsp;";
aae41ae9 223 echo " </SMALL>";
31f3d7c0 224 echo " </TD>";
225 echo " </TR>";
226 echo " </TABLE>";
8467bf00 227 echo " </TD></TR>";
4809f489 228 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
97afcee9 229 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
be69e508 230 echo " <TR>\n";
231 /** subject **/
c36ed9cf 232 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 233 echo _("Subject:");
c36ed9cf 234 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n";
aae41ae9 235 echo " <B>$subject</B>\n";
be69e508 236 echo " </TD>\n";
c36ed9cf 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>&nbsp;&nbsp;</td>";
be69e508 238 echo " </TR>\n";
239 /** from **/
240 echo " <TR>\n";
c36ed9cf 241 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 242 echo _("From:");
c36ed9cf 243 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
aae41ae9 244 echo " <B>$from_name</B>\n";
be69e508 245 echo " </TD>\n";
246 echo " </TR>\n";
247 /** date **/
248 echo " <TR>\n";
c36ed9cf 249 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n";
32c7898c 250 echo _("Date:");
c36ed9cf 251 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n";
aae41ae9 252 echo " <B>$dateString</B>\n";
be69e508 253 echo " </TD>\n";
254 echo " </TR>\n";
2844086d 255 /** to **/
256 echo " <TR>\n";
c36ed9cf 257 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
b581fa60 258 echo _("To:");
c36ed9cf 259 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
aae41ae9 260 echo " <B>$to_string</B>\n";
2844086d 261 echo " </TD>\n";
262 echo " </TR>\n";
078a40a4 263 /** cc **/
8beafbbc 264 if ($message->header->cc) {
078a40a4 265 echo " <TR>\n";
c36ed9cf 266 echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
aae41ae9 267 echo " Cc:\n";
c36ed9cf 268 echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n";
aae41ae9 269 echo " <B>$cc_string</B>\n";
078a40a4 270 echo " </TD>\n";
271 echo " </TR>\n";
272 }
4809f489 273 echo "</TABLE>";
274 echo " </TD></TR>";
d68a3926 275 echo "</table>";
276 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
be69e508 277
f8f9bed9 278 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
8d8ab69a 279 $body = formatBody($imapConnection, $message, $color, $wrap_at);
4809f489 280 echo "<BR>";
5c55c295 281
7831268e 282 echo "$body";
d4467150 283
7831268e 284 echo " </TD></TR>\n";
d68a3926 285 echo "</table>";
286 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
7831268e 287 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
be69e508 288 echo "</TABLE>\n";
289
1195c340 290 sqimap_logout($imapConnection);
b581fa60 291?>