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