6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
15 /* Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
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');
25 require_once(SM_PATH
. 'functions/set_language_align.php');
28 /* --------------------- Get globals ------------------------------------- */
29 $language_align = set_language_align();
32 * Given an IMAP message id number, this will look it up in the cached
33 * and sorted msgs array and return the index. Used for finding the next
34 * and previous messages.
36 * @return the index of the next valid message from the array
38 function findNextMessage($passed_id) {
39 global $msort, $msgs, $sort,
40 $thread_sort_messages, $allow_server_sort,
42 if (!is_array($server_sort_array)) {
43 $thread_sort_messages = 0;
44 $allow_server_sort = FALSE;
47 if ($thread_sort_messages ||
$allow_server_sort) {
48 $count = count($server_sort_array) - 1;
49 foreach($server_sort_array as $key=>$value) {
50 if ($passed_id == $value) {
54 $result = $server_sort_array[$key +
1];
59 if (is_array($msort)) {
60 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
61 if ($passed_id == $msgs[$key]['ID']) {
65 $result = $msgs[$key]['ID'];
75 /** returns the index of the previous message from the array. */
76 function findPreviousMessage($numMessages, $passed_id) {
77 global $msort, $sort, $msgs,
78 $thread_sort_messages,
79 $allow_server_sort, $server_sort_array;
81 if (!is_array($server_sort_array)) {
82 $thread_sort_messages = 0;
83 $allow_server_sort = FALSE;
85 if ($thread_sort_messages ||
$allow_server_sort ) {
86 foreach($server_sort_array as $key=>$value) {
87 if ($passed_id == $value) {
91 $result = $server_sort_array[$key - 1];
96 if (is_array($msort)) {
97 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
98 if ($passed_id == $msgs[$key]['ID']) {
102 $result = $msgs[$key]['ID'];
113 * Displays a link to a page where the message is displayed more
114 * "printer friendly".
116 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
117 global $javascript_on;
119 $params = '?passed_ent_id=' . $passed_ent_id .
120 '&mailbox=' . urlencode($mailbox) .
121 '&passed_id=' . $passed_id;
123 $print_text = _("View Printable Version");
126 /* Output the link. */
127 if ($javascript_on) {
128 $result = '<script language="javascript" type="text/javascript">' . "\n" .
130 " function printFormat() {\n" .
131 ' window.open("../src/printer_friendly_main.php' .
132 $params . '","Print","width=800,height=600");' . "\n".
136 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
138 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
139 "$params\">$print_text</a>\n";
144 function ServerMDNSupport($read) {
145 /* escaping $ doesn't work -> \x36 */
146 $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read);
150 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
151 global $username, $attachment_dir, $_SERVER,
152 $version, $attachments, $squirrelmail_language, $default_charset,
153 $languages, $useSendmail, $domain, $sent_folder,
154 $popuser, $data_dir, $username;
156 $SERVER_NAME = $_SERVER['SERVER_NAME'];
158 $header = $message->rfc822_header
;
159 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
161 $rfc822_header = new Rfc822Header();
162 $content_type = new ContentType('multipart/report');
163 $content_type->properties
['report-type']='disposition-notification';
166 if ($default_charset) {
167 $content_type->properties
['charset']=$default_charset;
169 $rfc822_header->content_type
= $content_type;
170 $rfc822_header->to
[] = $header->dnt
;
171 $rfc822_header->subject
= _("Read:") . ' ' . $header->subject
;
175 if (isset($identity) && $identity != 'default') {
176 $from_mail = getPref($data_dir, $username,
177 'email_address' . $identity);
178 $full_name = getPref($data_dir, $username,
179 'full_name' . $identity);
180 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
181 $reply_to = getPref($data_dir, $username,
182 'reply_to' . $identity);
184 $from_mail = getPref($data_dir, $username, 'email_address');
185 $full_name = getPref($data_dir, $username, 'full_name');
186 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
187 $reply_to = getPref($data_dir, $username,'reply_to');
190 $from_addr = "$popuser@$domain";
191 $from_mail = $from_addr;
193 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
195 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
199 $senton = getLongDateString( $header->date
);
200 $to_array = $header->to
;
202 foreach ($to_array as $line) {
203 $to .= ' '.$line->getAddress();
205 $now = getLongDateString( time() );
207 $body = _("Your message") . "\r\n\r\n" .
208 "\t" . _("To:") . ' ' . $to . "\r\n" .
209 "\t" . _("Subject:") . ' ' . $header->subject
. "\r\n" .
210 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
212 sprintf( _("Was displayed on %s"), $now );
214 $special_encoding = '';
215 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
216 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
217 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
218 if (strtolower($default_charset) == 'iso-2022-jp') {
219 if (mb_detect_encoding($body) == 'ASCII') {
220 $special_encoding = '8bit';
222 $body = mb_convert_encoding($body, 'JIS');
223 $special_encoding = '7bit';
227 $part1 = new Message();
228 $part1->setBody($body);
229 $mime_header = new MessageHeader
;
230 $mime_header->type0
= 'text';
231 $mime_header->type1
= 'plain';
232 if ($special_encoding) {
233 $mime_header->encoding
= $special_encoding;
235 $mime_header->encoding
= 'us-ascii';
237 if ($default_charset) {
238 $mime_header->parameters
['charset'] = $default_charset;
240 $part1->mime_header
= $mime_header;
243 $original_recipient = $to;
244 $original_message_id = $header->message_id
;
246 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
247 if ($original_recipient != '') {
248 $report .= "Original-Recipient : $original_recipient\r\n";
250 $final_recipient = $sender;
251 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
252 "Original-Message-ID : $original_message_id\r\n" .
253 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
255 $part2 = new Message();
256 $part2->setBody($report);
257 $mime_header = new MessageHeader
;
258 $mime_header->type0
= 'message';
259 $mime_header->type1
= 'disposition-notification';
260 $mime_header->encoding
= 'us-ascii';
261 $part2->mime_header
= $mime_header;
263 $composeMessage = new Message();
264 $composeMessage->rfc822_header
= $rfc822_header;
265 $composeMessage->addEntity($part1);
266 $composeMessage->addEntity($part2);
270 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
271 global $sendmail_path;
272 $deliver = new Deliver_SendMail();
273 $stream = $deliver->initStream($composeMessage,$sendmail_path);
275 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
276 $deliver = new Deliver_SMTP();
277 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
278 if ($smtp_auth_mech == 'none') {
282 global $key, $onetimepad;
284 $pass = OneTimePadDecrypt($key, $onetimepad);
286 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
287 $stream = $deliver->initStream($composeMessage,$domain,0,
288 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
292 $length = $deliver->mail($composeMessage, $stream);
293 $success = $deliver->finalizeStream($stream);
296 $msg = $deliver->dlv_msg
. '<br>' .
297 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
298 $deliver->dlv_server_msg
;
299 require_once(SM_PATH
. 'functions/display_messages.php');
300 plain_error_message($msg, $color);
303 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
304 sqimap_append ($imapConnection, $sent_folder, $length);
305 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
306 $imap_deliver = new Deliver_IMAP();
307 $imap_deliver->mail($composeMessage, $imapConnection);
308 sqimap_append_done ($imapConnection);
309 unset ($imap_deliver);
315 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
317 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
318 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
319 $readmessage, $uid_support);
322 function ClearAttachments() {
323 global $username, $attachments, $attachment_dir;
325 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
327 $rem_attachments = array();
328 foreach ($attachments as $info) {
329 if ($info['session'] == -1) {
330 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
331 if (file_exists($attached_file)) {
332 unlink($attached_file);
335 $rem_attachments[] = $info;
338 $attachments = $rem_attachments;
341 function formatRecipientString($recipients, $item ) {
342 global $show_more_cc, $show_more, $show_more_bcc,
346 if ((is_array($recipients)) && (isset($recipients[0]))) {
352 $url = set_url_var($PHP_SELF, 'show_more',0);
354 $url = set_url_var($PHP_SELF, 'show_more',1);
356 } else if ($item == 'cc') {
359 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
361 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
363 } else if ($item == 'bcc') {
364 if ($show_more_bcc) {
366 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
368 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
372 $cnt = count($recipients);
373 foreach($recipients as $r) {
374 $add = htmlspecialchars($r->getAddress());
376 $string .= '<BR>' . $add;
380 $string .= ' (<A HREF="'.$url;
382 $string .= '">'._("less").'</A>)';
384 $string .= '">'._("more").'</A>)';
394 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
395 $color, $FirstTimeSee) {
396 global $msn_user_support, $default_use_mdn, $default_use_priority, $language_align,
397 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
398 $squirrelmail_language;
400 $header = $message->rfc822_header
;
402 if ($squirrelmail_language == 'ja_JP') {
403 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject
));
405 $env[_("Subject")] = decodeHeader(htmlspecialchars($header->subject
));
407 $from_name = $header->getAddr_s('from');
409 $from_name = $header->getAddr_s('sender');
411 $from_name = _("Unknown sender");
414 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
415 $env[_("Date")] = getLongDateString($header->date
);
416 $env[_("To")] = formatRecipientString($header->to
, "to");
417 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
418 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
419 if ($default_use_priority) {
420 $env[_("Priority")] = getPriorityStr($header->priority
);
422 if ($show_xmailer_default) {
423 $env[_("Mailer")] = decodeHeader($header->xmailer
);
425 if ($default_use_mdn) {
426 if ($mdn_user_support) {
428 if ($message->is_mdnsent
) {
429 $env[_("Read receipt")] = _("send");
431 $env[_("Read receipt")] = _("requested");
432 if (!(handleAsSent($mailbox) ||
433 $message->is_deleted ||
435 $mdn_url = $PHP_SELF . '&sendreceipt=1';
436 if ($FirstTimeSee && $javascript_on) {
437 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
438 $script .= '<!--'. "\n";
439 $script .= 'if(window.confirm("' .
440 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
444 $script .= '// -->'. "\n";
445 $script .= '</script>'. "\n";
448 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
449 _("Send read receipt now") . ']</a>';
456 $s = '<TABLE dir="' . $language_align['dir'] . '" WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
457 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
458 foreach ($env as $key => $val) {
461 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
462 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
466 echo '<TABLE dir="' . $language_align['dir'] . '" BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
467 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
468 echo '<TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.
469 $color[4].'"></TD></TR><TR><TD dir="' . $language_align['dir'] . '" align=center>'."\n";
471 do_hook('read_body_header');
472 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
474 echo '</TD></TR><TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
478 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
479 global $base_uri, $draft_folder, $where, $what, $color, $sort, $language_align,
480 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
481 $enable_forward_as_attachment;
483 $topbar_delimiter = ' | ';
484 $urlMailbox = urlencode($mailbox);
485 $s = '<table dir=' . $language_align['dir'] . ' width="100%" cellpadding="3" cellspacing="0" align="center"'.
486 ' border="0" bgcolor="'.$color[9].'"><tr><td align="' . $language_align['left'] . '" width="33%"><small>';
488 $msgs_url = $base_uri . 'src/';
489 if (isset($where) && isset($what)) {
490 $msgs_url .= 'search.php?where=' . urlencode($where) .
491 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
492 $msgs_str = _("Search results");
494 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
495 $startMessage . '&mailbox=' . $urlMailbox;
496 $msgs_str = _("Message List");
498 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
500 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
501 '&message=' . $passed_id . '&';
502 if (!(isset($passed_ent_id) && $passed_ent_id)) {
503 if ($where && $what) {
504 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
506 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
508 $s .= $topbar_delimiter;
509 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
512 $comp_uri = $base_uri . 'src/compose.php' .
513 '?passed_id=' . $passed_id .
514 '&mailbox=' . $urlMailbox .
515 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
517 if ($compose_new_win == '1') {
518 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
519 $link_close = '\')">';
521 $link_open = '<a href="';
524 if (($mailbox == $draft_folder) && ($save_as_draft)) {
525 $comp_alt_uri = $comp_uri . '&action=draft';
526 $comp_alt_string = _("Resume Draft");
527 } else if (handleAsSent($mailbox)) {
528 $comp_alt_uri = $comp_uri . '&action=edit_as_new';
529 $comp_alt_string = _("Edit Message as New");
531 if (isset($comp_alt_uri)) {
532 $s .= $topbar_delimiter;
533 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
536 $s .= '</small></td><td align="center" width="33%"><small>';
538 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
539 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
540 $next = findNextMessage($passed_id);
542 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
543 '&mailbox='.$urlMailbox.'&sort='.$sort.
544 '&startMessage='.$startMessage.'&show_more=0';
545 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
549 $s .= $topbar_delimiter;
551 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
552 '&mailbox='.$urlMailbox.'&sort='.$sort.
553 '&startMessage='.$startMessage.'&show_more=0';
554 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
558 } else if (isset($passed_ent_id) && $passed_ent_id) {
559 /* code for navigating through attached message/rfc822 messages */
560 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
561 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
563 $entity_count = array();
566 foreach($message->parent
->entities
as $ent) {
567 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
569 $entity_count[$c] = $ent->entity_id
;
570 $entities[$ent->entity_id
] = $c;
573 $prev_link = _("Previous");
574 $next_link = _("Next");
575 if($entities[$passed_ent_id] > 1) {
576 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
577 $prev_link = '<a href="'
578 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
579 . '">' . $prev_link . '</a>';
581 if($entities[$passed_ent_id] < $c) {
582 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
583 $next_link = '<a href="'
584 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
585 . '">' . $next_link . '</a>';
587 $s .= $topbar_delimiter . $prev_link;
588 $par_ent_id = $message->parent
->entity_id
;
590 $par_ent_id = substr($par_ent_id,0,-2);
591 $s .= $topbar_delimiter;
592 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
593 $s .= '<a href="'.$url.'">'._("Up").'</a>';
595 $s .= $topbar_delimiter . $next_link;
598 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
599 $comp_action_uri = $comp_uri . '&action=forward';
600 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
602 if ($enable_forward_as_attachment) {
603 $comp_action_uri = $comp_uri . '&action=forward_as_attachment';
604 $s .= $topbar_delimiter;
605 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
608 $comp_action_uri = decodeHeader($comp_uri . '&action=reply');
609 $s .= $topbar_delimiter;
610 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
612 $comp_action_uri = $comp_uri . '&action=reply_all';
613 $s .= $topbar_delimiter;
614 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
615 $s .= '</small></td></tr></table>';
616 do_hook("read_body_menu_top");
618 do_hook("read_body_menu_bottom");
621 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
622 global $base_uri, $language_align;
624 $urlMailbox = urlencode($mailbox);
625 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
627 $s = "<TR dir=" . $language_align['dir'] . ">\n" .
628 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['right'] . ' WIDTH="20%"><B>' . _("Options") . ": </B></TD>\n" .
629 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['left'] . ' WIDTH="80%"><SMALL>' .
630 '<a href="'.$url.'">'._("View Full Header").'</a>';
632 /* Output the printer friendly link if we are in subtle mode. */
633 $s .= ' | ' .
634 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
636 do_hook("read_body_header_right");
637 $s = "</SMALL></TD>\n" .
643 /***************************/
644 /* Main of read_body.php */
645 /***************************/
647 /* get the globals we may need */
649 $username = $_SESSION['username'];
650 $key = $_COOKIE['key'];
651 $onetimepad = $_SESSION['onetimepad'];
652 $msgs = $_SESSION['msgs'];
653 $base_uri = $_SESSION['base_uri'];
654 $delimiter = $_SESSION['delimiter'];
656 if (isset($_GET['passed_id'])) {
657 $passed_id = (int) $_GET['passed_id'];
659 elseif (isset($_POST['passed_id'])) {
660 $passed_id = (int) $_POST['passed_id'];
663 if (isset($_GET['passed_ent_id'])) {
664 $passed_ent_id = $_GET['passed_ent_id'];
666 elseif (isset($_POST['passed_ent_id'])) {
667 $passed_ent_id = $_POST['passed_ent_id'];
670 if (isset($_GET['sendreceipt'])) {
671 $sendreceipt = $_GET['sendreceipt'];
674 if (isset($_GET['sort'])) {
675 $sort = (int) $_GET['sort'];
677 elseif (isset($_POST['sort'])) {
678 $sort = (int) $_POST['sort'];
680 if (isset($_GET['startMessage'])) {
681 $startMessage = (int) $_GET['startMessage'];
683 elseif (isset($_POST['startMessage'])) {
684 $startMessage = (int) $_POST['startMessage'];
686 if (isset($_GET['show_more'])) {
687 $show_more = (int) $_GET['show_more'];
689 if (isset($_GET['show_more_cc'])) {
690 $show_more_cc = (int) $_GET['show_more_cc'];
692 if (isset($_GET['show_more_bcc'])) {
693 $show_more_bcc = (int) $_GET['show_more_bcc'];
695 if (isset($_GET['mailbox'])) {
696 $mailbox = $_GET['mailbox'];
698 elseif (isset($_POST['mailbox'])) {
699 $mailbox = $_POST['mailbox'];
701 if (isset($_GET['where'])) {
702 $where = $_GET['where'];
704 if (isset($_GET['what'])) {
705 $what = $_GET['what'];
707 if (isset($_GET['view_hdr'])) {
708 $view_hdr = (int) $_GET['view_hdr'];
710 if (isset($_SESSION['server_sort_array'])) {
711 $server_sort_array = $_SESSION['server_sort_array'];
713 if (isset($_SESSION['msgs'])) {
714 $msgs = $_SESSION['msgs'];
716 if (isset($_SESSION['msort'])) {
717 $msort = $_SESSION['msort'];
719 if (isset($_POST['move_id'])) {
720 $move_id = $_POST['move_id'];
722 if (isset($_SESSION['lastTargetMailbox'])) {
723 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
725 if (isset($_SESSION['messages'])) {
726 $messages = $_SESSION['messages'];
733 /* end of get globals */
734 global $uid_support, $sqimap_capabilities;
736 if (isset($mailbox)) {
737 $mailbox = urldecode( $mailbox );
740 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
741 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
745 * $message contains all information about the message
746 * including header and body
749 $uidvalidity = $mbx_response['UIDVALIDITY'];
751 if (!isset($messages[$uidvalidity])) {
752 $messages[$uidvalidity] = array();
754 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
755 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
756 $FirstTimeSee = !$message->is_seen
;
757 $message->is_seen
= true;
758 $messages[$uidvalidity][$passed_id] = $message;
760 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
761 $message = $messages[$uidvalidity][$passed_id];
762 $FirstTimeSee = !$message->is_seen
;
765 if (isset($passed_ent_id) && $passed_ent_id) {
766 $message = $message->getEntity($passed_ent_id);
767 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
768 $message = $message->parent
;
770 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
771 $rfc822_header = new Rfc822Header();
772 $rfc822_header->parseHeader($read);
773 $message->rfc822_header
= $rfc822_header;
777 $header = $message->header
;
781 /****************************************/
782 /* Block for handling incoming url vars */
783 /****************************************/
785 if (isset($sendreceipt)) {
786 if ( !$message->is_mdnsent
) {
787 if (isset($identity) ) {
788 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
790 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
793 $final_recipient = trim($final_recipient);
794 if ($final_recipient == '' ) {
795 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
797 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
798 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
799 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
800 $message->is_mdnsent
= true;
801 $messages[$uidvalidity][$passed_id]=$message;
806 /***********************************************/
807 /* End of block for handling incoming url vars */
808 /***********************************************/
810 $msgs[$passed_id]['FLAG_SEEN'] = true;
813 do_hook('read_body_top');
814 if ($show_html_default == 1) {
815 $ent_ar = $message->findDisplayEntity(array());
817 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
819 $cnt = count($ent_ar);
820 for ($i = 0; $i < $cnt; $i++
) {
821 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
823 $messagebody .= '<hr noshade size=1>';
827 displayPageHeader($color, $mailbox);
828 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
829 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
830 echo '<table dir="' . $language_align['dir'] . '" width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
832 echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
834 echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
835 echo ' <tr bgcolor="'.$color[4].'"><td>';
836 echo ' <table dir="' . $language_align['dir'] . '" cellpadding="1" cellspacing="5" align="' . $language_align['left'] . '" border="0">';
837 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
841 echo ' </table></td></tr>';
845 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
846 $color[4].'"></TD></TR>'."\n";
848 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
849 if ($attachmentsdisplay) {
851 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
853 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
854 echo ' <tr><td align="' . $language_align['left'] . '" bgcolor="'.$color[9].'">';
855 echo ' <b>' . _("Attachments") . ':</b>';
858 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
859 echo $attachmentsdisplay;
860 echo ' </td></tr></table>';
861 echo ' </td></tr></table>';
862 echo ' </td></tr></table>';
864 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
865 $color[4].'"></TD></TR>';
869 /* show attached images inline -- if pref'fed so */
870 if (($attachment_common_show_images) &&
871 is_array($attachment_common_show_images_list)) {
872 foreach ($attachment_common_show_images_list as $img) {
873 $imgurl = SM_PATH
. 'src/download.php' .
875 'passed_id=' . urlencode($img['passed_id']) .
876 '&mailbox=' . urlencode($mailbox) .
877 '&ent_id=' . urlencode($img['ent_id']) .
878 '&absolute_dl=true';
880 echo html_tag( 'table', "\n" .
881 html_tag( 'tr', "\n" .
882 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
885 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
889 do_hook('read_body_bottom');
890 do_hook('html_bottom');
891 sqimap_logout($imapConnection);
892 /* sessions are written at the end of the script. it's better to register
893 them at the end so we avoid double session_register calls */
894 sqsession_register($messages,'messages');