6 * Copyright (c) 1999-2002 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');
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.
31 * @return the index of the next valid message from the array
33 function findNextMessage($passed_id) {
34 global $msort, $msgs, $sort,
35 $thread_sort_messages, $allow_server_sort,
37 if (!is_array($server_sort_array)) {
38 $thread_sort_messages = 0;
39 $allow_server_sort = FALSE;
42 if ($thread_sort_messages ||
$allow_server_sort) {
43 $count = count($server_sort_array) - 1;
44 foreach($server_sort_array as $key=>$value) {
45 if ($passed_id == $value) {
49 $result = $server_sort_array[$key +
1];
54 if (is_array($msort)) {
55 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
56 if ($passed_id == $msgs[$key]['ID']) {
60 $result = $msgs[$key]['ID'];
70 /** returns the index of the previous message from the array. */
71 function findPreviousMessage($numMessages, $passed_id) {
72 global $msort, $sort, $msgs,
73 $thread_sort_messages,
74 $allow_server_sort, $server_sort_array;
76 if (!is_array($server_sort_array)) {
77 $thread_sort_messages = 0;
78 $allow_server_sort = FALSE;
80 if ($thread_sort_messages ||
$allow_server_sort ) {
81 foreach($server_sort_array as $key=>$value) {
82 if ($passed_id == $value) {
86 $result = $server_sort_array[$key - 1];
91 if (is_array($msort)) {
92 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
93 if ($passed_id == $msgs[$key]['ID']) {
97 $result = $msgs[$key]['ID'];
108 * Displays a link to a page where the message is displayed more
109 * "printer friendly".
111 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
112 global $javascript_on;
114 $params = '?passed_ent_id=' . $passed_ent_id .
115 '&mailbox=' . urlencode($mailbox) .
116 '&passed_id=' . $passed_id;
118 $print_text = _("View Printable Version");
121 /* Output the link. */
122 if ($javascript_on) {
123 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
125 " function printFormat() {\n" .
126 ' window.open("../src/printer_friendly_main.php' .
127 $params . '","Print","width=800,height=600");' . "\n".
131 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
133 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
134 "$params\">$print_text</a>\n";
139 function ServerMDNSupport($read) {
140 /* escaping $ doesn't work -> \x36 */
141 $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read);
145 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
146 global $username, $attachment_dir, $_SERVER,
147 $version, $attachments, $squirrelmail_language, $default_charset,
148 $languages, $useSendmail, $domain, $sent_folder,
149 $popuser, $data_dir, $username;
151 $SERVER_NAME = $_SERVER['SERVER_NAME'];
153 $header = $message->rfc822_header
;
154 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
156 $rfc822_header = new Rfc822Header();
157 $content_type = new ContentType('multipart/report');
158 $content_type->properties
['report-type']='disposition-notification';
161 if ($default_charset) {
162 $content_type->properties
['charset']=$default_charset;
164 $rfc822_header->content_type
= $content_type;
165 $rfc822_header->to
[] = $header->dnt
;
166 $rfc822_header->subject
= _("Read:") . ' ' . $header->subject
;
170 if (isset($identity) && $identity != 'default') {
171 $from_mail = getPref($data_dir, $username,
172 'email_address' . $identity);
173 $full_name = getPref($data_dir, $username,
174 'full_name' . $identity);
175 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
176 $reply_to = getPref($data_dir, $username,
177 'reply_to' . $identity);
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.'>';
182 $reply_to = getPref($data_dir, $username,'reply_to');
185 $from_addr = "$popuser@$domain";
186 $from_mail = $from_addr;
188 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
190 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
194 $senton = getLongDateString( $header->date
);
195 $to_array = $header->to
;
197 foreach ($to_array as $line) {
198 $to .= ' '.$line->getAddress();
200 $now = getLongDateString( time() );
202 $body = _("Your message") . "\r\n\r\n" .
203 "\t" . _("To:") . ' ' . $to . "\r\n" .
204 "\t" . _("Subject:") . ' ' . $header->subject
. "\r\n" .
205 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
207 sprintf( _("Was displayed on %s"), $now );
209 $special_encoding = '';
210 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
211 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
212 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
213 if (strtolower($default_charset) == 'iso-2022-jp') {
214 if (mb_detect_encoding($body) == 'ASCII') {
215 $special_encoding = '8bit';
217 $body = mb_convert_encoding($body, 'JIS');
218 $special_encoding = '7bit';
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;
230 $mime_header->encoding
= 'us-ascii';
232 if ($default_charset) {
233 $mime_header->parameters
['charset'] = $default_charset;
235 $part1->mime_header
= $mime_header;
238 $original_recipient = $to;
239 $original_message_id = $header->message_id
;
241 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
242 if ($original_recipient != '') {
243 $report .= "Original-Recipient : $original_recipient\r\n";
245 $final_recipient = $sender;
246 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
247 "Original-Message-ID : $original_message_id\r\n" .
248 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
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;
258 $composeMessage = new Message();
259 $composeMessage->rfc822_header
= $rfc822_header;
260 $composeMessage->addEntity($part1);
261 $composeMessage->addEntity($part2);
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);
270 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
271 $deliver = new Deliver_SMTP();
272 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
273 if ($use_authenticated_smtp) {
274 global $key, $onetimepad;
276 $pass = OneTimePadDecrypt($key, $onetimepad);
281 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
282 $stream = $deliver->initStream($composeMessage,$domain,0,
283 $smtpServerAddress, $smtpPort, $authPop);
287 $length = $deliver->mail($composeMessage, $stream);
288 $success = $deliver->finalizeStream($stream);
291 $msg = $deliver->dlv_msg
. '<br>Server replied: '.$deliver->dlv_ret_nr
;
292 require_once(SM_PATH
. 'functions/display_messages.php');
293 plain_error_message($msg, $color);
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);
309 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
311 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
312 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
313 $readmessage, $uid_support);
316 function ClearAttachments() {
317 global $username, $attachments, $attachment_dir;
319 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
321 $rem_attachments = array();
322 foreach ($attachments as $info) {
323 if ($info['session'] == -1) {
324 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
325 if (file_exists($attached_file)) {
326 unlink($attached_file);
329 $rem_attachments[] = $info;
332 $attachments = $rem_attachments;
335 function formatRecipientString($recipients, $item ) {
336 global $show_more_cc, $show_more, $show_more_bcc,
340 if ((is_array($recipients)) && (isset($recipients[0]))) {
346 $url = set_url_var($PHP_SELF, 'show_more',0);
348 $url = set_url_var($PHP_SELF, 'show_more',1);
350 } else if ($item == 'cc') {
353 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
355 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
357 } else if ($item == 'bcc') {
358 if ($show_more_bcc) {
360 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
362 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
366 $cnt = count($recipients);
367 foreach($recipients as $r) {
368 $add = htmlspecialchars($r->getAddress());
370 $string .= '<BR>' . $add;
374 $string .= ' (<A HREF="'.$url;
376 $string .= '">'._("less").'</A>)';
378 $string .= '">'._("more").'</A>)';
388 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
389 $color, $FirstTimeSee) {
390 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
391 $default_use_priority, $show_xmailer_default,
392 $mdn_user_support, $PHP_SELF, $javascript_on;
394 $header = $message->rfc822_header
;
396 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject
));
397 $from_name = $header->getAddr_s('from');
399 $from_name = $header->getAddr_s('sender');
401 $from_name = _("Unknown sender");
404 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
405 $env[_("Date")] = getLongDateString($header->date
);
406 $env[_("To")] = formatRecipientString($header->to
, "to");
407 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
408 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
409 if ($default_use_priority) {
410 $env[_("Priority")] = getPriorityStr($header->priority
);
412 if ($show_xmailer_default) {
413 $env[_("Mailer")] = decodeHeader($header->xmailer
);
415 if ($default_use_mdn) {
416 if ($mdn_user_support) {
418 if ($message->is_mdnsent
) {
419 $env[_("Read receipt")] = _("send");
421 $env[_("Read receipt")] = _("requested");
422 if (!($mailbox == $draft_folder ||
423 $mailbox == $sent_folder ||
424 $message->is_deleted ||
426 $mdn_url = $PHP_SELF . '&sendreceipt=1';
427 if ($FirstTimeSee && $javascript_on) {
428 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
429 $script .= '<!--'. "\n";
430 $script .= 'if(window.confirm("' .
431 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
435 $script .= '// -->'. "\n";
436 $script .= '</script>'. "\n";
439 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
440 _("Send read receipt now") . ']</a>';
447 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
448 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
449 foreach ($env as $key => $val) {
452 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
453 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
457 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
458 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
459 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
460 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
462 do_hook("read_body_header");
463 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
465 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
469 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
470 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
471 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
472 $enable_forward_as_attachment;
474 $topbar_delimiter = ' | ';
475 $urlMailbox = urlencode($mailbox);
476 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
477 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
479 $msgs_url = $base_uri . 'src/';
480 if (isset($where) && isset($what)) {
481 $msgs_url .= 'search.php?where=' . urlencode($where) .
482 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
483 $msgs_str = _("Search results");
485 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
486 $startMessage . '&mailbox=' . $urlMailbox;
487 $msgs_str = _("Message List");
489 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
490 $s .= $topbar_delimiter;
492 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
493 '&message=' . $passed_id . '&';
494 if (!(isset($passed_ent_id) && $passed_ent_id)) {
495 if ($where && $what) {
496 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
498 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
500 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
503 $comp_uri = $base_uri . 'src/compose.php' .
504 '?passed_id=' . $passed_id .
505 '&mailbox=' . $urlMailbox .
506 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
508 if ($compose_new_win == '1') {
509 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
510 $link_close = '\')">';
512 $link_open = '<a href="';
515 if (($mailbox == $draft_folder) && ($save_as_draft)) {
516 $comp_alt_uri = $comp_uri . '&action=draft';
517 $comp_alt_string = _("Resume Draft");
518 } else if ($mailbox == $sent_folder) {
519 $comp_alt_uri = $comp_uri . '&action=edit_as_new';
520 $comp_alt_string = _("Edit Message as New");
522 if (isset($comp_alt_uri)) {
523 $s .= $topbar_delimiter;
524 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
527 $s .= '</small></td><td align="center" width="33%"><small>';
529 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
530 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
531 $next = findNextMessage($passed_id);
533 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
534 '&mailbox='.$urlMailbox.'&sort='.$sort.
535 '&startMessage='.$startMessage.'&show_more=0';
536 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
540 $s .= $topbar_delimiter;
542 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
543 '&mailbox='.$urlMailbox.'&sort='.$sort.
544 '&startMessage='.$startMessage.'&show_more=0';
545 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
549 } else if (isset($passed_ent_id) && $passed_ent_id) {
550 /* code for navigating through attached message/rfc822 messages */
551 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
552 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
554 $entity_count = array();
556 foreach($message->parent
->entities
as $ent) {
558 $entity_count[$c] = $ent->entity_id
;
559 $entities[$ent->entity_id
] = $c;
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>';
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>';
575 $s .= $topbar_delimiter . $prev_link;
576 $par_ent_id = $message->parent
->entity_id
;
578 $par_ent_id = substr($par_ent_id,0,-2);
579 $s .= $topbar_delimiter;
580 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
581 $s .= '<a href="'.$url.'">'._("Up").'</a>';
583 $s .= $topbar_delimiter . $next_link;
586 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
587 $comp_action_uri = $comp_uri . '&action=forward';
588 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
589 $s .= $topbar_delimiter;
591 if ($enable_forward_as_attachment) {
592 $comp_action_uri = $comp_uri . '&action=forward_as_attachment';
593 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
594 $s .= $topbar_delimiter;
597 $comp_action_uri = decodeHeader($comp_uri . '&action=reply');
598 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
599 $s .= $topbar_delimiter;
601 $comp_action_uri = $comp_uri . '&action=reply_all';
602 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
603 $s .= '</small></td></tr></table>';
604 do_hook("read_body_menu_top");
606 do_hook("read_body_menu_bottom");
609 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
612 $urlMailbox = urlencode($mailbox);
613 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
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>';
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);
624 do_hook("read_body_header_right");
625 $s = "</SMALL></TD>\n" .
631 /***************************/
632 /* Main of read_body.php */
633 /***************************/
635 /* get the globals we may need */
637 $username = $_SESSION['username'];
638 $key = $_COOKIE['key'];
639 $onetimepad = $_SESSION['onetimepad'];
640 $msgs = $_SESSION['msgs'];
641 $base_uri = $_SESSION['base_uri'];
642 $delimiter = $_SESSION['delimiter'];
644 if (isset($_GET['passed_id'])) {
645 $passed_id = $_GET['passed_id'];
647 elseif (isset($_POST['passed_id'])) {
648 $passed_id = $_POST['passed_id'];
651 if (isset($_GET['passed_ent_id'])) {
652 $passed_ent_id = $_GET['passed_ent_id'];
654 elseif (isset($_POST['passed_ent_id'])) {
655 $passed_ent_id = $_POST['passed_ent_id'];
658 if (isset($_GET['sendreceipt'])) {
659 $sendreceipt = $_GET['sendreceipt'];
662 if (isset($_GET['sort'])) {
663 $sort = $_GET['sort'];
665 elseif (isset($_POST['sort'])) {
666 $sort = $_POST['sort'];
668 if (isset($_GET['startMessage'])) {
669 $startMessage = $_GET['startMessage'];
671 elseif (isset($_POST['startMessage'])) {
672 $startMessage = $_POST['startMessage'];
674 if (isset($_GET['show_more'])) {
675 $show_more = $_GET['show_more'];
677 if (isset($_GET['show_more_cc'])) {
678 $show_more_cc = $_GET['show_more_cc'];
680 if (isset($_GET['show_more_bcc'])) {
681 $show_more_bcc = $_GET['show_more_bcc'];
683 if (isset($_GET['mailbox'])) {
684 $mailbox = $_GET['mailbox'];
686 elseif (isset($_POST['mailbox'])) {
687 $mailbox = $_POST['mailbox'];
689 if (isset($_GET['where'])) {
690 $where = $_GET['where'];
692 if (isset($_GET['what'])) {
693 $what = $_GET['what'];
695 if (isset($_GET['view_hdr'])) {
696 $view_hdr = $_GET['view_hdr'];
698 if (isset($_SESSION['server_sort_array'])) {
699 $server_sort_array = $_SESSION['server_sort_array'];
701 if (isset($_SESSION['msgs'])) {
702 $msgs = $_SESSION['msgs'];
704 if (isset($_SESSION['msort'])) {
705 $msort = $_SESSION['msort'];
707 if (isset($_POST['move_id'])) {
708 $move_id = $_POST['move_id'];
710 if (isset($_SESSION['lastTargetMailbox'])) {
711 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
713 if (isset($_SESSION['messages'])) {
714 $messages = $_SESSION['messages'];
721 /* end of get globals */
722 global $uid_support, $sqimap_capabilities;
724 if (isset($mailbox)) {
725 $mailbox = urldecode( $mailbox );
728 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
729 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
733 * $message contains all information about the message
734 * including header and body
737 $uidvalidity = $mbx_response['UIDVALIDITY'];
739 if (!isset($messages[$uidvalidity])) {
740 $messages[$uidvalidity] = array();
742 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
743 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
744 $FirstTimeSee = !$message->is_seen
;
745 $message->is_seen
= true;
746 $messages[$uidvalidity][$passed_id] = $message;
748 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
749 $message = $messages[$uidvalidity][$passed_id];
750 $FirstTimeSee = !$message->is_seen
;
753 if (isset($passed_ent_id) && $passed_ent_id) {
754 $message = $message->getEntity($passed_ent_id);
755 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
756 $message = $message->parent
;
758 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
759 $rfc822_header = new Rfc822Header();
760 $rfc822_header->parseHeader($read);
761 $message->rfc822_header
= $rfc822_header;
765 $header = $message->header
;
769 /****************************************/
770 /* Block for handling incoming url vars */
771 /****************************************/
773 if (isset($sendreceipt)) {
774 if ( !$message->is_mdnsent
) {
775 if (isset($identity) ) {
776 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
778 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
781 $final_recipient = trim($final_recipient);
782 if ($final_recipient == '' ) {
783 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
785 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
786 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
787 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
788 $message->is_mdnsent
= true;
789 $messages[$uidvalidity][$passed_id]=$message;
794 /***********************************************/
795 /* End of block for handling incoming url vars */
796 /***********************************************/
798 $msgs[$passed_id]['FLAG_SEEN'] = true;
801 do_hook('read_body_top');
802 if ($show_html_default == 1) {
803 $ent_ar = $message->findDisplayEntity(array());
805 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
807 $cnt = count($ent_ar);
808 for ($i = 0; $i < $cnt; $i++
) {
809 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
811 $messagebody .= '<hr noshade size=1>';
815 displayPageHeader($color, $mailbox);
816 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
817 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
818 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
820 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
822 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
823 echo ' <tr bgcolor="'.$color[4].'"><td>';
824 echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
825 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
829 echo ' </table></td></tr>';
833 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
834 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
836 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
837 if ($attachmentsdisplay) {
839 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
841 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
842 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
843 echo ' <b>' . _("Attachments") . ':</b>';
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>';
849 echo ' </table></td></tr>';
850 echo ' </table></td></tr>';
856 /* show attached images inline -- if pref'fed so */
857 if (($attachment_common_show_images) &&
858 is_array($attachment_common_show_images_list)) {
859 foreach ($attachment_common_show_images_list as $img) {
860 $imgurl = SM_PATH
. 'src/download.php' .
862 'passed_id=' . urlencode($img['passed_id']) .
863 '&mailbox=' . urlencode($mailbox) .
864 '&ent_id=' . urlencode($img['ent_id']) .
865 '&absolute_dl=true';
867 echo html_tag( 'table', "\n" .
868 html_tag( 'tr', "\n" .
869 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
872 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
876 do_hook('read_body_bottom');
877 do_hook('html_bottom');
878 sqimap_logout($imapConnection);
879 /* sessions are written at the end of the script. it's better to register
880 them at the end so we avoid double session_register calls */
881 sqsession_register($messages,'messages');