59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * read_body.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file is used for reading the msgs array and displaying |
10 | * the resulting emails in the right frame. |
11 | * |
12 | * $Id$ |
a07cd1a4 |
13 | */ |
35586184 |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/imap.php'); |
21 | require_once(SM_PATH . 'functions/mime.php'); |
22 | require_once(SM_PATH . 'functions/date.php'); |
23 | require_once(SM_PATH . 'functions/url_parser.php'); |
24 | require_once(SM_PATH . 'functions/html.php'); |
38c944cc |
25 | |
a07cd1a4 |
26 | /** |
1fca12b5 |
27 | * Given an IMAP message id number, this will look it up in the cached |
28 | * and sorted msgs array and return the index. Used for finding the next |
29 | * and previous messages. |
30 | * |
31 | * @return the index of the next valid message from the array |
32 | */ |
c615b1da |
33 | function findNextMessage($passed_id) { |
34 | global $msort, $msgs, $sort, |
cf710efe |
35 | $thread_sort_messages, $allow_server_sort, |
60a3e687 |
36 | $server_sort_array; |
2728fa19 |
37 | if (!is_array($server_sort_array)) { |
38 | $thread_sort_messages = 0; |
794d59c0 |
39 | $allow_server_sort = FALSE; |
2728fa19 |
40 | } |
a07cd1a4 |
41 | $result = -1; |
c615b1da |
42 | if ($thread_sort_messages || $allow_server_sort) { |
d9c1dccc |
43 | $count = count($server_sort_array) - 1; |
44 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
45 | if ($passed_id == $value) { |
d9c1dccc |
46 | if ($key == $count) { |
60a3e687 |
47 | break; |
48 | } |
1fca12b5 |
49 | $result = $server_sort_array[$key + 1]; |
60a3e687 |
50 | break; |
789b4d79 |
51 | } |
60a3e687 |
52 | } |
d9c1dccc |
53 | } else { |
7e818af0 |
54 | if (is_array($msort)) { |
55 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
56 | if ($passed_id == $msgs[$key]['ID']) { |
57 | next($msort); |
58 | $key = key($msort); |
59 | if (isset($key)){ |
60 | $result = $msgs[$key]['ID']; |
61 | break; |
d9c1dccc |
62 | } |
1fca12b5 |
63 | } |
10f0ce72 |
64 | } |
65 | } |
10f0ce72 |
66 | } |
d9c1dccc |
67 | return $result; |
a07cd1a4 |
68 | } |
69 | |
a07cd1a4 |
70 | /** returns the index of the previous message from the array. */ |
c615b1da |
71 | function findPreviousMessage($numMessages, $passed_id) { |
72 | global $msort, $sort, $msgs, |
73 | $thread_sort_messages, |
60a3e687 |
74 | $allow_server_sort, $server_sort_array; |
a07cd1a4 |
75 | $result = -1; |
2728fa19 |
76 | if (!is_array($server_sort_array)) { |
77 | $thread_sort_messages = 0; |
794d59c0 |
78 | $allow_server_sort = FALSE; |
2728fa19 |
79 | } |
c615b1da |
80 | if ($thread_sort_messages || $allow_server_sort ) { |
d9c1dccc |
81 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
82 | if ($passed_id == $value) { |
60a3e687 |
83 | if ($key == 0) { |
60a3e687 |
84 | break; |
85 | } |
d9c1dccc |
86 | $result = $server_sort_array[$key - 1]; |
60a3e687 |
87 | break; |
789b4d79 |
88 | } |
60a3e687 |
89 | } |
d9c1dccc |
90 | } else { |
7e818af0 |
91 | if (is_array($msort)) { |
92 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
93 | if ($passed_id == $msgs[$key]['ID']) { |
94 | prev($msort); |
95 | $key = key($msort); |
96 | if (isset($key)) { |
97 | $result = $msgs[$key]['ID']; |
98 | break; |
d9c1dccc |
99 | } |
10f0ce72 |
100 | } |
101 | } |
10f0ce72 |
102 | } |
a07cd1a4 |
103 | } |
d9c1dccc |
104 | return $result; |
a07cd1a4 |
105 | } |
10f0ce72 |
106 | |
a07cd1a4 |
107 | /** |
1fca12b5 |
108 | * Displays a link to a page where the message is displayed more |
109 | * "printer friendly". |
110 | */ |
c615b1da |
111 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
112 | global $javascript_on; |
a07cd1a4 |
113 | |
c615b1da |
114 | $params = '?passed_ent_id=' . $passed_ent_id . |
1ba8cd6b |
115 | '&mailbox=' . urlencode($mailbox) . |
116 | '&passed_id=' . $passed_id; |
10f0ce72 |
117 | |
a07cd1a4 |
118 | $print_text = _("View Printable Version"); |
10f0ce72 |
119 | |
c615b1da |
120 | $result = ''; |
a07cd1a4 |
121 | /* Output the link. */ |
122 | if ($javascript_on) { |
9f42bfc8 |
123 | $result = '<script language="javascript" type="text/javascript">' . "\n" . |
124 | '<!--' . "\n" . |
125 | " function printFormat() {\n" . |
126 | ' window.open("../src/printer_friendly_main.php' . |
127 | $params . '","Print","width=800,height=600");' . "\n". |
128 | " }\n" . |
129 | "// -->\n" . |
130 | "</script>\n" . |
131 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
a07cd1a4 |
132 | } else { |
9f42bfc8 |
133 | $result = '<A target="_blank" HREF="../src/printer_friendly_bottom.php' . |
134 | "$params\">$print_text</a>\n"; |
a07cd1a4 |
135 | } |
d9c1dccc |
136 | return $result; |
a07cd1a4 |
137 | } |
138 | |
d9c1dccc |
139 | function ServerMDNSupport($read) { |
f69feefe |
140 | /* escaping $ doesn't work -> \x36 */ |
d9c1dccc |
141 | $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read); |
142 | return $ret; |
57257333 |
143 | } |
144 | |
fc224f68 |
145 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
0b97a708 |
146 | global $username, $attachment_dir, $_SERVER, |
fc224f68 |
147 | $version, $attachments, $squirrelmail_language, $default_charset, |
d9c1dccc |
148 | $languages, $useSendmail, $domain, $sent_folder, |
149 | $popuser, $data_dir, $username; |
57257333 |
150 | |
0b97a708 |
151 | $SERVER_NAME = $_SERVER['SERVER_NAME']; |
152 | |
38bca81c |
153 | $header = $message->rfc822_header; |
57257333 |
154 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
155 | |
fc224f68 |
156 | $rfc822_header = new Rfc822Header(); |
d9c1dccc |
157 | $content_type = new ContentType('multipart/report'); |
fc224f68 |
158 | $content_type->properties['report-type']='disposition-notification'; |
d9c1dccc |
159 | |
fc224f68 |
160 | set_my_charset(); |
161 | if ($default_charset) { |
d9c1dccc |
162 | $content_type->properties['charset']=$default_charset; |
fc224f68 |
163 | } |
164 | $rfc822_header->content_type = $content_type; |
165 | $rfc822_header->to[] = $header->dnt; |
166 | $rfc822_header->subject = _("Read:") . ' ' . $header->subject; |
167 | |
168 | |
169 | $reply_to = ''; |
170 | if (isset($identity) && $identity != 'default') { |
171 | $from_mail = getPref($data_dir, $username, |
d9c1dccc |
172 | 'email_address' . $identity); |
fc224f68 |
173 | $full_name = getPref($data_dir, $username, |
d9c1dccc |
174 | 'full_name' . $identity); |
fc224f68 |
175 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
176 | $reply_to = getPref($data_dir, $username, |
177 | 'reply_to' . $identity); |
fc224f68 |
178 | } else { |
179 | $from_mail = getPref($data_dir, $username, 'email_address'); |
180 | $full_name = getPref($data_dir, $username, 'full_name'); |
181 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
182 | $reply_to = getPref($data_dir, $username,'reply_to'); |
fc224f68 |
183 | } |
184 | if (!$from_addr) { |
185 | $from_addr = "$popuser@$domain"; |
186 | $from_mail = $from_addr; |
187 | } |
188 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
189 | if ($reply_to) { |
190 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
191 | } |
d9c1dccc |
192 | |
57257333 |
193 | // part 1 (RFC2298) |
57257333 |
194 | $senton = getLongDateString( $header->date ); |
195 | $to_array = $header->to; |
196 | $to = ''; |
197 | foreach ($to_array as $line) { |
af568a82 |
198 | $to .= ' '.$line->getAddress(); |
57257333 |
199 | } |
57257333 |
200 | $now = getLongDateString( time() ); |
78db1583 |
201 | set_my_charset(); |
46bb8da8 |
202 | $body = _("Your message") . "\r\n\r\n" . |
203 | "\t" . _("To:") . ' ' . $to . "\r\n" . |
fc224f68 |
204 | "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" . |
46bb8da8 |
205 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
206 | "\r\n" . |
207 | sprintf( _("Was displayed on %s"), $now ); |
f69feefe |
208 | |
fc224f68 |
209 | $special_encoding = ''; |
210 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
211 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
6fbd125b |
212 | $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body); |
d9c1dccc |
213 | if (strtolower($default_charset) == 'iso-2022-jp') { |
214 | if (mb_detect_encoding($body) == 'ASCII') { |
215 | $special_encoding = '8bit'; |
216 | } else { |
217 | $body = mb_convert_encoding($body, 'JIS'); |
218 | $special_encoding = '7bit'; |
219 | } |
220 | } |
6fbd125b |
221 | } |
fc224f68 |
222 | $part1 = new Message(); |
223 | $part1->setBody($body); |
224 | $mime_header = new MessageHeader; |
225 | $mime_header->type0 = 'text'; |
226 | $mime_header->type1 = 'plain'; |
227 | if ($special_encoding) { |
228 | $mime_header->encoding = $special_encoding; |
d9c1dccc |
229 | } else { |
fc224f68 |
230 | $mime_header->encoding = 'us-ascii'; |
231 | } |
232 | if ($default_charset) { |
233 | $mime_header->parameters['charset'] = $default_charset; |
234 | } |
235 | $part1->mime_header = $mime_header; |
236 | |
57257333 |
237 | // part2 (RFC2298) |
d9c1dccc |
238 | $original_recipient = $to; |
57257333 |
239 | $original_message_id = $header->message_id; |
240 | |
fc224f68 |
241 | $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
57257333 |
242 | if ($original_recipient != '') { |
fc224f68 |
243 | $report .= "Original-Recipient : $original_recipient\r\n"; |
57257333 |
244 | } |
245 | $final_recipient = $sender; |
fc224f68 |
246 | $report .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
57257333 |
247 | "Original-Message-ID : $original_message_id\r\n" . |
248 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
249 | |
fc224f68 |
250 | $part2 = new Message(); |
251 | $part2->setBody($report); |
252 | $mime_header = new MessageHeader; |
253 | $mime_header->type0 = 'message'; |
254 | $mime_header->type1 = 'disposition-notification'; |
255 | $mime_header->encoding = 'us-ascii'; |
256 | $part2->mime_header = $mime_header; |
257 | |
258 | $composeMessage = new Message(); |
259 | $composeMessage->rfc822_header = $rfc822_header; |
260 | $composeMessage->addEntity($part1); |
261 | $composeMessage->addEntity($part2); |
262 | |
263 | |
d9c1dccc |
264 | if ($useSendmail) { |
265 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
266 | global $sendmail_path; |
267 | $deliver = new Deliver_SendMail(); |
268 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
fc224f68 |
269 | } else { |
d9c1dccc |
270 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
271 | $deliver = new Deliver_SMTP(); |
47a29326 |
272 | global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp; |
273 | if ($smtp_auth_mech == 'none') { |
274 | $user = ''; |
275 | $pass = ''; |
276 | } else { |
d9c1dccc |
277 | global $key, $onetimepad; |
278 | $user = $username; |
279 | $pass = OneTimePadDecrypt($key, $onetimepad); |
d9c1dccc |
280 | } |
281 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
282 | $stream = $deliver->initStream($composeMessage,$domain,0, |
70ce2218 |
283 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
d9c1dccc |
284 | } |
285 | $success = false; |
fc224f68 |
286 | if ($stream) { |
d9c1dccc |
287 | $length = $deliver->mail($composeMessage, $stream); |
288 | $success = $deliver->finalizeStream($stream); |
fc224f68 |
289 | } |
d9c1dccc |
290 | if (!$success) { |
fc224f68 |
291 | $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr; |
d9c1dccc |
292 | require_once(SM_PATH . 'functions/display_messages.php'); |
fc224f68 |
293 | plain_error_message($msg, $color); |
294 | } else { |
295 | unset ($deliver); |
d9c1dccc |
296 | if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
297 | sqimap_append ($imapConnection, $sent_folder, $length); |
298 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
299 | $imap_deliver = new Deliver_IMAP(); |
300 | $imap_deliver->mail($composeMessage, $imapConnection); |
301 | sqimap_append_done ($imapConnection); |
302 | unset ($imap_deliver); |
303 | } |
304 | } |
305 | return $success; |
57257333 |
306 | } |
307 | |
d9c1dccc |
308 | function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) { |
309 | $sg = $set?'+':'-'; |
310 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
0892e427 |
311 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
507d14ea |
312 | $readmessage, $uid_support); |
57257333 |
313 | } |
314 | |
315 | function ClearAttachments() { |
d9c1dccc |
316 | global $username, $attachments, $attachment_dir; |
317 | |
318 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
319 | |
320 | $rem_attachments = array(); |
321 | foreach ($attachments as $info) { |
322 | if ($info['session'] == -1) { |
323 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
324 | if (file_exists($attached_file)) { |
325 | unlink($attached_file); |
326 | } |
327 | } else { |
328 | $rem_attachments[] = $info; |
329 | } |
330 | } |
331 | $attachments = $rem_attachments; |
57257333 |
332 | } |
333 | |
4d0cd98b |
334 | function formatRecipientString($recipients, $item ) { |
d9c1dccc |
335 | global $show_more_cc, $show_more, $show_more_bcc, |
336 | $PHP_SELF; |
4d0cd98b |
337 | |
d9c1dccc |
338 | $string = ''; |
38c944cc |
339 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
d9c1dccc |
340 | $show = false; |
38c944cc |
341 | |
342 | if ($item == 'to') { |
d9c1dccc |
343 | if ($show_more) { |
344 | $show = true; |
345 | $url = set_url_var($PHP_SELF, 'show_more',0); |
346 | } else { |
347 | $url = set_url_var($PHP_SELF, 'show_more',1); |
348 | } |
349 | } else if ($item == 'cc') { |
350 | if ($show_more_cc) { |
351 | $show = true; |
352 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
353 | } else { |
354 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
355 | } |
356 | } else if ($item == 'bcc') { |
357 | if ($show_more_bcc) { |
358 | $show = true; |
359 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
360 | } else { |
361 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
362 | } |
363 | } |
364 | |
365 | $cnt = count($recipients); |
366 | foreach($recipients as $r) { |
367 | $add = htmlspecialchars($r->getAddress()); |
368 | if ($string) { |
369 | $string .= '<BR>' . $add; |
370 | } else { |
371 | $string = $add; |
372 | if ($cnt > 1) { |
38c944cc |
373 | $string .= ' (<A HREF="'.$url; |
d9c1dccc |
374 | if ($show) { |
375 | $string .= '">'._("less").'</A>)'; |
376 | } else { |
377 | $string .= '">'._("more").'</A>)'; |
378 | break; |
379 | } |
380 | } |
381 | } |
1fca12b5 |
382 | } |
4d0cd98b |
383 | } |
c615b1da |
384 | return $string; |
385 | } |
386 | |
af568a82 |
387 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, |
388 | $color, $FirstTimeSee) { |
8e1d27aa |
389 | global $msn_user_support, $default_use_mdn, $default_use_priority, |
390 | $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on; |
38bca81c |
391 | |
d9c1dccc |
392 | $header = $message->rfc822_header; |
393 | $env = array(); |
394 | $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject)); |
395 | $from_name = $header->getAddr_s('from'); |
396 | if (!$from_name) { |
397 | $from_name = $header->getAddr_s('sender'); |
398 | if (!$from_name) { |
399 | $from_name = _("Unknown sender"); |
400 | } |
401 | } |
402 | $env[_("From")] = htmlspecialchars(decodeHeader($from_name)); |
403 | $env[_("Date")] = getLongDateString($header->date); |
404 | $env[_("To")] = formatRecipientString($header->to, "to"); |
405 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
406 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
407 | if ($default_use_priority) { |
408 | $env[_("Priority")] = getPriorityStr($header->priority); |
409 | } |
410 | if ($show_xmailer_default) { |
411 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
412 | } |
413 | if ($default_use_mdn) { |
414 | if ($mdn_user_support) { |
415 | if ($header->dnt) { |
416 | if ($message->is_mdnsent) { |
417 | $env[_("Read receipt")] = _("send"); |
418 | } else { |
419 | $env[_("Read receipt")] = _("requested"); |
8e1d27aa |
420 | if (!(handleAsSent($mailbox) || |
d9c1dccc |
421 | $message->is_deleted || |
422 | $passed_ent_id)) { |
423 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
424 | if ($FirstTimeSee && $javascript_on) { |
425 | $script = '<script language="JavaScript" type="text/javascript">' . "\n"; |
426 | $script .= '<!--'. "\n"; |
427 | $script .= 'if(window.confirm("' . |
428 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
429 | '")) { '."\n" . |
430 | ' sendMDN()'. |
431 | '}' . "\n"; |
432 | $script .= '// -->'. "\n"; |
433 | $script .= '</script>'. "\n"; |
434 | echo $script; |
435 | } |
436 | $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' . |
437 | _("Send read receipt now") . ']</a>'; |
438 | } |
439 | } |
440 | } |
441 | } |
442 | } |
c615b1da |
443 | |
0e02d604 |
444 | $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"'; |
445 | $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">'; |
d9c1dccc |
446 | foreach ($env as $key => $val) { |
447 | if ($val) { |
448 | $s .= '<TR>'; |
449 | $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n"; |
450 | $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n"; |
451 | $s .= '</TR>'; |
452 | } |
453 | } |
feb5ec1b |
454 | echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'. |
455 | ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n"; |
d0a2476a |
456 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
457 | $color[4].'"></TD></TR><TR><TD align=center>'."\n"; |
d9c1dccc |
458 | echo $s; |
459 | do_hook("read_body_header"); |
460 | formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color); |
461 | echo '</TABLE>'; |
feb5ec1b |
462 | echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n"; |
463 | echo '</TABLE>'; |
d9c1dccc |
464 | } |
c615b1da |
465 | |
7172cad7 |
466 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { |
8e1d27aa |
467 | global $base_uri, $draft_folder, $where, $what, $color, $sort, |
d9c1dccc |
468 | $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft, |
469 | $enable_forward_as_attachment; |
c615b1da |
470 | |
d9c1dccc |
471 | $topbar_delimiter = ' | '; |
472 | $urlMailbox = urlencode($mailbox); |
e55c441a |
473 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
474 | ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>'; |
475 | |
d9c1dccc |
476 | $msgs_url = $base_uri . 'src/'; |
477 | if (isset($where) && isset($what)) { |
478 | $msgs_url .= 'search.php?where=' . urlencode($where) . |
479 | '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox; |
480 | $msgs_str = _("Search results"); |
481 | } else { |
482 | $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' . |
483 | $startMessage . '&mailbox=' . $urlMailbox; |
484 | $msgs_str = _("Message List"); |
485 | } |
e55c441a |
486 | $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>'; |
d9c1dccc |
487 | |
488 | $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox . |
489 | '&message=' . $passed_id . '&'; |
490 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
491 | if ($where && $what) { |
492 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
493 | } else { |
494 | $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage; |
495 | } |
9f42bfc8 |
496 | $s .= $topbar_delimiter; |
e55c441a |
497 | $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>'; |
d9c1dccc |
498 | } |
c615b1da |
499 | |
d9c1dccc |
500 | $comp_uri = $base_uri . 'src/compose.php' . |
501 | '?passed_id=' . $passed_id . |
502 | '&mailbox=' . $urlMailbox . |
503 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
2ffa3f57 |
504 | |
d9c1dccc |
505 | if ($compose_new_win == '1') { |
506 | $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\''; |
507 | $link_close = '\')">'; |
508 | } else { |
509 | $link_open = '<a href="'; |
510 | $link_close = '">'; |
511 | } |
512 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
513 | $comp_alt_uri = $comp_uri . '&action=draft'; |
514 | $comp_alt_string = _("Resume Draft"); |
8e1d27aa |
515 | } else if (handleAsSent($mailbox)) { |
d9c1dccc |
516 | $comp_alt_uri = $comp_uri . '&action=edit_as_new'; |
517 | $comp_alt_string = _("Edit Message as New"); |
518 | } |
519 | if (isset($comp_alt_uri)) { |
e55c441a |
520 | $s .= $topbar_delimiter; |
521 | $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>'; |
d9c1dccc |
522 | } |
2ffa3f57 |
523 | |
e55c441a |
524 | $s .= '</small></td><td align="center" width="33%"><small>'; |
525 | |
d9c1dccc |
526 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
527 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
528 | $next = findNextMessage($passed_id); |
529 | if ($prev != -1) { |
530 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
531 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
532 | '&startMessage='.$startMessage.'&show_more=0'; |
e55c441a |
533 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
d9c1dccc |
534 | } else { |
e55c441a |
535 | $s .= _("Previous"); |
d9c1dccc |
536 | } |
e55c441a |
537 | $s .= $topbar_delimiter; |
d9c1dccc |
538 | if ($next != -1) { |
539 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
540 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
541 | '&startMessage='.$startMessage.'&show_more=0'; |
e55c441a |
542 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
d9c1dccc |
543 | } else { |
e55c441a |
544 | $s .= _("Next"); |
d9c1dccc |
545 | } |
546 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
547 | /* code for navigating through attached message/rfc822 messages */ |
548 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
e55c441a |
549 | $s .= '<a href="'.$url.'">'._("View Message").'</a>'; |
70bdc740 |
550 | $entities = array(); |
551 | $entity_count = array(); |
552 | $c = 0; |
f2f03410 |
553 | |
70bdc740 |
554 | foreach($message->parent->entities as $ent) { |
9f42bfc8 |
555 | if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') { |
556 | $c++; |
557 | $entity_count[$c] = $ent->entity_id; |
558 | $entities[$ent->entity_id] = $c; |
559 | } |
70bdc740 |
560 | } |
561 | $prev_link = _("Previous"); |
562 | $next_link = _("Next"); |
563 | if($entities[$passed_ent_id] > 1) { |
564 | $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1]; |
565 | $prev_link = '<a href="' |
566 | . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id) |
567 | . '">' . $prev_link . '</a>'; |
568 | } |
569 | if($entities[$passed_ent_id] < $c) { |
570 | $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1]; |
571 | $next_link = '<a href="' |
572 | . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id) |
573 | . '">' . $next_link . '</a>'; |
574 | } |
e55c441a |
575 | $s .= $topbar_delimiter . $prev_link; |
d9c1dccc |
576 | $par_ent_id = $message->parent->entity_id; |
577 | if ($par_ent_id) { |
578 | $par_ent_id = substr($par_ent_id,0,-2); |
e55c441a |
579 | $s .= $topbar_delimiter; |
d9c1dccc |
580 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
e55c441a |
581 | $s .= '<a href="'.$url.'">'._("Up").'</a>'; |
d9c1dccc |
582 | } |
e55c441a |
583 | $s .= $topbar_delimiter . $next_link; |
d9c1dccc |
584 | } |
c615b1da |
585 | |
e55c441a |
586 | $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>'; |
d9c1dccc |
587 | $comp_action_uri = $comp_uri . '&action=forward'; |
e55c441a |
588 | $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>'; |
c615b1da |
589 | |
d9c1dccc |
590 | if ($enable_forward_as_attachment) { |
591 | $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; |
e55c441a |
592 | $s .= $topbar_delimiter; |
9f42bfc8 |
593 | $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>'; |
d9c1dccc |
594 | } |
a128c967 |
595 | |
d9c1dccc |
596 | $comp_action_uri = decodeHeader($comp_uri . '&action=reply'); |
e55c441a |
597 | $s .= $topbar_delimiter; |
9f42bfc8 |
598 | $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>'; |
d9c1dccc |
599 | |
600 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
9f42bfc8 |
601 | $s .= $topbar_delimiter; |
e55c441a |
602 | $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>'; |
603 | $s .= '</small></td></tr></table>'; |
d9c1dccc |
604 | do_hook("read_body_menu_top"); |
e55c441a |
605 | echo $s; |
d9c1dccc |
606 | do_hook("read_body_menu_bottom"); |
c615b1da |
607 | } |
608 | |
609 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
fe369c70 |
610 | global $base_uri; |
611 | |
d9c1dccc |
612 | $urlMailbox = urlencode($mailbox); |
fe369c70 |
613 | $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING']; |
d9c1dccc |
614 | |
615 | $s = "<TR>\n" . |
616 | '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ": </B></TD>\n" . |
617 | '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' . |
618 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
619 | |
620 | /* Output the printer friendly link if we are in subtle mode. */ |
621 | $s .= ' | ' . |
622 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
623 | echo $s; |
624 | do_hook("read_body_header_right"); |
625 | $s = "</SMALL></TD>\n" . |
626 | "</TR>\n"; |
627 | echo $s; |
a128c967 |
628 | |
4d0cd98b |
629 | } |
630 | |
6206f6c4 |
631 | /***************************/ |
2ffa3f57 |
632 | /* Main of read_body.php */ |
6206f6c4 |
633 | /***************************/ |
57257333 |
634 | |
0b97a708 |
635 | /* get the globals we may need */ |
636 | |
9f42bfc8 |
637 | $username = $_SESSION['username']; |
638 | $key = $_COOKIE['key']; |
0b97a708 |
639 | $onetimepad = $_SESSION['onetimepad']; |
9f42bfc8 |
640 | $msgs = $_SESSION['msgs']; |
641 | $base_uri = $_SESSION['base_uri']; |
642 | $delimiter = $_SESSION['delimiter']; |
0b97a708 |
643 | |
644 | if (isset($_GET['passed_id'])) { |
9b761dbd |
645 | $passed_id = (int) $_GET['passed_id']; |
0b97a708 |
646 | } |
647 | elseif (isset($_POST['passed_id'])) { |
9b761dbd |
648 | $passed_id = (int) $_POST['passed_id']; |
0b97a708 |
649 | } |
650 | |
ce274df9 |
651 | if (isset($_GET['passed_ent_id'])) { |
652 | $passed_ent_id = $_GET['passed_ent_id']; |
653 | } |
654 | elseif (isset($_POST['passed_ent_id'])) { |
655 | $passed_ent_id = $_POST['passed_ent_id']; |
656 | } |
657 | |
0b97a708 |
658 | if (isset($_GET['sendreceipt'])) { |
659 | $sendreceipt = $_GET['sendreceipt']; |
660 | } |
661 | |
662 | if (isset($_GET['sort'])) { |
9b761dbd |
663 | $sort = (int) $_GET['sort']; |
0b97a708 |
664 | } |
665 | elseif (isset($_POST['sort'])) { |
9b761dbd |
666 | $sort = (int) $_POST['sort']; |
0b97a708 |
667 | } |
668 | if (isset($_GET['startMessage'])) { |
9b761dbd |
669 | $startMessage = (int) $_GET['startMessage']; |
0b97a708 |
670 | } |
671 | elseif (isset($_POST['startMessage'])) { |
9b761dbd |
672 | $startMessage = (int) $_POST['startMessage']; |
0b97a708 |
673 | } |
674 | if (isset($_GET['show_more'])) { |
9b761dbd |
675 | $show_more = (int) $_GET['show_more']; |
0b97a708 |
676 | } |
1b9f3c04 |
677 | if (isset($_GET['show_more_cc'])) { |
9b761dbd |
678 | $show_more_cc = (int) $_GET['show_more_cc']; |
1b9f3c04 |
679 | } |
680 | if (isset($_GET['show_more_bcc'])) { |
9b761dbd |
681 | $show_more_bcc = (int) $_GET['show_more_bcc']; |
0b97a708 |
682 | } |
683 | if (isset($_GET['mailbox'])) { |
684 | $mailbox = $_GET['mailbox']; |
685 | } |
686 | elseif (isset($_POST['mailbox'])) { |
687 | $mailbox = $_POST['mailbox']; |
688 | } |
689 | if (isset($_GET['where'])) { |
690 | $where = $_GET['where']; |
691 | } |
692 | if (isset($_GET['what'])) { |
693 | $what = $_GET['what']; |
694 | } |
695 | if (isset($_GET['view_hdr'])) { |
9b761dbd |
696 | $view_hdr = (int) $_GET['view_hdr']; |
0b97a708 |
697 | } |
698 | if (isset($_SESSION['server_sort_array'])) { |
699 | $server_sort_array = $_SESSION['server_sort_array']; |
700 | } |
701 | if (isset($_SESSION['msgs'])) { |
702 | $msgs = $_SESSION['msgs']; |
703 | } |
704 | if (isset($_SESSION['msort'])) { |
705 | $msort = $_SESSION['msort']; |
706 | } |
707 | if (isset($_POST['move_id'])) { |
708 | $move_id = $_POST['move_id']; |
709 | } |
710 | if (isset($_SESSION['lastTargetMailbox'])) { |
711 | $lastTargetMailbox = $_SESSION['lastTargetMailbox']; |
712 | } |
ce274df9 |
713 | if (isset($_SESSION['messages'])) { |
714 | $messages = $_SESSION['messages']; |
715 | } else { |
716 | $messages = array(); |
717 | } |
0b97a708 |
718 | |
a07cd1a4 |
719 | |
ce274df9 |
720 | |
721 | /* end of get globals */ |
38c944cc |
722 | global $uid_support, $sqimap_capabilities; |
723 | |
6a108031 |
724 | if (isset($mailbox)) { |
4366bea4 |
725 | $mailbox = urldecode( $mailbox ); |
726 | } |
38c944cc |
727 | |
6206f6c4 |
728 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
9f42bfc8 |
729 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
38c944cc |
730 | |
38c944cc |
731 | |
732 | /** |
733 | * $message contains all information about the message |
734 | * including header and body |
735 | */ |
37d2a6ee |
736 | |
737 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
9f42bfc8 |
738 | |
37d2a6ee |
739 | if (!isset($messages[$uidvalidity])) { |
740 | $messages[$uidvalidity] = array(); |
9f42bfc8 |
741 | } |
5200c026 |
742 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
743 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
fc224f68 |
744 | $FirstTimeSee = !$message->is_seen; |
745 | $message->is_seen = true; |
5200c026 |
746 | $messages[$uidvalidity][$passed_id] = $message; |
38c944cc |
747 | } else { |
fc224f68 |
748 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
749 | $message = $messages[$uidvalidity][$passed_id]; |
750 | $FirstTimeSee = !$message->is_seen; |
5200c026 |
751 | } |
af568a82 |
752 | |
dd628162 |
753 | if (isset($passed_ent_id) && $passed_ent_id) { |
5200c026 |
754 | $message = $message->getEntity($passed_ent_id); |
ff9d4297 |
755 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
756 | $message = $message->parent; |
757 | } |
141a16b2 |
758 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support); |
19d470aa |
759 | $rfc822_header = new Rfc822Header(); |
141a16b2 |
760 | $rfc822_header->parseHeader($read); |
761 | $message->rfc822_header = $rfc822_header; |
c615b1da |
762 | } else { |
763 | $passed_ent_id = 0; |
38c944cc |
764 | } |
5200c026 |
765 | $header = $message->header; |
57257333 |
766 | |
6c31f818 |
767 | do_hook('html_top'); |
57257333 |
768 | |
6206f6c4 |
769 | /****************************************/ |
770 | /* Block for handling incoming url vars */ |
771 | /****************************************/ |
5200c026 |
772 | |
5200c026 |
773 | if (isset($sendreceipt)) { |
774 | if ( !$message->is_mdnsent ) { |
775 | if (isset($identity) ) { |
776 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
777 | } else { |
778 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
779 | } |
780 | |
781 | $final_recipient = trim($final_recipient); |
782 | if ($final_recipient == '' ) { |
783 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
784 | } |
af568a82 |
785 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
fc224f68 |
786 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
c615b1da |
787 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
5200c026 |
788 | $message->is_mdnsent = true; |
6a108031 |
789 | $messages[$uidvalidity][$passed_id]=$message; |
5200c026 |
790 | } |
791 | ClearAttachments(); |
792 | } |
793 | } |
6206f6c4 |
794 | /***********************************************/ |
795 | /* End of block for handling incoming url vars */ |
796 | /***********************************************/ |
797 | |
38c944cc |
798 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
9f42bfc8 |
799 | |
800 | $messagebody = ''; |
c4ad259b |
801 | do_hook('read_body_top'); |
802 | if ($show_html_default == 1) { |
803 | $ent_ar = $message->findDisplayEntity(array()); |
804 | } else { |
805 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
806 | } |
a128c967 |
807 | $cnt = count($ent_ar); |
808 | for ($i = 0; $i < $cnt; $i++) { |
6a108031 |
809 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
a128c967 |
810 | if ($i != $cnt-1) { |
811 | $messagebody .= '<hr noshade size=1>'; |
812 | } |
38c944cc |
813 | } |
e55c441a |
814 | |
c615b1da |
815 | displayPageHeader($color, $mailbox); |
7172cad7 |
816 | formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
af568a82 |
817 | formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
6206f6c4 |
818 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
819 | echo ' <tr><td>'; |
820 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
a128c967 |
821 | echo ' <tr><td>'; |
6206f6c4 |
822 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
823 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
4b214684 |
824 | echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">'; |
ce810ea7 |
825 | echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left') |
6c7b5d8c |
826 | . '</tr>'; |
6206f6c4 |
827 | echo ' </table>'; |
828 | echo ' </td></tr>'; |
829 | echo ' </table></td></tr>'; |
2ffa3f57 |
830 | echo ' </table>'; |
831 | echo ' </td></tr>'; |
a128c967 |
832 | |
d0a2476a |
833 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
6c7b5d8c |
834 | $color[4].'"></TD></TR>'."\n"; |
d0a2476a |
835 | |
a128c967 |
836 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
837 | if ($attachmentsdisplay) { |
2ffa3f57 |
838 | echo ' <tr><td>'; |
6206f6c4 |
839 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
2ffa3f57 |
840 | echo ' <tr><td>'; |
d0a2476a |
841 | echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
6206f6c4 |
842 | echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">'; |
843 | echo ' <b>' . _("Attachments") . ':</b>'; |
844 | echo ' </td></tr>'; |
845 | echo ' <tr><td>'; |
846 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
847 | echo $attachmentsdisplay; |
848 | echo ' </td></tr></table>'; |
6c7b5d8c |
849 | echo ' </td></tr></table>'; |
850 | echo ' </td></tr></table>'; |
6206f6c4 |
851 | echo ' </td></tr>'; |
6c7b5d8c |
852 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
853 | $color[4].'"></TD></TR>'; |
a128c967 |
854 | } |
c615b1da |
855 | echo '</table>'; |
a07cd1a4 |
856 | |
857 | /* show attached images inline -- if pref'fed so */ |
5be9f195 |
858 | if (($attachment_common_show_images) && |
a07cd1a4 |
859 | is_array($attachment_common_show_images_list)) { |
860 | foreach ($attachment_common_show_images_list as $img) { |
ce274df9 |
861 | $imgurl = SM_PATH . 'src/download.php' . |
57257333 |
862 | '?' . |
cd7b8833 |
863 | 'passed_id=' . urlencode($img['passed_id']) . |
3d570ba0 |
864 | '&mailbox=' . urlencode($mailbox) . |
ff9d4297 |
865 | '&ent_id=' . urlencode($img['ent_id']) . |
3d570ba0 |
866 | '&absolute_dl=true'; |
5be9f195 |
867 | |
b5058e9e |
868 | echo html_tag( 'table', "\n" . |
d9c1dccc |
869 | html_tag( 'tr', "\n" . |
870 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
871 | ) |
872 | ) , |
b5058e9e |
873 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
10f0ce72 |
874 | } |
a07cd1a4 |
875 | } |
876 | |
c615b1da |
877 | do_hook('read_body_bottom'); |
878 | do_hook('html_bottom'); |
a07cd1a4 |
879 | sqimap_logout($imapConnection); |
ce274df9 |
880 | /* sessions are written at the end of the script. it's better to register |
881 | them at the end so we avoid double session_register calls */ |
882 | sqsession_register($messages,'messages'); |
e55c441a |
883 | |
a07cd1a4 |
884 | ?> |
c615b1da |
885 | </body> |
886 | </html> |