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