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/global.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/mime.php');
23 require_once(SM_PATH
. 'functions/date.php');
24 require_once(SM_PATH
. 'functions/url_parser.php');
25 require_once(SM_PATH
. 'functions/html.php');
26 require_once(SM_PATH
. 'functions/global.php');
29 * Given an IMAP message id number, this will look it up in the cached
30 * and sorted msgs array and return the index. Used for finding the next
31 * and previous messages.
33 * @return the index of the next valid message from the array
35 function findNextMessage($passed_id) {
36 global $msort, $msgs, $sort,
37 $thread_sort_messages, $allow_server_sort,
39 if (!is_array($server_sort_array)) {
40 $thread_sort_messages = 0;
41 $allow_server_sort = FALSE;
44 if ($thread_sort_messages ||
$allow_server_sort) {
45 $count = count($server_sort_array) - 1;
46 foreach($server_sort_array as $key=>$value) {
47 if ($passed_id == $value) {
51 $result = $server_sort_array[$key +
1];
56 if (is_array($msort)) {
57 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
58 if ($passed_id == $msgs[$key]['ID']) {
62 $result = $msgs[$key]['ID'];
72 /** returns the index of the previous message from the array. */
73 function findPreviousMessage($numMessages, $passed_id) {
74 global $msort, $sort, $msgs,
75 $thread_sort_messages,
76 $allow_server_sort, $server_sort_array;
78 if (!is_array($server_sort_array)) {
79 $thread_sort_messages = 0;
80 $allow_server_sort = FALSE;
82 if ($thread_sort_messages ||
$allow_server_sort ) {
83 foreach($server_sort_array as $key=>$value) {
84 if ($passed_id == $value) {
88 $result = $server_sort_array[$key - 1];
93 if (is_array($msort)) {
94 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
95 if ($passed_id == $msgs[$key]['ID']) {
99 $result = $msgs[$key]['ID'];
110 * Displays a link to a page where the message is displayed more
111 * "printer friendly".
113 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
114 global $javascript_on;
116 $params = '?passed_ent_id=' . $passed_ent_id .
117 '&mailbox=' . urlencode($mailbox) .
118 '&passed_id=' . $passed_id;
120 $print_text = _("View Printable Version");
123 /* Output the link. */
124 if ($javascript_on) {
125 $result = '<script language="javascript" type="text/javascript">' . "\n" .
127 " function printFormat() {\n" .
128 ' window.open("../src/printer_friendly_main.php' .
129 $params . '","Print","width=800,height=600");' . "\n".
133 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
135 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
136 "$params\">$print_text</a>\n";
141 function ServerMDNSupport($read) {
142 /* escaping $ doesn't work -> \x36 */
143 $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read);
147 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
148 global $username, $attachment_dir,
149 $version, $attachments, $squirrelmail_language, $default_charset,
150 $languages, $useSendmail, $domain, $sent_folder,
151 $popuser, $data_dir, $username;
153 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
155 $header = $message->rfc822_header
;
156 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
158 $rfc822_header = new Rfc822Header();
159 $content_type = new ContentType('multipart/report');
160 $content_type->properties
['report-type']='disposition-notification';
163 if ($default_charset) {
164 $content_type->properties
['charset']=$default_charset;
166 $rfc822_header->content_type
= $content_type;
167 $rfc822_header->to
[] = $header->dnt
;
168 $rfc822_header->subject
= _("Read:") . ' ' . decodeHeader($header->subject
);
172 if (isset($identity) && $identity != 'default') {
173 $from_mail = getPref($data_dir, $username,
174 'email_address' . $identity);
175 $full_name = getPref($data_dir, $username,
176 'full_name' . $identity);
177 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
178 $reply_to = getPref($data_dir, $username,
179 'reply_to' . $identity);
181 $from_mail = getPref($data_dir, $username, 'email_address');
182 $full_name = getPref($data_dir, $username, 'full_name');
183 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
184 $reply_to = getPref($data_dir, $username,'reply_to');
187 $from_addr = "$popuser@$domain";
188 $from_mail = $from_addr;
190 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
192 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
196 $senton = getLongDateString( $header->date
);
197 $to_array = $header->to
;
199 foreach ($to_array as $line) {
200 $to .= ' '.$line->getAddress();
202 $now = getLongDateString( time() );
204 $body = _("Your message") . "\r\n\r\n" .
205 "\t" . _("To:") . ' ' . decodeHeader($to) . "\r\n" .
206 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
) . "\r\n" .
207 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
209 sprintf( _("Was displayed on %s"), $now );
211 $special_encoding = '';
212 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
213 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
214 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
215 if (strtolower($default_charset) == 'iso-2022-jp') {
216 if (mb_detect_encoding($body) == 'ASCII') {
217 $special_encoding = '8bit';
219 $body = mb_convert_encoding($body, 'JIS');
220 $special_encoding = '7bit';
224 $part1 = new Message();
225 $part1->setBody($body);
226 $mime_header = new MessageHeader
;
227 $mime_header->type0
= 'text';
228 $mime_header->type1
= 'plain';
229 if ($special_encoding) {
230 $mime_header->encoding
= $special_encoding;
232 $mime_header->encoding
= 'us-ascii';
234 if ($default_charset) {
235 $mime_header->parameters
['charset'] = $default_charset;
237 $part1->mime_header
= $mime_header;
240 $original_recipient = $to;
241 $original_message_id = $header->message_id
;
243 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
244 if ($original_recipient != '') {
245 $report .= "Original-Recipient : $original_recipient\r\n";
247 $final_recipient = $sender;
248 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
249 "Original-Message-ID : $original_message_id\r\n" .
250 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
252 $part2 = new Message();
253 $part2->setBody($report);
254 $mime_header = new MessageHeader
;
255 $mime_header->type0
= 'message';
256 $mime_header->type1
= 'disposition-notification';
257 $mime_header->encoding
= 'us-ascii';
258 $part2->mime_header
= $mime_header;
260 $composeMessage = new Message();
261 $composeMessage->rfc822_header
= $rfc822_header;
262 $composeMessage->addEntity($part1);
263 $composeMessage->addEntity($part2);
267 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
268 global $sendmail_path;
269 $deliver = new Deliver_SendMail();
270 $stream = $deliver->initStream($composeMessage,$sendmail_path);
272 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
273 $deliver = new Deliver_SMTP();
274 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
275 if ($smtp_auth_mech == 'none') {
279 global $key, $onetimepad;
281 $pass = OneTimePadDecrypt($key, $onetimepad);
283 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
284 $stream = $deliver->initStream($composeMessage,$domain,0,
285 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
289 $length = $deliver->mail($composeMessage, $stream);
290 $success = $deliver->finalizeStream($stream);
293 $msg = $deliver->dlv_msg
. '<br>' .
294 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
295 $deliver->dlv_server_msg
;
296 require_once(SM_PATH
. 'functions/display_messages.php');
297 plain_error_message($msg, $color);
300 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
301 sqimap_append ($imapConnection, $sent_folder, $length);
302 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
303 $imap_deliver = new Deliver_IMAP();
304 $imap_deliver->mail($composeMessage, $imapConnection);
305 sqimap_append_done ($imapConnection);
306 unset ($imap_deliver);
312 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
314 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
315 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
316 $readmessage, $uid_support);
319 function ClearAttachments() {
320 global $username, $attachments, $attachment_dir;
322 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
324 $rem_attachments = array();
325 if (isset($attachments)) {
326 foreach ($attachments as $info) {
327 if ($info['session'] == -1) {
328 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
329 if (file_exists($attached_file)) {
330 unlink($attached_file);
333 $rem_attachments[] = $info;
337 $attachments = $rem_attachments;
340 function formatRecipientString($recipients, $item ) {
341 global $show_more_cc, $show_more, $show_more_bcc,
345 if ((is_array($recipients)) && (isset($recipients[0]))) {
351 $url = set_url_var($PHP_SELF, 'show_more',0);
353 $url = set_url_var($PHP_SELF, 'show_more',1);
355 } else if ($item == 'cc') {
358 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
360 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
362 } else if ($item == 'bcc') {
363 if ($show_more_bcc) {
365 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
367 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
371 $cnt = count($recipients);
372 foreach($recipients as $r) {
373 $add = decodeHeader($r->getAddress(true));
375 $string .= '<BR>' . $add;
379 $string .= ' (<A HREF="'.$url;
381 $string .= '">'._("less").'</A>)';
383 $string .= '">'._("more").'</A>)';
393 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
394 $color, $FirstTimeSee) {
395 global $msn_user_support, $default_use_mdn, $default_use_priority,
396 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
397 $squirrelmail_language;
399 $header = $message->rfc822_header
;
401 $env[_("Subject")] = decodeHeader($header->subject
);
402 $from_name = $header->getAddr_s('from');
404 $from_name = $header->getAddr_s('sender');
406 $from_name = _("Unknown sender");
409 $env[_("From")] = decodeHeader($from_name);
410 $env[_("Date")] = getLongDateString($header->date
);
411 $env[_("To")] = formatRecipientString($header->to
, "to");
412 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
413 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
414 if ($default_use_priority) {
415 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
417 if ($show_xmailer_default) {
418 $env[_("Mailer")] = decodeHeader($header->xmailer
);
420 if ($default_use_mdn) {
421 if ($mdn_user_support) {
423 if ($message->is_mdnsent
) {
424 $env[_("Read receipt")] = _("send");
426 $env[_("Read receipt")] = _("requested");
427 if (!(handleAsSent($mailbox) ||
428 $message->is_deleted ||
430 $mdn_url = $PHP_SELF . '&sendreceipt=1';
431 if ($FirstTimeSee && $javascript_on) {
432 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
433 $script .= '<!--'. "\n";
434 $script .= 'if(window.confirm("' .
435 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
439 $script .= '// -->'. "\n";
440 $script .= '</script>'. "\n";
443 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
444 _("Send read receipt now") . ']</a>';
451 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
452 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
453 foreach ($env as $key => $val) {
456 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
457 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
461 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
462 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
463 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
464 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
466 do_hook('read_body_header');
467 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
469 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
473 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
474 global $base_uri, $draft_folder, $where, $what, $color, $sort,
475 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
476 $enable_forward_as_attachment;
478 $topbar_delimiter = ' | ';
479 $urlMailbox = urlencode($mailbox);
480 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
481 ' border="0" bgcolor="'.$color[9].'"><tr>' .
482 html_tag( 'td', '', 'left', '', 'width="33%"' ) . '<small>';
484 $msgs_url = $base_uri . 'src/';
485 if (isset($where) && isset($what)) {
486 $msgs_url .= 'search.php?where=' . urlencode($where) .
487 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
488 $msgs_str = _("Search results");
490 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
491 $startMessage . '&mailbox=' . $urlMailbox;
492 $msgs_str = _("Message List");
494 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
496 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
497 '&message=' . $passed_id . '&';
498 if (!(isset($passed_ent_id) && $passed_ent_id)) {
499 if ($where && $what) {
500 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
502 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
504 $s .= $topbar_delimiter;
505 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
508 $comp_uri = $base_uri . 'src/compose.php' .
509 '?passed_id=' . $passed_id .
510 '&mailbox=' . $urlMailbox .
511 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
513 if ($compose_new_win == '1') {
514 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
515 $link_close = '\')">';
517 $link_open = '<a href="';
520 if (($mailbox == $draft_folder) && ($save_as_draft)) {
521 $comp_alt_uri = $comp_uri . '&action=draft';
522 $comp_alt_string = _("Resume Draft");
523 } else if (handleAsSent($mailbox)) {
524 $comp_alt_uri = $comp_uri . '&action=edit_as_new';
525 $comp_alt_string = _("Edit Message as New");
527 if (isset($comp_alt_uri)) {
528 $s .= $topbar_delimiter;
529 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
532 $s .= '</small></td><td align="center" width="33%"><small>';
534 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
535 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
536 $next = findNextMessage($passed_id);
538 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
539 '&mailbox='.$urlMailbox.'&sort='.$sort.
540 '&startMessage='.$startMessage.'&show_more=0';
541 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
545 $s .= $topbar_delimiter;
547 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
548 '&mailbox='.$urlMailbox.'&sort='.$sort.
549 '&startMessage='.$startMessage.'&show_more=0';
550 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
554 } else if (isset($passed_ent_id) && $passed_ent_id) {
555 /* code for navigating through attached message/rfc822 messages */
556 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
557 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
559 $entity_count = array();
562 foreach($message->parent
->entities
as $ent) {
563 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
565 $entity_count[$c] = $ent->entity_id
;
566 $entities[$ent->entity_id
] = $c;
569 $prev_link = _("Previous");
570 $next_link = _("Next");
571 if($entities[$passed_ent_id] > 1) {
572 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
573 $prev_link = '<a href="'
574 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
575 . '">' . $prev_link . '</a>';
577 if($entities[$passed_ent_id] < $c) {
578 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
579 $next_link = '<a href="'
580 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
581 . '">' . $next_link . '</a>';
583 $s .= $topbar_delimiter . $prev_link;
584 $par_ent_id = $message->parent
->entity_id
;
586 $par_ent_id = substr($par_ent_id,0,-2);
587 $s .= $topbar_delimiter;
588 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
589 $s .= '<a href="'.$url.'">'._("Up").'</a>';
591 $s .= $topbar_delimiter . $next_link;
594 $s .= '</small></td>' . "\n" .
595 html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>';
596 $comp_action_uri = $comp_uri . '&action=forward';
597 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
599 if ($enable_forward_as_attachment) {
600 $comp_action_uri = $comp_uri . '&action=forward_as_attachment';
601 $s .= $topbar_delimiter;
602 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
605 $comp_action_uri = $comp_uri . '&action=reply';
606 $s .= $topbar_delimiter;
607 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
609 $comp_action_uri = $comp_uri . '&action=reply_all';
610 $s .= $topbar_delimiter;
611 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
612 $s .= '</small></td></tr></table>';
613 do_hook("read_body_menu_top");
615 do_hook("read_body_menu_bottom");
618 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
621 $urlMailbox = urlencode($mailbox);
622 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER
);
623 $url = $base_uri.'src/view_header.php?'.$query_string;
626 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
627 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
628 '<a href="'.$url.'">'._("View Full Header").'</a>';
630 /* Output the printer friendly link if we are in subtle mode. */
631 $s .= ' | ' .
632 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
634 do_hook("read_body_header_right");
635 $s = "</SMALL></TD>\n" .
641 /***************************/
642 /* Main of read_body.php */
643 /***************************/
645 /* get the globals we may need */
647 sqgetGlobalVar('key', $key, SQ_COOKIE
);
648 sqgetGlobalVar('username', $username, SQ_SESSION
);
649 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
650 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
651 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
653 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
654 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
655 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
656 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
657 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
662 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
663 sqgetGlobalVar('where', $where, SQ_GET
);
664 sqgetGlobalVar('what', $what, SQ_GET
);
665 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
666 $show_more = (int) $temp;
668 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
669 $show_more_cc = (int) $temp;
671 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
672 $show_more_bcc = (int) $temp;
674 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
675 $view_hdr = (int) $temp;
679 sqgetGlobalVar('move_id', $move_id, SQ_POST
);
682 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
683 sqgetGlobalVar('mailbox', $mailbox);
685 if ( sqgetGlobalVar('passed_id', $temp) ) {
686 $passed_id = (int) $temp;
688 if ( sqgetGlobalVar('sort', $temp) ) {
691 if ( sqgetGlobalVar('startMessage', $temp) ) {
692 $startMessage = (int) $temp;
695 /* end of get globals */
696 global $uid_support, $sqimap_capabilities;
698 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
699 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
703 * $message contains all information about the message
704 * including header and body
707 $uidvalidity = $mbx_response['UIDVALIDITY'];
709 if (!isset($messages[$uidvalidity])) {
710 $messages[$uidvalidity] = array();
712 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
713 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
714 $FirstTimeSee = !$message->is_seen
;
715 $message->is_seen
= true;
716 $messages[$uidvalidity][$passed_id] = $message;
718 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
719 $message = $messages[$uidvalidity][$passed_id];
720 $FirstTimeSee = !$message->is_seen
;
723 if (isset($passed_ent_id) && $passed_ent_id) {
724 $message = $message->getEntity($passed_ent_id);
725 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
726 $message = $message->parent
;
728 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
729 $rfc822_header = new Rfc822Header();
730 $rfc822_header->parseHeader($read);
731 $message->rfc822_header
= $rfc822_header;
735 $header = $message->header
;
739 /****************************************/
740 /* Block for handling incoming url vars */
741 /****************************************/
743 if (isset($sendreceipt)) {
744 if ( !$message->is_mdnsent
) {
745 if (isset($identity) ) {
746 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
748 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
751 $final_recipient = trim($final_recipient);
752 if ($final_recipient == '' ) {
753 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
755 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
756 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
757 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
758 $message->is_mdnsent
= true;
759 $messages[$uidvalidity][$passed_id]=$message;
764 /***********************************************/
765 /* End of block for handling incoming url vars */
766 /***********************************************/
768 $msgs[$passed_id]['FLAG_SEEN'] = true;
771 do_hook('read_body_top');
772 if ($show_html_default == 1) {
773 $ent_ar = $message->findDisplayEntity(array());
775 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
777 $cnt = count($ent_ar);
778 for ($i = 0; $i < $cnt; $i++
) {
779 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
781 $messagebody .= '<hr noshade size=1>';
785 displayPageHeader($color, $mailbox);
786 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
787 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
788 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
790 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
792 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
793 echo ' <tr bgcolor="'.$color[4].'"><td>';
794 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
795 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
796 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
800 echo ' </table></td></tr>';
804 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
805 $color[4].'"></TD></TR>'."\n";
807 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
808 if ($attachmentsdisplay) {
810 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
812 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
813 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
814 echo ' <b>' . _("Attachments") . ':</b>';
817 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
818 echo $attachmentsdisplay;
819 echo ' </td></tr></table>';
820 echo ' </td></tr></table>';
822 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
823 $color[4].'"></TD></TR>';
827 /* show attached images inline -- if pref'fed so */
828 if (($attachment_common_show_images) &&
829 is_array($attachment_common_show_images_list)) {
830 foreach ($attachment_common_show_images_list as $img) {
831 $imgurl = SM_PATH
. 'src/download.php' .
833 'passed_id=' . urlencode($img['passed_id']) .
834 '&mailbox=' . urlencode($mailbox) .
835 '&ent_id=' . urlencode($img['ent_id']) .
836 '&absolute_dl=true';
838 echo html_tag( 'table', "\n" .
839 html_tag( 'tr', "\n" .
840 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
843 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
847 do_hook('read_body_bottom');
848 do_hook('html_bottom');
849 sqimap_logout($imapConnection);
850 /* sessions are written at the end of the script. it's better to register
851 them at the end so we avoid double session_register calls */
852 sqsession_register($messages,'messages');