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); |
124 | $url_replytoallcc = urlencode(getLineOfAddrs($message->header->to) . ", " . getLineOfAddrs($message->header->cc)); |
4bfed9f3 |
125 | |
8beafbbc |
126 | $dateString = getLongDateString($message->header->date); |
429f8906 |
127 | $ent_num = findDisplayEntity($message); |
31f3d7c0 |
128 | |
b581fa60 |
129 | /** TEXT STRINGS DEFINITIONS **/ |
130 | $echo_more = _("more"); |
131 | $echo_less = _("less"); |
132 | |
078a40a4 |
133 | /** FORMAT THE TO STRING **/ |
2844086d |
134 | $i = 0; |
135 | $to_string = ""; |
8beafbbc |
136 | $to_ary = $message->header->to; |
2844086d |
137 | while ($i < count($to_ary)) { |
99fa2b21 |
138 | $to_ary[$i] = htmlspecialchars(decodeHeader($to_ary[$i])); |
be8e07f8 |
139 | |
2844086d |
140 | if ($to_string) |
141 | $to_string = "$to_string<BR>$to_ary[$i]"; |
142 | else |
143 | $to_string = "$to_ary[$i]"; |
144 | |
145 | $i++; |
146 | if (count($to_ary) > 1) { |
147 | if ($show_more == false) { |
148 | if ($i == 1) { |
f4991a86 |
149 | if ($where && $what) { |
150 | // from a search |
151 | $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>)"; |
152 | } else { |
153 | $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>)"; |
154 | } |
2844086d |
155 | $i = count($to_ary); |
156 | } |
157 | } else if ($i == 1) { |
f4991a86 |
158 | if ($where && $what) { |
159 | // from a search |
160 | $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>)"; |
161 | } else { |
162 | $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>)"; |
163 | } |
2844086d |
164 | } |
165 | } |
166 | } |
167 | |
078a40a4 |
168 | /** FORMAT THE CC STRING **/ |
169 | $i = 0; |
170 | $cc_string = ""; |
8beafbbc |
171 | $cc_ary = $message->header->cc; |
99fa2b21 |
172 | while ($i < count(decodeHeader($cc_ary))) { |
f7fb20fe |
173 | $cc_ary[$i] = htmlspecialchars($cc_ary[$i]); |
078a40a4 |
174 | if ($cc_string) |
175 | $cc_string = "$cc_string<BR>$cc_ary[$i]"; |
176 | else |
177 | $cc_string = "$cc_ary[$i]"; |
178 | |
179 | $i++; |
180 | if (count($cc_ary) > 1) { |
181 | if ($show_more_cc == false) { |
182 | if ($i == 1) { |
f4991a86 |
183 | if ($where && $what) { |
184 | // from a search |
185 | $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>)"; |
186 | } else { |
187 | $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>)"; |
188 | } |
078a40a4 |
189 | $i = count($cc_ary); |
190 | } |
191 | } else if ($i == 1) { |
f4991a86 |
192 | if ($where && $what) { |
193 | // from a search |
194 | $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>)"; |
195 | } else { |
196 | $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>)"; |
197 | } |
078a40a4 |
198 | } |
199 | } |
200 | } |
201 | |
f7fb20fe |
202 | /** make sure everything will display in HTML format **/ |
8beafbbc |
203 | $from_name = decodeHeader(htmlspecialchars($message->header->from)); |
204 | $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject))); |
078a40a4 |
205 | |
8467bf00 |
206 | echo "<BR>"; |
d68a3926 |
207 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
c36ed9cf |
208 | echo " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=100%>"; |
4809f489 |
209 | echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>"; |
31f3d7c0 |
210 | echo " <TR>"; |
90033b64 |
211 | echo " <TD ALIGN=LEFT WIDTH=33%>"; |
aae41ae9 |
212 | echo " <SMALL>"; |
1809bad8 |
213 | if ($where && $what) { |
214 | echo " <A HREF=\"search.php?where=".urlencode($where)."&what=".urlencode($what)."&mailbox=$urlMailbox\">"; |
215 | } else { |
216 | echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">"; |
217 | } |
b581fa60 |
218 | echo _("Message List"); |
219 | echo "</A> | "; |
1809bad8 |
220 | if ($where && $what) { |
99fa2b21 |
221 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&where=".urlencode($where)."&what=".urlencode($what)."\">"; |
1809bad8 |
222 | } else { |
223 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">"; |
224 | } |
b581fa60 |
225 | echo _("Delete"); |
226 | echo "</A> "; |
aae41ae9 |
227 | echo " </SMALL>"; |
90033b64 |
228 | echo " </TD><TD WIDTH=33% ALIGN=CENTER>"; |
229 | echo " <SMALL>\n"; |
1809bad8 |
230 | if ($where && $what) { |
90033b64 |
231 | } else { |
1809bad8 |
232 | if ($currentArrayIndex == -1) { |
233 | echo "Previous | Next"; |
234 | } else { |
235 | $prev = findPreviousMessage(); |
236 | $next = findNextMessage(); |
237 | if ($prev != -1) |
238 | echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | "; |
239 | else |
240 | echo _("Previous") . " | "; |
241 | if ($next != -1) |
242 | echo "<a href=\"read_body.php?passed_id=$next&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>"; |
243 | else |
244 | echo _("Next"); |
245 | } |
246 | } |
90033b64 |
247 | echo " </SMALL>\n"; |
248 | echo " </TD><TD WIDTH=33% ALIGN=RIGHT>"; |
aae41ae9 |
249 | echo " <SMALL>"; |
429f8906 |
250 | echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
251 | echo _("Forward"); |
252 | echo "</A> | "; |
429f8906 |
253 | echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
254 | echo _("Reply"); |
255 | echo "</A> | "; |
429f8906 |
256 | 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 |
257 | echo _("Reply All"); |
258 | echo "</A> "; |
aae41ae9 |
259 | echo " </SMALL>"; |
31f3d7c0 |
260 | echo " </TD>"; |
261 | echo " </TR>"; |
262 | echo " </TABLE>"; |
8467bf00 |
263 | echo " </TD></TR>"; |
4809f489 |
264 | echo " <TR><TD CELLSPACING=0 WIDTH=100%>"; |
97afcee9 |
265 | echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n"; |
be69e508 |
266 | echo " <TR>\n"; |
267 | /** subject **/ |
c36ed9cf |
268 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
269 | echo _("Subject:"); |
c36ed9cf |
270 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=84%>\n"; |
aae41ae9 |
271 | echo " <B>$subject</B>\n"; |
be69e508 |
272 | echo " </TD>\n"; |
f4991a86 |
273 | if ($where && $what) { |
274 | // Got here from a search |
275 | 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>"; |
276 | } else { |
277 | 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>"; |
278 | } |
be69e508 |
279 | echo " </TR>\n"; |
280 | /** from **/ |
281 | echo " <TR>\n"; |
c36ed9cf |
282 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
283 | echo _("From:"); |
c36ed9cf |
284 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
aae41ae9 |
285 | echo " <B>$from_name</B>\n"; |
be69e508 |
286 | echo " </TD>\n"; |
287 | echo " </TR>\n"; |
288 | /** date **/ |
289 | echo " <TR>\n"; |
c36ed9cf |
290 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT>\n"; |
32c7898c |
291 | echo _("Date:"); |
c36ed9cf |
292 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% colspan=2>\n"; |
aae41ae9 |
293 | echo " <B>$dateString</B>\n"; |
be69e508 |
294 | echo " </TD>\n"; |
295 | echo " </TR>\n"; |
2844086d |
296 | /** to **/ |
297 | echo " <TR>\n"; |
c36ed9cf |
298 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
b581fa60 |
299 | echo _("To:"); |
c36ed9cf |
300 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
aae41ae9 |
301 | echo " <B>$to_string</B>\n"; |
2844086d |
302 | echo " </TD>\n"; |
303 | echo " </TR>\n"; |
078a40a4 |
304 | /** cc **/ |
8beafbbc |
305 | if ($message->header->cc) { |
078a40a4 |
306 | echo " <TR>\n"; |
c36ed9cf |
307 | echo " <TD BGCOLOR=\"$color[0]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
aae41ae9 |
308 | echo " Cc:\n"; |
c36ed9cf |
309 | echo " </TD><TD BGCOLOR=\"$color[0]\" WIDTH=85% VALIGN=TOP colspan=2>\n"; |
aae41ae9 |
310 | echo " <B>$cc_string</B>\n"; |
078a40a4 |
311 | echo " </TD>\n"; |
312 | echo " </TR>\n"; |
313 | } |
4809f489 |
314 | echo "</TABLE>"; |
315 | echo " </TD></TR>"; |
d68a3926 |
316 | echo "</table>"; |
a48fbf9b |
317 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=97% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
be69e508 |
318 | |
f8f9bed9 |
319 | echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n"; |
4809f489 |
320 | echo "<BR>"; |
9297917e |
321 | |
322 | $body = formatBody($imapConnection, $message, $color, $wrap_at); |
5c55c295 |
323 | |
7831268e |
324 | echo "$body"; |
d4467150 |
325 | |
7831268e |
326 | echo " </TD></TR>\n"; |
d68a3926 |
327 | echo "</table>"; |
328 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=100% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
7831268e |
329 | echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>"; |
be69e508 |
330 | echo "</TABLE>\n"; |
331 | |
1195c340 |
332 | sqimap_logout($imapConnection); |
b581fa60 |
333 | ?> |