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