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 | |
12 | |
13 | |
14 | |
15 | |
16 | |
2a32fc83 |
17 | session_start(); |
18 | |
d068c0ec |
19 | if (!isset($config_php)) |
20 | include("../config/config.php"); |
21 | if (!isset($strings_php)) |
22 | include("../functions/strings.php"); |
23 | if (!isset($page_header_php)) |
24 | include("../functions/page_header.php"); |
25 | if (!isset($imap_php)) |
26 | include("../functions/imap.php"); |
27 | if (!isset($mime_php)) |
28 | include("../functions/mime.php"); |
29 | if (!isset($date_php)) |
30 | include("../functions/date.php"); |
be69e508 |
31 | |
90033b64 |
32 | // given an IMAP message id number, this will look it up in the cached and sorted msgs array and |
33 | // return the index. used for finding the next and previous messages |
34 | |
35 | // returns the index of the next valid message from the array |
36 | function findNextMessage() { |
53524fa0 |
37 | global $msort, $currentArrayIndex, $msgs; |
38 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
39 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
40 | next($msort); |
41 | $key = key($msort); |
42 | if (isset($key)) |
43 | return $msgs[$key]["ID"]; |
44 | } |
45 | } |
90033b64 |
46 | return -1; |
47 | } |
48 | |
49 | // returns the index of the previous message from the array |
50 | function findPreviousMessage() { |
53524fa0 |
51 | global $msort, $currentArrayIndex, $msgs; |
52 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
53 | if ($currentArrayIndex == $msgs[$key]["ID"]) { |
54 | prev($msort); |
55 | $key = key($msort); |
56 | if (isset($key)) |
57 | return $msgs[$key]["ID"]; |
58 | } |
59 | } |
90033b64 |
60 | return -1; |
61 | } |
62 | |
63 | if (isset($msgs)) { |
53524fa0 |
64 | $currentArrayIndex = $passed_id; |
65 | /* |
90033b64 |
66 | for ($i=0; $i < count($msgs); $i++) { |
67 | if ($msgs[$i]["ID"] == $passed_id) { |
68 | $currentArrayIndex = $i; |
69 | break; |
70 | } |
71 | } |
53524fa0 |
72 | */ |
90033b64 |
73 | } else { |
74 | $currentArrayIndex = -1; |
75 | } |
76 | |
1108e8bb |
77 | for ($i = 0; $i < count($msgs); $i++) { |
78 | if ($msgs[$i]["ID"] == $passed_id) |
79 | $msgs[$i]["FLAG_SEEN"] = true; |
80 | } |
81 | |
d3cdb279 |
82 | include("../src/load_prefs.php"); |
e1469126 |
83 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
813eba2f |
84 | sqimap_mailbox_select($imapConnection, $mailbox); |
be69e508 |
85 | |
f7fb20fe |
86 | // $message contains all information about the message |
87 | // including header and body |
813eba2f |
88 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
31f3d7c0 |
89 | |
f8f9bed9 |
90 | displayPageHeader($color, $mailbox); |
d4467150 |
91 | |
f7fb20fe |
92 | /** translate the subject and mailbox into url-able text **/ |
8beafbbc |
93 | $url_subj = urlencode(trim(stripslashes($message->header->subject))); |
8467bf00 |
94 | $urlMailbox = urlencode($mailbox); |
8beafbbc |
95 | $url_replyto = urlencode($message->header->replyto); |
be69e508 |
96 | |
8beafbbc |
97 | $url_replytoall = urlencode($message->header->replyto); |
98 | $url_replytoallcc = urlencode(getLineOfAddrs($message->header->to) . ", " . getLineOfAddrs($message->header->cc)); |
4bfed9f3 |
99 | |
8beafbbc |
100 | $dateString = getLongDateString($message->header->date); |
429f8906 |
101 | $ent_num = findDisplayEntity($message); |
31f3d7c0 |
102 | |
b581fa60 |
103 | /** TEXT STRINGS DEFINITIONS **/ |
104 | $echo_more = _("more"); |
105 | $echo_less = _("less"); |
106 | |
078a40a4 |
107 | /** FORMAT THE TO STRING **/ |
2844086d |
108 | $i = 0; |
109 | $to_string = ""; |
8beafbbc |
110 | $to_ary = $message->header->to; |
2844086d |
111 | while ($i < count($to_ary)) { |
f7fb20fe |
112 | $to_ary[$i] = htmlspecialchars($to_ary[$i]); |
be8e07f8 |
113 | |
2844086d |
114 | if ($to_string) |
115 | $to_string = "$to_string<BR>$to_ary[$i]"; |
116 | else |
117 | $to_string = "$to_ary[$i]"; |
118 | |
119 | $i++; |
120 | if (count($to_ary) > 1) { |
121 | if ($show_more == false) { |
122 | if ($i == 1) { |
9f2215a1 |
123 | $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 |
124 | $i = count($to_ary); |
125 | } |
126 | } else if ($i == 1) { |
9f2215a1 |
127 | $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 |
128 | } |
129 | } |
130 | } |
131 | |
078a40a4 |
132 | /** FORMAT THE CC STRING **/ |
133 | $i = 0; |
134 | $cc_string = ""; |
8beafbbc |
135 | $cc_ary = $message->header->cc; |
078a40a4 |
136 | while ($i < count($cc_ary)) { |
f7fb20fe |
137 | $cc_ary[$i] = htmlspecialchars($cc_ary[$i]); |
078a40a4 |
138 | if ($cc_string) |
139 | $cc_string = "$cc_string<BR>$cc_ary[$i]"; |
140 | else |
141 | $cc_string = "$cc_ary[$i]"; |
142 | |
143 | $i++; |
144 | if (count($cc_ary) > 1) { |
145 | if ($show_more_cc == false) { |
146 | if ($i == 1) { |
9f2215a1 |
147 | $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 |
148 | $i = count($cc_ary); |
149 | } |
150 | } else if ($i == 1) { |
9f2215a1 |
151 | $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 |
152 | } |
153 | } |
154 | } |
155 | |
f7fb20fe |
156 | /** make sure everything will display in HTML format **/ |
8beafbbc |
157 | $from_name = decodeHeader(htmlspecialchars($message->header->from)); |
158 | $subject = decodeHeader(htmlspecialchars(stripslashes($message->header->subject))); |
078a40a4 |
159 | |
8467bf00 |
160 | echo "<BR>"; |
4809f489 |
161 | echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n"; |
f8f9bed9 |
162 | echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>"; |
4809f489 |
163 | echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>"; |
31f3d7c0 |
164 | echo " <TR>"; |
90033b64 |
165 | echo " <TD ALIGN=LEFT WIDTH=33%>"; |
aae41ae9 |
166 | echo " <SMALL>"; |
90033b64 |
167 | echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">"; |
b581fa60 |
168 | echo _("Message List"); |
169 | echo "</A> | "; |
9f2215a1 |
170 | echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">"; |
b581fa60 |
171 | echo _("Delete"); |
172 | echo "</A> "; |
aae41ae9 |
173 | echo " </SMALL>"; |
90033b64 |
174 | echo " </TD><TD WIDTH=33% ALIGN=CENTER>"; |
175 | echo " <SMALL>\n"; |
176 | if ($currentArrayIndex == -1) { |
9988d19e |
177 | echo "Previous | Next"; |
90033b64 |
178 | } else { |
179 | $prev = findPreviousMessage(); |
180 | $next = findNextMessage(); |
181 | if ($prev != -1) |
182 | echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A> | "; |
183 | else |
184 | echo _("Previous") . " | "; |
185 | if ($next != -1) |
186 | echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>"; |
187 | else |
188 | echo _("Next"); |
189 | } |
190 | echo " </SMALL>\n"; |
191 | echo " </TD><TD WIDTH=33% ALIGN=RIGHT>"; |
aae41ae9 |
192 | echo " <SMALL>"; |
429f8906 |
193 | echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
194 | echo _("Forward"); |
195 | echo "</A> | "; |
429f8906 |
196 | echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">"; |
b581fa60 |
197 | echo _("Reply"); |
198 | echo "</A> | "; |
429f8906 |
199 | 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 |
200 | echo _("Reply All"); |
201 | echo "</A> "; |
aae41ae9 |
202 | echo " </SMALL>"; |
31f3d7c0 |
203 | echo " </TD>"; |
204 | echo " </TR>"; |
205 | echo " </TABLE>"; |
8467bf00 |
206 | echo " </TD></TR>"; |
4809f489 |
207 | echo " <TR><TD CELLSPACING=0 WIDTH=100%>"; |
97afcee9 |
208 | echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n"; |
be69e508 |
209 | echo " <TR>\n"; |
210 | /** subject **/ |
4809f489 |
211 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
212 | echo _("Subject:"); |
f8f9bed9 |
213 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n"; |
aae41ae9 |
214 | echo " <B>$subject</B>\n"; |
be69e508 |
215 | echo " </TD>\n"; |
216 | echo " </TR>\n"; |
217 | /** from **/ |
218 | echo " <TR>\n"; |
4809f489 |
219 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n"; |
b581fa60 |
220 | echo _("From:"); |
f8f9bed9 |
221 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n"; |
aae41ae9 |
222 | echo " <B>$from_name</B>\n"; |
be69e508 |
223 | echo " </TD>\n"; |
224 | echo " </TR>\n"; |
225 | /** date **/ |
226 | echo " <TR>\n"; |
4809f489 |
227 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n"; |
32c7898c |
228 | echo _("Date:"); |
f8f9bed9 |
229 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n"; |
aae41ae9 |
230 | echo " <B>$dateString</B>\n"; |
be69e508 |
231 | echo " </TD>\n"; |
232 | echo " </TR>\n"; |
2844086d |
233 | /** to **/ |
234 | echo " <TR>\n"; |
4809f489 |
235 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
b581fa60 |
236 | echo _("To:"); |
f8f9bed9 |
237 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n"; |
aae41ae9 |
238 | echo " <B>$to_string</B>\n"; |
2844086d |
239 | echo " </TD>\n"; |
240 | echo " </TR>\n"; |
078a40a4 |
241 | /** cc **/ |
8beafbbc |
242 | if ($message->header->cc) { |
078a40a4 |
243 | echo " <TR>\n"; |
4809f489 |
244 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n"; |
aae41ae9 |
245 | echo " Cc:\n"; |
f8f9bed9 |
246 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n"; |
aae41ae9 |
247 | echo " <B>$cc_string</B>\n"; |
078a40a4 |
248 | echo " </TD>\n"; |
249 | echo " </TR>\n"; |
250 | } |
4809f489 |
251 | echo "</TABLE>"; |
252 | echo " </TD></TR>"; |
be69e508 |
253 | |
f8f9bed9 |
254 | echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n"; |
11307a4c |
255 | $body = formatBody($message, $color, $wrap_at); |
4809f489 |
256 | echo "<BR>"; |
5c55c295 |
257 | |
7831268e |
258 | echo "$body"; |
d4467150 |
259 | |
7831268e |
260 | echo " </TD></TR>\n"; |
261 | echo " <TR><TD BGCOLOR=\"$color[9]\"> </TD></TR>"; |
be69e508 |
262 | echo "</TABLE>\n"; |
263 | |
b581fa60 |
264 | ?> |