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