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); |
441f2d33 |
30 | do_hook("html_top"); |
c36ed9cf |
31 | displayPageHeader($color, $mailbox); |
32 | |
33 | if ($view_hdr) { |
34 | fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n"); |
35 | $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b); |
36 | |
37 | echo "<br>"; |
e9f8ea4e |
38 | echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n"; |
c36ed9cf |
39 | echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - "; |
f4991a86 |
40 | if ($where && $what) { |
41 | // Got here from a search |
42 | echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">"; |
8ae331c2 |
43 | } else { |
f4991a86 |
44 | echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">"; |
45 | } |
e9f8ea4e |
46 | echo ""._("View message") . "</a></b></center></td></tr></table>\n"; |
47 | echo "<table width=99% cellpadding=2 cellspacing=0 border=0 align=center>\n"; |
623332f3 |
48 | echo "<tr><td><pre>"; |
c36ed9cf |
49 | for ($i=1; $i < count($read)-1; $i++) { |
50 | $read[$i] = htmlspecialchars($read[$i]); |
51 | if (substr($read[$i], 0, 1) != "\t" && |
52 | substr($read[$i], 0, 1) != " " && |
53 | substr($read[$i], 0, 1) != "&" && |
54 | trim($read[$i])) { |
55 | $pre = substr($read[$i], 0, strpos($read[$i], ":")); |
623332f3 |
56 | $read[$i] = str_replace("$pre", "<b>$pre</b>", decodeHeader($read[$i])); |
c36ed9cf |
57 | } |
58 | echo "$read[$i]"; |
59 | } |
623332f3 |
60 | echo "</pre></td></tr></table>\n"; |
c36ed9cf |
61 | echo "</body></html>"; |
a2790a61 |
62 | sqimap_mailbox_close($imapConnection); |
eabc2883 |
63 | sqimap_logout($imapConnection); |
c36ed9cf |
64 | exit; |
65 | } |
66 | |
90033b64 |
67 | // given an IMAP message id number, this will look it up in the cached and sorted msgs array and |
68 | // return the index. used for finding the next and previous messages |
69 | |
70 | // returns the index of the next valid message from the array |
71 | function findNextMessage() { |
53524fa0 |
72 | global $msort, $currentArrayIndex, $msgs; |
73 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
74 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
75 | next($msort); |
76 | $key = key($msort); |
77 | if (isset($key)) |
78 | return $msgs[$key]["ID"]; |
79 | } |
80 | } |
90033b64 |
81 | return -1; |
82 | } |
83 | |
84 | // returns the index of the previous message from the array |
85 | function findPreviousMessage() { |
53524fa0 |
86 | global $msort, $currentArrayIndex, $msgs; |
87 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
88 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
89 | prev($msort); |
90 | $key = key($msort); |
91 | if (isset($key)) |
92 | return $msgs[$key]["ID"]; |
93 | } |
94 | } |
90033b64 |
95 | return -1; |
96 | } |
97 | |
98 | if (isset($msgs)) { |
8ae331c2 |
99 | $currentArrayIndex = $passed_id; |
53524fa0 |
100 | /* |
90033b64 |
101 | for ($i=0; $i < count($msgs); $i++) { |
102 | if ($msgs[$i]["ID"] == $passed_id) { |
103 | $currentArrayIndex = $i; |
104 | break; |
105 | } |
106 | } |
53524fa0 |
107 | */ |
90033b64 |
108 | } else { |
109 | $currentArrayIndex = -1; |
110 | } |
111 | |
1108e8bb |
112 | for ($i = 0; $i < count($msgs); $i++) { |
113 | if ($msgs[$i]["ID"] == $passed_id) |
114 | $msgs[$i]["FLAG_SEEN"] = true; |
115 | } |
116 | |
f7fb20fe |
117 | // $message contains all information about the message |
118 | // including header and body |
813eba2f |
119 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
31f3d7c0 |
120 | |
f7fb20fe |
121 | /** translate the subject and mailbox into url-able text **/ |
7aaa81fc |
122 | $url_subj = urlencode(trim(sqStripSlashes($message->header->subject))); |
8467bf00 |
123 | $urlMailbox = urlencode($mailbox); |
8beafbbc |
124 | $url_replyto = urlencode($message->header->replyto); |
be69e508 |
125 | |
8beafbbc |
126 | $url_replytoall = urlencode($message->header->replyto); |
b676ba7e |
127 | $url_replytoallcc = getLineOfAddrs($message->header->to); |
128 | $url_replytoallcc_cc = getLineOfAddrs($message->header->cc); |
129 | if ($url_replytoallcc) { |
130 | if ($url_replytoallcc_cc) { |
131 | $url_replytoallcc .= ", " . $url_replytoallcc_cc; |
132 | } |
133 | } else { |
134 | if ($url_replytoallcc_cc) { |
135 | $url_replytoallcc = $url_replytoallcc_cc; |
136 | } else { |
137 | $url_replytoallcc = ""; |
138 | } |
139 | } |
140 | $url_replytoallcc = urlencode($url_replytoallcc); |
4bfed9f3 |
141 | |
8beafbbc |
142 | $dateString = getLongDateString($message->header->date); |
429f8906 |
143 | $ent_num = findDisplayEntity($message); |
31f3d7c0 |
144 | |
b581fa60 |
145 | /** TEXT STRINGS DEFINITIONS **/ |
146 | $echo_more = _("more"); |
147 | $echo_less = _("less"); |
148 | |
078a40a4 |
149 | /** FORMAT THE TO STRING **/ |
2844086d |
150 | $i = 0; |
151 | $to_string = ""; |
8beafbbc |
152 | $to_ary = $message->header->to; |
2844086d |
153 | while ($i < count($to_ary)) { |
99fa2b21 |
154 | $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i])); |
be8e07f8 |
155 | |
2844086d |
156 | if ($to_string) |
157 | $to_string = "$to_string<BR>$to_ary[$i]"; |
158 | else |
159 | $to_string = "$to_ary[$i]"; |
160 | |
161 | $i++; |
162 | if (count($to_ary) > 1) { |
163 | if ($show_more == false) { |
164 | if ($i == 1) { |
f4991a86 |
165 | if ($where && $what) { |
166 | // from a search |
167 | $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>)"; |
168 | } else { |
169 | $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>)"; |
170 | } |
2844086d |
171 | $i = count($to_ary); |
172 | } |
173 | } else if ($i == 1) { |
f4991a86 |
174 | if ($where && $what) { |
175 | // from a search |
176 | $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>)"; |
177 | } else { |
178 | $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>)"; |
179 | } |
2844086d |
180 | } |
181 | } |
182 | } |
183 | |
078a40a4 |
184 | /** FORMAT THE CC STRING **/ |
185 | $i = 0; |
186 | $cc_string = ""; |
8beafbbc |
187 | $cc_ary = $message->header->cc; |
99fa2b21 |
188 | while ($i < count(decodeHeader($cc_ary))) { |
f7fb20fe |
189 | $cc_ary[$i] = htmlspecialchars($cc_ary[$i]); |
078a40a4 |
190 | if ($cc_string) |
191 | $cc_string = "$cc_string<BR>$cc_ary[$i]"; |
192 | else |
193 | $cc_string = "$cc_ary[$i]"; |
194 | |
195 | $i++; |
196 | if (count($cc_ary) > 1) { |
197 | if ($show_more_cc == false) { |
198 | if ($i == 1) { |
f4991a86 |
199 | if ($where && $what) { |
200 | // from a search |
201 | $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>)"; |
202 | } else { |
203 | $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>)"; |
204 | } |
078a40a4 |
205 | $i = count($cc_ary); |
206 | } |
207 | } else if ($i == 1) { |
f4991a86 |
208 | if ($where && $what) { |
209 | // from a search |
210 | $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>)"; |
211 | } else { |
212 | $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>)"; |
213 | } |
078a40a4 |
214 | } |
215 | } |
216 | } |
217 | |
f7fb20fe |
218 | /** make sure everything will display in HTML format **/ |
8beafbbc |
219 | $from_name = decodeHeader(htmlspecialchars($message->header->from)); |
7aaa81fc |
220 | $subject = decodeHeader(htmlspecialchars($message->header->subject)); |
078a40a4 |
221 | |
06ad27a2 |
222 | do_hook("read_body_top"); |
8467bf00 |
223 | echo "<BR>"; |
8ae331c2 |
224 | |
d68a3926 |
225 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
c36ed9cf |
226 | echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>"; |
4809f489 |
227 | echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>"; |
31f3d7c0 |
228 | echo " <TR>"; |
90033b64 |
229 | echo " <TD ALIGN=LEFT WIDTH=33%>"; |
aae41ae9 |
230 | echo " <SMALL>"; |
1809bad8 |
231 | if ($where && $what) { |
232 | echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">"; |
233 | } else { |
234 | echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">"; |
235 | } |
b581fa60 |
236 | echo _("Message List"); |
237 | echo "</A> | "; |
1809bad8 |
238 | if ($where && $what) { |
99fa2b21 |
239 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">"; |
1809bad8 |
240 | } else { |
d36f3e63 |
241 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">"; |
1809bad8 |
242 | } |
b581fa60 |
243 | echo _("Delete"); |
244 | echo "</A> "; |
aae41ae9 |
245 | echo " </SMALL>"; |
90033b64 |
246 | echo " </TD><TD WIDTH=33% ALIGN=CENTER>"; |
247 | echo " <SMALL>\n"; |
1809bad8 |
248 | if ($where && $what) { |
90033b64 |
249 | } else { |
1809bad8 |
250 | if ($currentArrayIndex == -1) { |
251 | echo "Previous | Next"; |
252 | } else { |
253 | $prev = findPreviousMessage(); |
254 | $next = findNextMessage(); |
255 | if ($prev != -1) |
256 | echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | "; |
257 | else |
258 | echo _("Previous") . " | "; |
259 | if ($next != -1) |
260 | echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>"; |
261 | else |
262 | echo _("Next"); |
263 | } |
264 | } |
90033b64 |
265 | echo " </SMALL>\n"; |
266 | echo " </TD><TD WIDTH=33% ALIGN=RIGHT>"; |
aae41ae9 |
267 | echo " <SMALL>"; |
429f8906 |
268 | echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
269 | echo _("Forward"); |
270 | echo "</A> | "; |
429f8906 |
271 | echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
272 | echo _("Reply"); |
273 | echo "</A> | "; |
429f8906 |
274 | 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 |
275 | echo _("Reply All"); |
276 | echo "</A> "; |
aae41ae9 |
277 | echo " </SMALL>"; |
31f3d7c0 |
278 | echo " </TD>"; |
279 | echo " </TR>"; |
280 | echo " </TABLE>"; |
8467bf00 |
281 | echo " </TD></TR>"; |
4809f489 |
282 | echo " <TR><TD CELLSPACING=0 WIDTH=100%>"; |
97afcee9 |
283 | echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n"; |
be69e508 |
284 | echo " <TR>\n"; |
285 | /** subject **/ |
c36ed9cf |
286 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
287 | echo _("Subject:"); |
c36ed9cf |
288 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n"; |
c221adce |
289 | echo " <B>$subject</B> \n"; |
be69e508 |
290 | echo " </TD>\n"; |
f4991a86 |
291 | if ($where && $what) { |
292 | // Got here from a search |
293 | 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>"; |
294 | } else { |
295 | 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>"; |
296 | } |
be69e508 |
297 | echo " </TR>\n"; |
298 | /** from **/ |
299 | echo " <TR>\n"; |
c36ed9cf |
300 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
301 | echo _("From:"); |
c36ed9cf |
302 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
c221adce |
303 | echo " <B>$from_name</B> \n"; |
be69e508 |
304 | echo " </TD>\n"; |
305 | echo " </TR>\n"; |
306 | /** date **/ |
307 | echo " <TR>\n"; |
c36ed9cf |
308 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
32c7898c |
309 | echo _("Date:"); |
c36ed9cf |
310 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
c221adce |
311 | echo " <B>$dateString</B> \n"; |
be69e508 |
312 | echo " </TD>\n"; |
313 | echo " </TR>\n"; |
2844086d |
314 | /** to **/ |
315 | echo " <TR>\n"; |
c36ed9cf |
316 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
b581fa60 |
317 | echo _("To:"); |
c36ed9cf |
318 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
c221adce |
319 | echo " <B>$to_string</B> \n"; |
2844086d |
320 | echo " </TD>\n"; |
321 | echo " </TR>\n"; |
078a40a4 |
322 | /** cc **/ |
8beafbbc |
323 | if ($message->header->cc) { |
078a40a4 |
324 | echo " <TR>\n"; |
c36ed9cf |
325 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
aae41ae9 |
326 | echo " Cc:\n"; |
c36ed9cf |
327 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
c221adce |
328 | echo " <B>$cc_string</B> \n"; |
078a40a4 |
329 | echo " </TD>\n"; |
330 | echo " </TR>\n"; |
331 | } |
4809f489 |
332 | echo "</TABLE>"; |
333 | echo " </TD></TR>"; |
d68a3926 |
334 | echo "</table>"; |
a48fbf9b |
335 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
be69e508 |
336 | |
f8f9bed9 |
337 | echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n"; |
4809f489 |
338 | echo "<BR>"; |
9297917e |
339 | |
340 | $body = formatBody($imapConnection, $message, $color, $wrap_at); |
5c55c295 |
341 | |
441f2d33 |
342 | echo $body; |
343 | |
d68a3926 |
344 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
7831268e |
345 | echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>"; |
be69e508 |
346 | echo "</TABLE>\n"; |
347 | |
06ad27a2 |
348 | do_hook("read_body_bottom"); |
441f2d33 |
349 | do_hook("html_bottom"); |
1195c340 |
350 | sqimap_logout($imapConnection); |
b581fa60 |
351 | ?> |