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. |
245a6892 |
10 | ** |
11 | ** $Id$ |
ef870322 |
12 | **/ |
13 | |
2a32fc83 |
14 | session_start(); |
15 | |
d068c0ec |
16 | if (!isset($strings_php)) |
17 | include("../functions/strings.php"); |
245a6892 |
18 | if (!isset($config_php)) |
19 | include("../config/config.php"); |
d068c0ec |
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"); |
172fd718 |
28 | if (!isset($url_parser_php)) |
29 | include("../functions/url_parser.php"); |
be69e508 |
30 | |
c36ed9cf |
31 | include("../src/load_prefs.php"); |
32 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
33 | sqimap_mailbox_select($imapConnection, $mailbox); |
441f2d33 |
34 | do_hook("html_top"); |
c36ed9cf |
35 | displayPageHeader($color, $mailbox); |
36 | |
245a6892 |
37 | if (isset($view_hdr)) { |
c36ed9cf |
38 | fputs ($imapConnection, "a003 FETCH $passed_id BODY[HEADER]\r\n"); |
39 | $read = sqimap_read_data ($imapConnection, "a003", true, $a, $b); |
40 | |
41 | echo "<br>"; |
e9f8ea4e |
42 | echo "<table width=100% cellpadding=2 cellspacing=0 border=0 align=center>\n"; |
c36ed9cf |
43 | echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%><center><b>" . _("Viewing full header") . "</b> - "; |
f4991a86 |
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)."\">"; |
8ae331c2 |
47 | } else { |
f4991a86 |
48 | echo "<a href=\"read_body.php?mailbox=".urlencode($mailbox)."&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">"; |
49 | } |
e9f8ea4e |
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"; |
5c54e435 |
52 | echo "<tr><td>"; |
53 | |
c36ed9cf |
54 | for ($i=1; $i < count($read)-1; $i++) { |
5c54e435 |
55 | $line = htmlspecialchars($read[$i]); |
172fd718 |
56 | if (eregi("^>", $line)) { |
57 | $second[$i] = $line; |
58 | $first[$i] = " "; |
59 | $cnum++; |
60 | } else if (eregi("^[ |\t]", $line)) { |
61 | $second[$i] = $line; |
62 | $first[$i] = ""; |
63 | } else if (eregi("^([^:]+):(.+)", $line, $regs)) { |
64 | $first[$i] = $regs[1] . ":"; |
65 | $second[$i] = $regs[2]; |
66 | $cnum++; |
5c54e435 |
67 | } else { |
172fd718 |
68 | $second[$i] = trim($line); |
69 | $first[$i] = ""; |
c36ed9cf |
70 | } |
172fd718 |
71 | } |
72 | for ($i=0; $i < count($second); $i = $j) { |
73 | $f = $first[$i]; |
74 | $s = nl2br($second[$i]); |
75 | $j = $i + 1; |
76 | while ($first[$j] == "" && $j < count($first)) { |
77 | $s .= " " . nl2br($second[$j]); |
78 | $j++; |
79 | } |
80 | parseEmail($s); |
81 | echo "<nobr><tt><b>$f</b>$s</tt></nobr>"; |
c36ed9cf |
82 | } |
5c54e435 |
83 | echo "</td></tr></table>\n"; |
c36ed9cf |
84 | echo "</body></html>"; |
eabc2883 |
85 | sqimap_logout($imapConnection); |
c36ed9cf |
86 | exit; |
87 | } |
88 | |
90033b64 |
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 |
91 | |
92 | // returns the index of the next valid message from the array |
93 | function findNextMessage() { |
5c54e435 |
94 | global $msort, $currentArrayIndex, $msgs, $sort; |
95 | |
96 | if ($sort == 6) { |
97 | if ($currentArrayIndex != 1) { |
98 | return $currentArrayIndex - 1; |
99 | } |
100 | } else { |
101 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
102 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
103 | next($msort); |
104 | $key = key($msort); |
105 | if (isset($key)) |
106 | return $msgs[$key]["ID"]; |
107 | } |
108 | } |
109 | } |
90033b64 |
110 | return -1; |
111 | } |
112 | |
113 | // returns the index of the previous message from the array |
114 | function findPreviousMessage() { |
5c54e435 |
115 | global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, $mailbox; |
116 | if ($sort == 6) { |
117 | $numMessages = sqimap_get_num_messages($imapConnection, $mailbox); |
118 | if ($currentArrayIndex != $numMessages) { |
119 | return $currentArrayIndex + 1; |
120 | } |
121 | } else { |
122 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
123 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
124 | prev($msort); |
125 | $key = key($msort); |
126 | if (isset($key)) |
127 | return $msgs[$key]["ID"]; |
128 | } |
129 | } |
130 | } |
90033b64 |
131 | return -1; |
132 | } |
133 | |
134 | if (isset($msgs)) { |
8ae331c2 |
135 | $currentArrayIndex = $passed_id; |
53524fa0 |
136 | /* |
90033b64 |
137 | for ($i=0; $i < count($msgs); $i++) { |
138 | if ($msgs[$i]["ID"] == $passed_id) { |
139 | $currentArrayIndex = $i; |
140 | break; |
141 | } |
142 | } |
53524fa0 |
143 | */ |
90033b64 |
144 | } else { |
145 | $currentArrayIndex = -1; |
146 | } |
147 | |
1108e8bb |
148 | for ($i = 0; $i < count($msgs); $i++) { |
149 | if ($msgs[$i]["ID"] == $passed_id) |
150 | $msgs[$i]["FLAG_SEEN"] = true; |
151 | } |
152 | |
f7fb20fe |
153 | // $message contains all information about the message |
154 | // including header and body |
813eba2f |
155 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
31f3d7c0 |
156 | |
f7fb20fe |
157 | /** translate the subject and mailbox into url-able text **/ |
7aaa81fc |
158 | $url_subj = urlencode(trim(sqStripSlashes($message->header->subject))); |
8467bf00 |
159 | $urlMailbox = urlencode($mailbox); |
8beafbbc |
160 | $url_replyto = urlencode($message->header->replyto); |
be69e508 |
161 | |
8beafbbc |
162 | $url_replytoall = urlencode($message->header->replyto); |
5bc39e3f |
163 | |
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 | $url_replytoall_extra_addrs = array_merge(array($message->header->from), |
169 | $message->header->to, $message->header->cc); |
170 | |
171 | // 2) Make one big string out of them |
172 | $url_replytoall_extra_addrs = join(';', $url_replytoall_extra_addrs); |
173 | |
174 | // 3) Parse that into an array of addresses |
175 | $url_replytoall_extra_addrs = parseAddrs($url_replytoall_extra_addrs); |
176 | |
177 | // 4) Make them unique -- weed out duplicates |
40023540 |
178 | // (Coded for PHP 4.0.0) |
179 | $url_replytoall_extra_addrs = |
180 | array_keys(array_flip($url_replytoall_extra_addrs); |
5bc39e3f |
181 | |
182 | // 5) Remove the addresses we'll be sending the message 'to' |
183 | $url_replytoall_avoid_addrs = parseAddrs($message->header->replyto); |
184 | foreach ($url_replytoall_avoid_addrs as $addr) |
185 | { |
186 | foreach (array_keys($url_replytoall_extra_addrs, $addr) as $key_to_delete) |
187 | { |
188 | unset($url_replytoall_extra_addrs[$key_to_delete]); |
189 | } |
190 | } |
191 | |
192 | // 6) Smoosh back into one nice line |
193 | $url_replytoallcc = getLineOfAddrs($url_replytoall_extra_addrs); |
194 | |
195 | // 7) urlencode() it |
b676ba7e |
196 | $url_replytoallcc = urlencode($url_replytoallcc); |
4bfed9f3 |
197 | |
8beafbbc |
198 | $dateString = getLongDateString($message->header->date); |
429f8906 |
199 | $ent_num = findDisplayEntity($message); |
31f3d7c0 |
200 | |
b581fa60 |
201 | /** TEXT STRINGS DEFINITIONS **/ |
202 | $echo_more = _("more"); |
203 | $echo_less = _("less"); |
204 | |
078a40a4 |
205 | /** FORMAT THE TO STRING **/ |
2844086d |
206 | $i = 0; |
207 | $to_string = ""; |
8beafbbc |
208 | $to_ary = $message->header->to; |
2844086d |
209 | while ($i < count($to_ary)) { |
99fa2b21 |
210 | $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i])); |
be8e07f8 |
211 | |
2844086d |
212 | if ($to_string) |
213 | $to_string = "$to_string<BR>$to_ary[$i]"; |
214 | else |
215 | $to_string = "$to_ary[$i]"; |
216 | |
217 | $i++; |
218 | if (count($to_ary) > 1) { |
219 | if ($show_more == false) { |
220 | if ($i == 1) { |
f4991a86 |
221 | if ($where && $what) { |
222 | // from a search |
223 | $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>)"; |
224 | } else { |
225 | $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>)"; |
226 | } |
2844086d |
227 | $i = count($to_ary); |
228 | } |
229 | } else if ($i == 1) { |
f4991a86 |
230 | if ($where && $what) { |
231 | // from a search |
232 | $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>)"; |
233 | } else { |
234 | $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>)"; |
235 | } |
2844086d |
236 | } |
237 | } |
238 | } |
239 | |
078a40a4 |
240 | /** FORMAT THE CC STRING **/ |
241 | $i = 0; |
e7681707 |
242 | if (isset ($message->header->cc[0]) && trim($message->header->cc[0])){ |
243 | $cc_string = ""; |
244 | $cc_ary = $message->header->cc; |
245 | while ($i < count(decodeHeader($cc_ary))) { |
246 | $cc_ary[$i] = htmlspecialchars($cc_ary[$i]); |
247 | if ($cc_string) |
248 | $cc_string = "$cc_string<BR>$cc_ary[$i]"; |
249 | else |
250 | $cc_string = "$cc_ary[$i]"; |
251 | |
252 | $i++; |
253 | if (count($cc_ary) > 1) { |
254 | if ($show_more_cc == false) { |
255 | if ($i == 1) { |
256 | if ($where && $what) { |
257 | // from a search |
258 | $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>)"; |
259 | } else { |
260 | $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>)"; |
261 | } |
262 | $i = count($cc_ary); |
263 | } |
264 | } else if ($i == 1) { |
f4991a86 |
265 | if ($where && $what) { |
266 | // from a search |
e7681707 |
267 | $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>)"; |
f4991a86 |
268 | } else { |
e7681707 |
269 | $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>)"; |
f4991a86 |
270 | } |
078a40a4 |
271 | } |
078a40a4 |
272 | } |
273 | } |
274 | } |
f7fb20fe |
275 | /** make sure everything will display in HTML format **/ |
8beafbbc |
276 | $from_name = decodeHeader(htmlspecialchars($message->header->from)); |
7aaa81fc |
277 | $subject = decodeHeader(htmlspecialchars($message->header->subject)); |
078a40a4 |
278 | |
06ad27a2 |
279 | do_hook("read_body_top"); |
8467bf00 |
280 | echo "<BR>"; |
8ae331c2 |
281 | |
d68a3926 |
282 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
c36ed9cf |
283 | echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>"; |
4809f489 |
284 | echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>"; |
31f3d7c0 |
285 | echo " <TR>"; |
90033b64 |
286 | echo " <TD ALIGN=LEFT WIDTH=33%>"; |
aae41ae9 |
287 | echo " <SMALL>"; |
1809bad8 |
288 | if ($where && $what) { |
289 | echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">"; |
290 | } else { |
291 | echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">"; |
292 | } |
b581fa60 |
293 | echo _("Message List"); |
294 | echo "</A> | "; |
1809bad8 |
295 | if ($where && $what) { |
99fa2b21 |
296 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">"; |
1809bad8 |
297 | } else { |
d36f3e63 |
298 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=$startMessage\">"; |
1809bad8 |
299 | } |
b581fa60 |
300 | echo _("Delete"); |
301 | echo "</A> "; |
aae41ae9 |
302 | echo " </SMALL>"; |
90033b64 |
303 | echo " </TD><TD WIDTH=33% ALIGN=CENTER>"; |
304 | echo " <SMALL>\n"; |
1809bad8 |
305 | if ($where && $what) { |
90033b64 |
306 | } else { |
1809bad8 |
307 | if ($currentArrayIndex == -1) { |
308 | echo "Previous | Next"; |
309 | } else { |
310 | $prev = findPreviousMessage(); |
311 | $next = findNextMessage(); |
312 | if ($prev != -1) |
313 | echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | "; |
314 | else |
315 | echo _("Previous") . " | "; |
316 | if ($next != -1) |
317 | echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>"; |
318 | else |
319 | echo _("Next"); |
320 | } |
321 | } |
90033b64 |
322 | echo " </SMALL>\n"; |
323 | echo " </TD><TD WIDTH=33% ALIGN=RIGHT>"; |
aae41ae9 |
324 | echo " <SMALL>"; |
429f8906 |
325 | echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
326 | echo _("Forward"); |
327 | echo "</A> | "; |
429f8906 |
328 | echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
329 | echo _("Reply"); |
330 | echo "</A> | "; |
429f8906 |
331 | 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 |
332 | echo _("Reply All"); |
333 | echo "</A> "; |
aae41ae9 |
334 | echo " </SMALL>"; |
31f3d7c0 |
335 | echo " </TD>"; |
336 | echo " </TR>"; |
337 | echo " </TABLE>"; |
8467bf00 |
338 | echo " </TD></TR>"; |
4809f489 |
339 | echo " <TR><TD CELLSPACING=0 WIDTH=100%>"; |
97afcee9 |
340 | echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n"; |
be69e508 |
341 | echo " <TR>\n"; |
342 | /** subject **/ |
c36ed9cf |
343 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
344 | echo _("Subject:"); |
c36ed9cf |
345 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n"; |
c221adce |
346 | echo " <B>$subject</B> \n"; |
be69e508 |
347 | echo " </TD>\n"; |
f4991a86 |
348 | if ($where && $what) { |
349 | // Got here from a search |
350 | 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>"; |
351 | } else { |
352 | 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>"; |
353 | } |
be69e508 |
354 | echo " </TR>\n"; |
355 | /** from **/ |
356 | echo " <TR>\n"; |
c36ed9cf |
357 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
358 | echo _("From:"); |
c36ed9cf |
359 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
c221adce |
360 | echo " <B>$from_name</B> \n"; |
be69e508 |
361 | echo " </TD>\n"; |
362 | echo " </TR>\n"; |
363 | /** date **/ |
364 | echo " <TR>\n"; |
c36ed9cf |
365 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
32c7898c |
366 | echo _("Date:"); |
c36ed9cf |
367 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
c221adce |
368 | echo " <B>$dateString</B> \n"; |
be69e508 |
369 | echo " </TD>\n"; |
370 | echo " </TR>\n"; |
2844086d |
371 | /** to **/ |
372 | echo " <TR>\n"; |
c36ed9cf |
373 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
b581fa60 |
374 | echo _("To:"); |
c36ed9cf |
375 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
c221adce |
376 | echo " <B>$to_string</B> \n"; |
2844086d |
377 | echo " </TD>\n"; |
378 | echo " </TR>\n"; |
078a40a4 |
379 | /** cc **/ |
e7681707 |
380 | if (isset($cc_string)) { |
078a40a4 |
381 | echo " <TR>\n"; |
c36ed9cf |
382 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
aae41ae9 |
383 | echo " Cc:\n"; |
c36ed9cf |
384 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
c221adce |
385 | echo " <B>$cc_string</B> \n"; |
078a40a4 |
386 | echo " </TD>\n"; |
387 | echo " </TR>\n"; |
388 | } |
cc24badd |
389 | do_hook("read_body_header"); |
4809f489 |
390 | echo "</TABLE>"; |
391 | echo " </TD></TR>"; |
d68a3926 |
392 | echo "</table>"; |
a48fbf9b |
393 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
be69e508 |
394 | |
f8f9bed9 |
395 | echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n"; |
4809f489 |
396 | echo "<BR>"; |
9297917e |
397 | |
398 | $body = formatBody($imapConnection, $message, $color, $wrap_at); |
5c55c295 |
399 | |
441f2d33 |
400 | echo $body; |
401 | |
d68a3926 |
402 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
7831268e |
403 | echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>"; |
be69e508 |
404 | echo "</TABLE>\n"; |
405 | |
06ad27a2 |
406 | do_hook("read_body_bottom"); |
441f2d33 |
407 | do_hook("html_bottom"); |
1195c340 |
408 | sqimap_logout($imapConnection); |
b581fa60 |
409 | ?> |