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