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