"Arief S Fitrianto" <arief@gurame.fisika.ui.ac.id>
[squirrelmail.git] / src / read_body.php
CommitLineData
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
15require_once('../src/validate.php');
16require_once('../functions/imap.php');
17require_once('../functions/mime.php');
18require_once('../functions/date.php');
19require_once('../functions/url_parser.php');
57257333 20require_once('../functions/smtp.php');
fab3baa6 21require_once('../functions/html.php');
38c944cc 22
a07cd1a4 23/**
1fca12b5 24 * Given an IMAP message id number, this will look it up in the cached
25 * and sorted msgs array and return the index. Used for finding the next
26 * and previous messages.
27 *
28 * @return the index of the next valid message from the array
29 */
c615b1da 30function findNextMessage($passed_id) {
31 global $msort, $msgs, $sort,
cf710efe 32 $thread_sort_messages, $allow_server_sort,
60a3e687 33 $server_sort_array;
2728fa19 34 if (!is_array($server_sort_array)) {
35 $thread_sort_messages = 0;
794d59c0 36 $allow_server_sort = FALSE;
2728fa19 37 }
a07cd1a4 38 $result = -1;
c615b1da 39 if ($thread_sort_messages || $allow_server_sort) {
60a3e687 40 reset($server_sort_array);
41 while(list($key, $value) = each ($server_sort_array)) {
c615b1da 42 if ($passed_id == $value) {
1fca12b5 43 if ($key == (count($server_sort_array) - 1)) {
60a3e687 44 $result = -1;
45 break;
46 }
1fca12b5 47 $result = $server_sort_array[$key + 1];
60a3e687 48 break;
789b4d79 49 }
60a3e687 50 }
6206f6c4 51 } else if ($sort == 6 && !$allow_server_sort &&
c615b1da 52 !$thread_sort_messages ) {
53 if ($passed_id != 1) {
54 $result = $passed_id - 1;
a07cd1a4 55 }
6206f6c4 56 } else if (!$allow_server_sort && !$thread_sort_messages ) {
75ef78d8 57 if (!is_array($msort)) {
58 return -1;
59 }
a07cd1a4 60 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
c615b1da 61 if ($passed_id == $msgs[$key]['ID']) {
a07cd1a4 62 next($msort);
63 $key = key($msort);
1fca12b5 64 if (isset($key)){
a07cd1a4 65 $result = $msgs[$key]['ID'];
66 break;
1fca12b5 67 }
10f0ce72 68 }
69 }
10f0ce72 70 }
a07cd1a4 71 return ($result);
72}
73
a07cd1a4 74/** returns the index of the previous message from the array. */
c615b1da 75function findPreviousMessage($numMessages, $passed_id) {
76 global $msort, $sort, $msgs,
77 $thread_sort_messages,
60a3e687 78 $allow_server_sort, $server_sort_array;
a07cd1a4 79 $result = -1;
2728fa19 80 if (!is_array($server_sort_array)) {
81 $thread_sort_messages = 0;
794d59c0 82 $allow_server_sort = FALSE;
2728fa19 83 }
c615b1da 84 if ($thread_sort_messages || $allow_server_sort ) {
60a3e687 85 reset($server_sort_array);
86 while(list($key, $value) = each ($server_sort_array)) {
c615b1da 87 if ($passed_id == $value) {
60a3e687 88 if ($key == 0) {
89 $result = -1;
90 break;
91 }
92 $result = $server_sort_array[$key -1];
93 break;
789b4d79 94 }
60a3e687 95 }
6206f6c4 96 } else if ($sort == 6 && !$allow_server_sort &&
c615b1da 97 !$thread_sort_messages) {
98 if ($passed_id != $numMessages) {
99 $result = $passed_id + 1;
a07cd1a4 100 }
6206f6c4 101 } else if (!$thread_sort_messages && !$allow_server_sort) {
1fca12b5 102 if (!is_array($msort)) {
75ef78d8 103 return -1;
1fca12b5 104 }
a07cd1a4 105 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
c615b1da 106 if ($passed_id == $msgs[$key]['ID']) {
a07cd1a4 107 prev($msort);
108 $key = key($msort);
109 if (isset($key)) {
6206f6c4 110 //echo $msort[$key]; /* Why again were we echoing here? */
a07cd1a4 111 $result = $msgs[$key]['ID'];
112 break;
10f0ce72 113 }
114 }
10f0ce72 115 }
a07cd1a4 116 }
117 return ($result);
118}
10f0ce72 119
a07cd1a4 120/**
1fca12b5 121 * Displays a link to a page where the message is displayed more
122 * "printer friendly".
123 */
c615b1da 124function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
125 global $javascript_on;
a07cd1a4 126
c615b1da 127 $params = '?passed_ent_id=' . $passed_ent_id .
1fca12b5 128 '&mailbox=' . urlencode($mailbox) .
129 '&passed_id=' . $passed_id;
10f0ce72 130
a07cd1a4 131 $print_text = _("View Printable Version");
10f0ce72 132
c615b1da 133 $result = '';
a07cd1a4 134 /* Output the link. */
135 if ($javascript_on) {
3d570ba0 136 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
a07cd1a4 137 '<!--' . "\n" .
138 " function printFormat() {\n" .
139 ' window.open("../src/printer_friendly_main.php' .
c615b1da 140 $params . '","Print","width=800,height=600");' . "\n".
a07cd1a4 141 " }\n" .
142 "// -->\n" .
143 "</script>\n" .
b5058e9e 144 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
a07cd1a4 145 } else {
b5058e9e 146 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
147 "$params\">$print_text</a>\n";
a07cd1a4 148 }
a07cd1a4 149 return ($result);
150}
151
57257333 152function ServerMDNSupport( $read ) {
f69feefe 153 /* escaping $ doesn't work -> \x36 */
154 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
57257333 155 return ( $ret );
156}
157
c615b1da 158function SendMDN ( $mailbox, $passed_id, $sender, $message) {
159 global $username, $attachment_dir, $SERVER_NAME,
6fbd125b 160 $version, $attachments, $squirrelmail_language;
57257333 161
38bca81c 162 $header = $message->rfc822_header;
57257333 163 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
5200c026 164
165 $recipient_o = $header->dnt;
166 $recipient = $recipient_o->getAddress(true);
57257333 167
168 // part 1 (RFC2298)
169
170 $senton = getLongDateString( $header->date );
171 $to_array = $header->to;
172 $to = '';
173 foreach ($to_array as $line) {
af568a82 174 $to .= ' '.$line->getAddress();
57257333 175 }
176
177 $subject = $header->subject;
178 $now = getLongDateString( time() );
46bb8da8 179
78db1583 180 set_my_charset();
181
46bb8da8 182 $body = _("Your message") . "\r\n\r\n" .
183 "\t" . _("To:") . ' ' . $to . "\r\n" .
184 "\t" . _("Subject:") . ' ' . $subject . "\r\n" .
185 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
186 "\r\n" .
187 sprintf( _("Was displayed on %s"), $now );
f69feefe 188
6fbd125b 189 if (function_exists($languages[$squrrelmail_language]['XTRA_CODE'])) {
190 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
191 }
83be314a 192
57257333 193 // part2 (RFC2298)
57257333 194 $original_recipient = $to;
195 $original_message_id = $header->message_id;
196
197 $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
198 if ($original_recipient != '') {
199 $part2 .= "Original-Recipient : $original_recipient\r\n";
200 }
201 $final_recipient = $sender;
202 $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" .
203 "Original-Message-ID : $original_message_id\r\n" .
204 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
205
57257333 206 $localfilename = GenerateRandomString(32, 'FILE', 7);
207 $full_localfilename = "$hashed_attachment_dir/$localfilename";
208
81d79073 209 $fp = fopen( $full_localfilename, 'wb');
57257333 210 fwrite ($fp, $part2);
211 fclose($fp);
212
213 $newAttachment = array();
214 $newAttachment['localfilename'] = $localfilename;
215 $newAttachment['type'] = "message/disposition-notification";
aa866a40 216 $newAttachment['session']=-1;
57257333 217 $attachments[] = $newAttachment;
5200c026 218
5200c026 219 return (SendMessage($recipient, '', '', _("Read:") . ' ' . $subject,
c615b1da 220 $body, 0, True, 3, -1) );
57257333 221}
222
223
c615b1da 224function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
0892e427 225 $sg = $set?'+':'-';
226 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
0892e427 227 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
507d14ea 228 $readmessage, $uid_support);
57257333 229}
230
231function ClearAttachments() {
232 global $username, $attachments, $attachment_dir;
233
234 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
235
aa866a40 236 $rem_attachments = array();
57257333 237 foreach ($attachments as $info) {
b2c19764 238 if ($info['session'] == -1) {
aa866a40 239 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
240 if (file_exists($attached_file)) {
241 unlink($attached_file);
242 }
243 } else {
244 $rem_attachments[] = $info;
245 }
246 }
68c3b52a 247 $attachments = $rem_attachments;
57257333 248}
249
4d0cd98b 250function formatRecipientString($recipients, $item ) {
c615b1da 251 global $show_more_cc, $show_more, $show_more_bcc,
38c944cc 252 $PHP_SELF;
4d0cd98b 253
38c944cc 254 if ((is_array($recipients)) && (isset($recipients[0]))) {
1fca12b5 255 $string = '';
4d0cd98b 256 $ary = $recipients;
38c944cc 257 $show = false;
258
259 if ($item == 'to') {
260 if ($show_more) {
261 $show = true;
262 $url = set_url_var($PHP_SELF, 'show_more',0);
263 } else {
264 $url = set_url_var($PHP_SELF, 'show_more',1);
265 }
266 } else if ($item == 'cc') {
267 if ($show_more_cc) {
268 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
269 $show = true;
270 } else {
271 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
272 }
273 } else if ($item == 'bcc') {
274 if ($show_more_bcc) {
275 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
276 $show = true;
277 } else {
278 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
279 }
280 }
4d0cd98b 281
38c944cc 282 $cnt = count($ary);
c615b1da 283 $i = 0;
38c944cc 284 while ($i < $cnt) {
c615b1da 285 $ary[$i] = htmlspecialchars($ary[$i]->getAddress());
4d0cd98b 286 if ($string) {
38c944cc 287 $string .= '<BR>'.$ary[$i];
4d0cd98b 288 } else {
38c944cc 289 $string = $ary[$i];
290 if ($cnt>1) {
291 $string .= '&nbsp;(<A HREF="'.$url;
292 if ($show) {
c615b1da 293 $string .= '">'._("less").'</A>)';
38c944cc 294 } else {
c615b1da 295 $string .= '">'._("more").'</A>)';
38c944cc 296 break;
297 }
298 }
4d0cd98b 299 }
4d0cd98b 300 $i++;
1fca12b5 301 }
4d0cd98b 302 }
303 else {
1fca12b5 304 $string = '';
4d0cd98b 305 }
c615b1da 306 return $string;
307}
308
af568a82 309function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
310 $color, $FirstTimeSee) {
2ffa3f57 311 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
312 $default_use_priority, $show_xmailer_default,
313 $mdn_user_support, $PHP_SELF, $javascript_on;
38bca81c 314
315 $header = $message->rfc822_header;
c615b1da 316 $env = array();
83be314a 317 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
38bca81c 318 $from_name = $header->getAddr_s('from');
319 if (!$from_name) {
320 $from_name = $header->getAddr_s('sender');
321 if (!$from_name) {
322 $from_name = _("Unknown sender");
323 }
c615b1da 324 }
83be314a 325 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
88d3af4f 326 $env[_("Date")] = getLongDateString($header->date);
c615b1da 327 $env[_("To")] = formatRecipientString($header->to, "to");
328 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
329 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
330 if ($default_use_priority) {
331 $env[_("Priority")] = getPriorityStr($header->priority);
332 }
333 if ($show_xmailer_default) {
83be314a 334 $env[_("Mailer")] = decodeHeader($header->xmailer);
c615b1da 335 }
336 if ($default_use_mdn) {
337 if ($mdn_user_support) {
338 if ($header->dnt) {
339 if ($message->is_mdnsent) {
340 $env[_("Read receipt")] = _("send");
341 } else {
342 if ( !($mailbox == $draft_folder ||
27ff41bd 343 $mailbox == $sent_folder ||
344 $message->is_deleted ||
345 $passed_ent_id)) {
c615b1da 346 $mdn_url = $PHP_SELF . '&sendreceipt=1';
c615b1da 347 if ($FirstTimeSee && $javascript_on) {
348 $script = '<script language="JavaScript" type="text/javascript">' ."\n";
349 $script .= '<!--'. "\n";
350 $script .= 'if(window.confirm("' .
351 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
352 '")) { '."\n" .
353 ' sendMDN()'.
354 '}' . "\n";
355 $script .= '// -->'. "\n";
356 $script .= '</script>'. "\n";
357 echo $script;
358 }
359 $env[_("Read receipt")] = _("requested") .
360 '&nbsp;<a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>';
361 } else {
362 $env[_("Read receipt")] = _("requested");
363 }
364 }
365 }
366 }
367 }
368
9feb4369 369 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
370 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
c615b1da 371 foreach ($env as $key => $val) {
372 if ($val) {
9feb4369 373 $s .= '<TR>';
9a231083 374 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
375 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
9feb4369 376 $s .= '</TR>';
c615b1da 377 }
378 }
7172cad7 379 echo $s;
2ffa3f57 380 do_hook("read_body_header");
9feb4369 381 formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color);
382 echo '</table>';
c615b1da 383}
384
7172cad7 385function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
c615b1da 386 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
6206f6c4 387 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
388 $enable_forward_as_attachment;
c615b1da 389
390 $topbar_delimiter = '&nbsp;|&nbsp;';
f099d05f 391 $urlMailbox = urlencode($mailbox);
c615b1da 392 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
393 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
394
395 $msgs_url = $base_uri . 'src/';
396 if (isset($where) && isset($what)) {
d215ca7d 397 $msgs_url .= 'search.php?where='.urlencode($where).
c615b1da 398 '&amp;what='.urlencode($what).'&amp;mailbox='.$urlMailbox;
2ffa3f57 399 $msgs_str = _("Search results");
c615b1da 400 } else {
401 $msgs_url .= 'right_main.php?sort='.$sort.'&amp;startMessage='.
402 $startMessage.'&amp;mailbox='.$urlMailbox;
d215ca7d 403 $msgs_str = _("Message List");
c615b1da 404 }
d215ca7d 405 $s .= '<a href="'. $msgs_url.'">'.$msgs_str.'</a>';
c615b1da 406 $s .= $topbar_delimiter;
6206f6c4 407
c615b1da 408 $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox.
409 '&amp;message='.$passed_id.'&amp;';
410 if (!(isset($passed_ent_id) && $passed_ent_id)) {
411 if ($where && $what) {
412 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
413 } else {
414 $delete_url .= 'sort='. $sort . '&amp;startMessage='. $startMessage;
415 }
416 $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>';
417 }
418
419 $comp_uri = $base_uri . 'src/compose.php'.
420 '?passed_id='.$passed_id.
2ffa3f57 421 '&amp;mailbox='.$urlMailbox.
422 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
c615b1da 423
424 if (($mailbox == $draft_folder) && ($save_as_draft)) {
425 $comp_alt_uri = $comp_uri . '&amp;action=draft';
426 $comp_alt_string = _("Resume Draft");
427 } else if ($mailbox == $sent_folder) {
428 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
429 $comp_alt_string = _("Edit Message as New");
430 }
431 if (isset($comp_alt_uri)) {
432 $s .= $topbar_delimiter;
433 if ($compose_new_win == '1') {
434 $s .= '<a href="javascript:void(0)" '.
2ffa3f57 435 'onclick="comp_in_new(\''.$comp_alt_uri.'\')">'.$comp_alt_string.'</a>';
c615b1da 436 } else {
437 $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>';
438 }
439 }
2ffa3f57 440
c615b1da 441 $s .= '</small></td><td align="center" width="33%"><small>';
2ffa3f57 442
c615b1da 443 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
444 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
445 $next = findNextMessage($passed_id);
446 if ($prev != -1) {
447 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
448 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
449 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
450 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
451 } else {
452 $s .= _("Previous");
453 }
454 $s .= $topbar_delimiter;
455 if ($next != -1) {
456 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
457 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
458 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
2ffa3f57 459 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
c615b1da 460 } else {
461 $s .= _("Next");
462 }
463 } else if (isset($passed_ent_id) && $passed_ent_id) {
7172cad7 464 /* code for navigating through attached message/rfc822 messages */
465 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
466 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
467 $par_ent_id = $message->parent->entity_id;
468 if ($par_ent_id) {
2ffa3f57 469 $par_ent_id = substr($par_ent_id,0,-2);
470 $s .= $topbar_delimiter;
471 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
472 $s .= '<a href="'.$url.'">'._("Up").'</a>';
7172cad7 473 }
2ffa3f57 474 }
c615b1da 475
a128c967 476 $s .= '</small></td><td align="right" width="33%" nowrap><small>';
c615b1da 477 $comp_action_uri = $comp_uri . '&amp;action=forward';
478 if ($compose_new_win == '1') {
479 $s .= '<a href="javascript:void(0)" '.
480 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>';
481 } else {
482 $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>';
483 }
484 $s .= $topbar_delimiter;
485
6206f6c4 486 if ($enable_forward_as_attachment) {
487 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
488 if ($compose_new_win == '1') {
489 $s .= '<a href="javascript:void(0)" '.
490 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward as Attachment").'</a>';
491 } else {
492 $s .= '<a href="'.$comp_action_uri.'">'._("Forward as Attachment").'</a>';
493 }
494 $s .= $topbar_delimiter;
a128c967 495 }
a128c967 496
c615b1da 497 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
498 if ($compose_new_win == '1') {
499 $s .= '<a href="javascript:void(0)" '.
500 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>';
501 } else {
502 $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>';
503 }
504 $s .= $topbar_delimiter;
505
506 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
507 if ($compose_new_win == '1') {
508 $s .= '<a href="javascript:void(0)" '.
509 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>';
510 } else {
511 $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>';
512 }
513 $s .= '</small></td></tr></table>';
2ffa3f57 514 do_hook("read_body_menu_top");
7172cad7 515 echo $s;
2ffa3f57 516 do_hook("read_body_menu_bottom");
c615b1da 517}
518
519function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
8fde8417 520 global $QUERY_STRING, $base_uri;
c615b1da 521
f099d05f 522 $urlMailbox = urlencode($mailbox);
8fde8417 523 $url = $base_uri.'src/view_header.php?'.$QUERY_STRING;
9feb4369 524
70b98171 525 $s = "<TR>\n" .
526 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
527 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
528 '<a href="'.$url.'">'._("View Full Header").'</a>';
9feb4369 529
530 /* Output the printer friendly link if we are in subtle mode. */
70b98171 531 $s .= '&nbsp;|&nbsp;' .
532 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
7172cad7 533 echo $s;
c615b1da 534 do_hook("read_body_header_right");
70b98171 535 $s = "</SMALL></TD>\n" .
536 "</TR>\n";
a128c967 537 echo $s;
538
4d0cd98b 539}
540
6206f6c4 541/***************************/
2ffa3f57 542/* Main of read_body.php */
6206f6c4 543/***************************/
57257333 544
545/*
546 Urled vars
547 ----------
548 $passed_id
549*/
a07cd1a4 550
38c944cc 551global $uid_support, $sqimap_capabilities;
552
6a108031 553if (isset($mailbox)) {
4366bea4 554 $mailbox = urldecode( $mailbox );
555}
38c944cc 556
6206f6c4 557$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
38c944cc 558$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
559
560if (!isset($messages)) {
561 $messages = array();
562 session_register('messages');
38c944cc 563}
564
565/**
566 * $message contains all information about the message
567 * including header and body
568 */
37d2a6ee 569
570$uidvalidity = $mbx_response['UIDVALIDITY'];
571
572if (!isset($messages[$uidvalidity])) {
573 $messages[$uidvalidity] = array();
574}
5200c026 575if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
576 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
577 $messages[$uidvalidity][$passed_id] = $message;
38c944cc 578} else {
38bca81c 579 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
580// $message = $messages[$uidvalidity][$passed_id];
5200c026 581}
af568a82 582$FirstTimeSee = !$message->is_seen;
583$message->is_seen = true;
584$messages[$uidvalidity][$passed_id] = $message;
585
dd628162 586if (isset($passed_ent_id) && $passed_ent_id) {
5200c026 587 $message = $message->getEntity($passed_ent_id);
ff9d4297 588 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
589 $message = $message->parent;
590 }
141a16b2 591 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
19d470aa 592 $rfc822_header = new Rfc822Header();
141a16b2 593 $rfc822_header->parseHeader($read);
594 $message->rfc822_header = $rfc822_header;
c615b1da 595} else {
596 $passed_ent_id = 0;
38c944cc 597}
5200c026 598$header = $message->header;
57257333 599
6c31f818 600do_hook('html_top');
57257333 601
6206f6c4 602/****************************************/
603/* Block for handling incoming url vars */
604/****************************************/
5200c026 605
5200c026 606if (isset($sendreceipt)) {
607 if ( !$message->is_mdnsent ) {
608 if (isset($identity) ) {
609 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
610 } else {
611 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
612 }
613
614 $final_recipient = trim($final_recipient);
615 if ($final_recipient == '' ) {
616 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
617 }
af568a82 618 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
c615b1da 619 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message ) > 0 && $supportMDN ) {
620 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
5200c026 621 $message->is_mdnsent = true;
6a108031 622 $messages[$uidvalidity][$passed_id]=$message;
5200c026 623 }
624 ClearAttachments();
625 }
626}
6206f6c4 627/***********************************************/
628/* End of block for handling incoming url vars */
629/***********************************************/
630
38c944cc 631$msgs[$passed_id]['FLAG_SEEN'] = true;
38c944cc 632
5200c026 633$messagebody = '';
c4ad259b 634do_hook('read_body_top');
635if ($show_html_default == 1) {
636 $ent_ar = $message->findDisplayEntity(array());
637} else {
638 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
639}
a128c967 640$cnt = count($ent_ar);
641for ($i = 0; $i < $cnt; $i++) {
6a108031 642 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
a128c967 643 if ($i != $cnt-1) {
644 $messagebody .= '<hr noshade size=1>';
645 }
38c944cc 646}
6a108031 647
c615b1da 648displayPageHeader($color, $mailbox);
7172cad7 649formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
af568a82 650formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
6206f6c4 651echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
652echo ' <tr><td>';
653echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
a128c967 654echo ' <tr><td>';
6206f6c4 655echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
656echo ' <tr bgcolor="'.$color[4].'"><td>';
657echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">';
658echo ' <tr><td><br>' . $messagebody . '</td></td>';
659echo ' </table>';
660echo ' </td></tr>';
661echo ' </table></td></tr>';
2ffa3f57 662echo ' </table>';
663echo ' </td></tr>';
a128c967 664
665$attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
666if ($attachmentsdisplay) {
2ffa3f57 667 echo ' <tr><td>';
6206f6c4 668 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
2ffa3f57 669 echo ' <tr><td>';
670 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
6206f6c4 671 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
672 echo ' <b>' . _("Attachments") . ':</b>';
673 echo ' </td></tr>';
674 echo ' <tr><td>';
675 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
676 echo $attachmentsdisplay;
677 echo ' </td></tr></table>';
678 echo ' </table></td></tr>';
2ffa3f57 679 echo ' </table></td></tr>';
6206f6c4 680 echo ' </table>';
681 echo ' </td></tr>';
a128c967 682}
c615b1da 683echo '</table>';
a07cd1a4 684
a128c967 685
a07cd1a4 686/* show attached images inline -- if pref'fed so */
5be9f195 687if (($attachment_common_show_images) &&
a07cd1a4 688 is_array($attachment_common_show_images_list)) {
689 foreach ($attachment_common_show_images_list as $img) {
5be9f195 690 $imgurl = '../src/download.php' .
57257333 691 '?' .
cd7b8833 692 'passed_id=' . urlencode($img['passed_id']) .
3d570ba0 693 '&amp;mailbox=' . urlencode($mailbox) .
ff9d4297 694 '&amp;ent_id=' . urlencode($img['ent_id']) .
3d570ba0 695 '&amp;absolute_dl=true';
5be9f195 696
b5058e9e 697 echo html_tag( 'table', "\n" .
698 html_tag( 'tr', "\n" .
699 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
700 )
701 ) ,
702 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
10f0ce72 703 }
a07cd1a4 704}
705
c615b1da 706do_hook('read_body_bottom');
707do_hook('html_bottom');
d7eab095 708//$message->clean_up();
a07cd1a4 709sqimap_logout($imapConnection);
710?>
c615b1da 711</body>
712</html>