5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/global.php');
24 require_once(SM_PATH
. 'functions/imap.php');
25 require_once(SM_PATH
. 'functions/mime.php');
26 require_once(SM_PATH
. 'functions/date.php');
27 require_once(SM_PATH
. 'functions/url_parser.php');
28 require_once(SM_PATH
. 'functions/html.php');
29 require_once(SM_PATH
. 'functions/global.php');
30 require_once(SM_PATH
. 'functions/identity.php');
31 require_once(SM_PATH
. 'functions/mailbox_display.php');
34 * Given an IMAP message id number, this will look it up in the cached
35 * and sorted msgs array and return the index of the next message
37 * @param int $passed_id The current message UID
38 * @return the index of the next valid message from the array
40 function findNextMessage($passed_id) {
41 global $server_sort_array;
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];
57 * Given an IMAP message id number, this will look it up in the cached
58 * and sorted msgs array and return the index of the previous message
60 * @param int $passed_id The current message UID
61 * @return the index of the next valid message from the array
63 function findPreviousMessage($numMessages, $passed_id) {
64 global $server_sort_array;
66 foreach($server_sort_array as $key=>$value) {
67 if ($passed_id == $value) {
69 $result = $server_sort_array[$key - 1];
79 * Displays a link to a page where the message is displayed more
81 * @param string $mailbox Name of current mailbox
82 * @param int $passed_id
84 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
85 global $javascript_on, $color;
87 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
88 '&mailbox=' . urlencode($mailbox) .
89 '&passed_id=' . urlencode($passed_id);
91 $print_text = _("View Printable Version");
94 /* Output the link. */
96 $result = '<script language="javascript" type="text/javascript">' . "\n" .
98 " function printFormat() {\n" .
99 ' window.open("../src/printer_friendly_main.php' .
100 $params . '","Print","width=800,height=600");' . "\n".
104 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
106 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
107 "$params\">$print_text</a>\n";
112 function ServerMDNSupport($aFlags) {
113 /* escaping $ doesn't work -> \x36 */
114 return (array_search('$mdnsent',$aFlags,true) !== false ||
115 array_search('\\*',$aFlags,true) !== false) ?
true : false;
116 //$ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
120 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
121 global $username, $attachment_dir,
122 $version, $attachments, $squirrelmail_language, $default_charset,
123 $languages, $useSendmail, $domain, $sent_folder,
124 $popuser, $data_dir, $username;
126 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
128 $header = $message->rfc822_header
;
129 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
131 $rfc822_header = new Rfc822Header();
132 $content_type = new ContentType('multipart/report');
133 $content_type->properties
['report-type']='disposition-notification';
136 if ($default_charset) {
137 $content_type->properties
['charset']=$default_charset;
139 $rfc822_header->content_type
= $content_type;
140 $rfc822_header->to
[] = $header->dnt
;
141 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
143 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
144 // This merely comes from compose.php and only happens when there is no
145 // email_addr specified in user's identity (which is the startup config)
146 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
147 $popuser = $usernamedata[1];
148 $domain = $usernamedata[2];
149 unset($usernamedata);
151 $popuser = $username;
155 $ident = get_identities();
156 if(!isset($identity)) $identity = 0;
157 $full_name = $ident[$identity]['full_name'];
158 $from_mail = $ident[$identity]['email_address'];
159 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
160 $reply_to = $ident[$identity]['reply_to'];
163 $from_mail = "$popuser@$domain";
164 $from_addr = $from_mail;
166 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
168 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
172 $senton = getLongDateString( $header->date
);
173 $to_array = $header->to
;
175 foreach ($to_array as $line) {
176 $to .= ' '.$line->getAddress();
178 $now = getLongDateString( time() );
180 $body = _("Your message") . "\r\n\r\n" .
181 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
182 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
183 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
185 sprintf( _("Was displayed on %s"), $now );
187 $special_encoding = '';
188 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
189 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
190 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
191 if (strtolower($default_charset) == 'iso-2022-jp') {
192 if (mb_detect_encoding($body) == 'ASCII') {
193 $special_encoding = '8bit';
195 $body = mb_convert_encoding($body, 'JIS');
196 $special_encoding = '7bit';
200 $part1 = new Message();
201 $part1->setBody($body);
202 $mime_header = new MessageHeader
;
203 $mime_header->type0
= 'text';
204 $mime_header->type1
= 'plain';
205 if ($special_encoding) {
206 $mime_header->encoding
= $special_encoding;
208 $mime_header->encoding
= 'us-ascii';
210 if ($default_charset) {
211 $mime_header->parameters
['charset'] = $default_charset;
213 $part1->mime_header
= $mime_header;
216 $original_recipient = $to;
217 $original_message_id = $header->message_id
;
219 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
220 if ($original_recipient != '') {
221 $report .= "Original-Recipient : $original_recipient\r\n";
223 $final_recipient = $sender;
224 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
225 "Original-Message-ID : $original_message_id\r\n" .
226 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
228 $part2 = new Message();
229 $part2->setBody($report);
230 $mime_header = new MessageHeader
;
231 $mime_header->type0
= 'message';
232 $mime_header->type1
= 'disposition-notification';
233 $mime_header->encoding
= 'us-ascii';
234 $part2->mime_header
= $mime_header;
236 $composeMessage = new Message();
237 $composeMessage->rfc822_header
= $rfc822_header;
238 $composeMessage->addEntity($part1);
239 $composeMessage->addEntity($part2);
243 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
244 global $sendmail_path;
245 $deliver = new Deliver_SendMail();
246 $stream = $deliver->initStream($composeMessage,$sendmail_path);
248 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
249 $deliver = new Deliver_SMTP();
250 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
251 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
252 get_smtp_user($user, $pass);
253 $stream = $deliver->initStream($composeMessage,$domain,0,
254 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
258 $length = $deliver->mail($composeMessage, $stream);
259 $success = $deliver->finalizeStream($stream);
262 $msg = $deliver->dlv_msg
. '<br>' .
263 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
264 $deliver->dlv_server_msg
;
265 require_once(SM_PATH
. 'functions/display_messages.php');
266 plain_error_message($msg, $color);
269 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
270 sqimap_append ($imapConnection, $sent_folder, $length);
271 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
272 $imap_deliver = new Deliver_IMAP();
273 $imap_deliver->mail($composeMessage, $imapConnection);
274 sqimap_append_done ($imapConnection);
275 unset ($imap_deliver);
281 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
283 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
284 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
288 function ClearAttachments() {
289 global $username, $attachments, $attachment_dir;
291 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
293 $rem_attachments = array();
294 if (isset($attachments)) {
295 foreach ($attachments as $info) {
296 if ($info['session'] == -1) {
297 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
298 if (file_exists($attached_file)) {
299 unlink($attached_file);
302 $rem_attachments[] = $info;
306 $attachments = $rem_attachments;
309 function formatRecipientString($recipients, $item ) {
310 global $show_more_cc, $show_more, $show_more_bcc,
314 if ((is_array($recipients)) && (isset($recipients[0]))) {
320 $url = set_url_var($PHP_SELF, 'show_more',0);
322 $url = set_url_var($PHP_SELF, 'show_more',1);
324 } else if ($item == 'cc') {
327 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
329 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
331 } else if ($item == 'bcc') {
332 if ($show_more_bcc) {
334 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
336 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
340 $cnt = count($recipients);
341 foreach($recipients as $r) {
342 $add = decodeHeader($r->getAddress(true));
344 $string .= '<BR>' . $add;
348 $string .= ' (<A HREF="'.$url;
350 $string .= '">'._("less").'</A>)';
352 $string .= '">'._("more").'</A>)';
362 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
363 $color, $FirstTimeSee) {
364 global $msn_user_support, $default_use_mdn, $default_use_priority,
365 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
366 $squirrelmail_language;
368 $header = $message->rfc822_header
;
370 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
372 $from_name = $header->getAddr_s('from');
374 $from_name = $header->getAddr_s('sender');
376 $env[_("From")] = _("Unknown sender");
378 $env[_("From")] = decodeHeader($from_name);
379 $env[_("Date")] = getLongDateString($header->date
);
380 $env[_("To")] = formatRecipientString($header->to
, "to");
381 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
382 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
383 if ($default_use_priority) {
384 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
386 if ($show_xmailer_default) {
387 $env[_("Mailer")] = decodeHeader($header->xmailer
);
389 if ($default_use_mdn) {
390 if ($mdn_user_support) {
392 if ($message->is_mdnsent
) {
393 $env[_("Read receipt")] = _("sent");
395 $env[_("Read receipt")] = _("requested");
396 if (!(handleAsSent($mailbox) ||
397 $message->is_deleted ||
399 $mdn_url = $PHP_SELF . '&sendreceipt=1';
400 if ($FirstTimeSee && $javascript_on) {
401 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
402 $script .= '<!--'. "\n";
403 $script .= 'if(window.confirm("' .
404 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
408 $script .= '// -->'. "\n";
409 $script .= '</script>'. "\n";
412 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
413 _("Send read receipt now") . ']</a>';
420 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
421 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
422 foreach ($env as $key => $val) {
425 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
426 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
430 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
431 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
432 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
433 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
435 do_hook('read_body_header');
436 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
438 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
443 * Format message toolbar
445 * @param string $mailbox Name of current mailbox
446 * @param int $passed_id UID of current message
447 * @param int $passed_ent_id Id of entity within message
448 * @param object $message Current message object
449 * @param object $mbx_response
451 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
452 global $base_uri, $draft_folder, $where, $what, $color, $sort,
453 $startMessage, $PHP_SELF, $save_as_draft,
454 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
455 $data_dir, $username, $delete_prev_next_display,
456 $compose_new_win, $javascript_on;
458 $topbar_delimiter = ' | ';
459 $double_delimiter = ' ';
460 $urlMailbox = urlencode($mailbox);
462 $msgs_url = $base_uri . 'src/';
464 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
465 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
467 // Create Prev & Next links
468 // Handle nested entities first (i.e. Mime Attach parts)
469 if (isset($passed_ent_id) && $passed_ent_id) {
470 // code for navigating through attached message/rfc822 messages
471 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
473 $entity_count = array();
476 foreach($message->parent
->entities
as $ent) {
477 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
479 $entity_count[$c] = $ent->entity_id
;
480 $entities[$ent->entity_id
] = $c;
484 $prev_link = _("Previous");
485 if($entities[$passed_ent_id] > 1) {
486 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
487 $prev_link = '<a href="'
488 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
489 . '">' . $prev_link . '</a>';
492 $next_link = _("Next");
493 if($entities[$passed_ent_id] < $c) {
494 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
495 $next_link = '<a href="'
496 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
497 . '">' . $next_link . '</a>';
500 $par_ent_id = $message->parent
->entity_id
;
503 $par_ent_id = substr($par_ent_id,0,-2);
504 if ( $par_ent_id != 0 ) {
505 $up_link = $topbar_delimiter;
506 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
507 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
511 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
512 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
514 // Prev/Next links for regular messages
515 } else if ( !(isset($where) && isset($what)) ) {
516 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
517 $next = findNextMessage($passed_id);
519 $prev_link = _("Previous");
521 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
522 '&mailbox='.$urlMailbox.'&sort='.$sort.
523 '&startMessage='.$startMessage.'&show_more=0';
524 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
527 $next_link = _("Next");
529 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
530 '&mailbox='.$urlMailbox.'&sort='.$sort.
531 '&startMessage='.$startMessage.'&show_more=0';
532 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
535 // Only bother with Delete & Prev and Delete & Next IF
536 // top display is enabled.
537 if ( $delete_prev_next_display == 1 &&
538 array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
539 $del_prev_link = _("Delete & Prev");
541 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
542 '&mailbox='.$urlMailbox.'&sort='.$sort.
543 '&startMessage='.$startMessage.'&show_more=0'.
544 '&delete_id='.$passed_id;
545 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
548 $del_next_link = _("Delete & Next");
550 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
551 '&mailbox='.$urlMailbox.'&sort='.$sort.
552 '&startMessage='.$startMessage.'&show_more=0'.
553 '&delete_id='.$passed_id;
554 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
558 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
559 if ( isset($del_prev_link) && isset($del_next_link) )
560 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
563 // Start with Search Results or Message List link.
564 if (isset($where) && isset($what)) {
565 $msgs_url .= 'search.php?where=' . urlencode($where) .
566 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
567 $msgs_str = _("Search Results");
569 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
570 $startMessage . '&mailbox=' . $urlMailbox;
571 $msgs_str = _("Message List");
573 $nav_row .= $double_delimiter .
574 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
576 $nav_row .= '</small></td></tr>';
579 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
580 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
581 $comp_uri = $base_uri.'src/compose.php' .
582 '?passed_id=' . $passed_id .
583 '&mailbox=' . $urlMailbox .
584 '&startMessage=' . $startMessage .
585 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
587 // Start form for reply/reply all/forward..
590 $method='method="post" ';
591 if ($compose_new_win == '1') {
592 if ( $javascript_on ) {
593 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
594 $comp_uri = 'javascript:void(0)';
595 $method='method="get" ';
597 $target = 'target="_blank"';
601 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
603 // If Draft folder - create Resume link
604 if (($mailbox == $draft_folder) && ($save_as_draft)) {
605 $new_button = 'smaction_draft';
606 $comp_alt_string = _("Resume Draft");
607 } else if (handleAsSent($mailbox)) {
608 // If in Sent folder, edit as new
609 $new_button = 'smaction_edit_new';
610 $comp_alt_string = _("Edit Message as New");
612 // Show Alt URI for Draft/Sent
613 if (isset($comp_alt_string))
614 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
616 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
617 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
618 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
619 if ($enable_forward_as_attachment)
620 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .' '."\n";
622 $menu_row .= '</form> ';
624 if (array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
626 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
627 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
629 if (!(isset($passed_ent_id) && $passed_ent_id)) {
630 $menu_row .= addHidden('message', $passed_id);
632 if ($where && $what) {
633 $menu_row .= addHidden('where', $where);
634 $menu_row .= addHidden('what', $what);
636 $menu_row .= addHidden('sort', $sort);
637 $menu_row .= addHidden('startMessage', $startMessage);
639 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
640 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
643 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
645 $menu_row .= '</form>';
649 $menu_row .= '</small></td><td align="right">';
650 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
651 array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
653 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
655 // Set subsequent location based on whether or not there is a 'next' message.
656 if ( isset($next) && $next >= 0 ) {
657 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
658 } elseif (isset($prev) && $prev >= 0) {
659 $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
661 $location = $base_uri . 'src/right_main.php?';
664 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
666 addHidden('show_more', '0' ).
667 addHidden('dmn', '1').
668 addHidden('location', $location.$current_box).
669 addHidden('msg[0]', $passed_id) . _("Move to:") .
670 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
672 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
673 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
675 $menu_row .= sqimap_mailbox_option_list($imapConnection);
677 $menu_row .= '</select> ';
679 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
681 $menu_row .= '</td></tr>';
683 // echo rows, with hooks
684 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
685 if (is_array($ret)) {
686 if (isset($ret[0]) && !empty($ret[0])) {
689 if (isset($ret[1]) && !empty($ret[1])) {
693 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
694 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
695 echo '</table>'."\n";
696 do_hook('read_body_menu_bottom');
699 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
700 global $base_uri, $where, $what;
702 $urlMailbox = urlencode($mailbox);
703 $urlPassed_id = urlencode($passed_id);
704 $urlPassed_ent_id = urlencode($passed_ent_id);
706 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
708 if (!empty($where)) {
709 $query_string .= '&where=' . urlencode($where);
713 $query_string .= '&what=' . urlencode($what);
716 $url = $base_uri.'src/view_header.php?'.$query_string;
719 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
720 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
721 '<a href="'.$url.'">'._("View Full Header").'</a>';
723 /* Output the printer friendly link if we are in subtle mode. */
724 $s .= ' | ' .
725 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
727 do_hook("read_body_header_right");
728 $s = "</SMALL></TD>\n" .
734 /***************************/
735 /* Main of read_body.php */
736 /***************************/
738 /* get the globals we may need */
740 sqgetGlobalVar('key', $key, SQ_COOKIE
);
741 sqgetGlobalVar('username', $username, SQ_SESSION
);
742 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
743 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
744 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
746 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
747 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
748 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
749 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
750 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
755 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
756 sqgetGlobalVar('where', $where, SQ_GET
);
757 sqgetGlobalVar('what', $what, SQ_GET
);
758 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
759 $show_more = (int) $temp;
761 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
762 $show_more_cc = (int) $temp;
764 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
765 $show_more_bcc = (int) $temp;
767 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
768 $view_hdr = (int) $temp;
772 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
773 sqgetGlobalVar('mailbox', $mailbox);
775 if ( sqgetGlobalVar('passed_id', $temp) ) {
776 $passed_id = (int) $temp;
778 if ( sqgetGlobalVar('sort', $temp) ) {
781 if ( sqgetGlobalVar('startMessage', $temp) ) {
782 $startMessage = (int) $temp;
785 /* end of get globals */
786 global $sqimap_capabilities, $lastTargetMailbox;
788 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
789 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
792 * Process Delete from delete-move-next
793 * but only if delete_id was set
795 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
796 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
797 sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
801 * $message contains all information about the message
802 * including header and body
805 $uidvalidity = $mbx_response['UIDVALIDITY'];
807 if (!isset($messages[$uidvalidity])) {
808 $messages[$uidvalidity] = array();
810 if (!isset($messages[$uidvalidity][$passed_id]) ||
$delete_id) {
811 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
812 $FirstTimeSee = !$message->is_seen
;
813 $message->is_seen
= true;
814 $messages[$uidvalidity][$passed_id] = $message;
816 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
817 $message = $messages[$uidvalidity][$passed_id];
818 $FirstTimeSee = !$message->is_seen
;
821 if (isset($passed_ent_id) && $passed_ent_id) {
822 $message = $message->getEntity($passed_ent_id);
823 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
824 $message = $message->parent
;
826 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
827 $rfc822_header = new Rfc822Header();
828 $rfc822_header->parseHeader($read);
829 $message->rfc822_header
= $rfc822_header;
833 $header = $message->header
;
837 /****************************************/
838 /* Block for handling incoming url vars */
839 /****************************************/
841 if (isset($sendreceipt)) {
842 if ( !$message->is_mdnsent
) {
843 $final_recipient = '';
844 if ((isset($identity)) && ($identity != 0)) //Main identity
845 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
846 if ($final_recipient == '' )
847 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
848 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
849 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
850 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
851 $message->is_mdnsent
= true;
852 $messages[$uidvalidity][$passed_id]=$message;
857 /***********************************************/
858 /* End of block for handling incoming url vars */
859 /***********************************************/
861 $msgs[$passed_id]['FLAG_SEEN'] = true;
864 do_hook('read_body_top');
865 if ($show_html_default == 1) {
866 $ent_ar = $message->findDisplayEntity(array());
868 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
870 $cnt = count($ent_ar);
871 for ($i = 0; $i < $cnt; $i++
) {
872 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
874 $messagebody .= '<hr noshade size=1>';
878 displayPageHeader($color, $mailbox);
879 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
880 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
881 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
883 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
885 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
886 echo ' <tr bgcolor="'.$color[4].'"><td>';
887 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
888 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
889 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
893 echo ' </table></td></tr>';
897 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
898 $color[4].'"></TD></TR>'."\n";
900 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
901 if ($attachmentsdisplay) {
903 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
905 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
906 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
907 echo ' <b>' . _("Attachments") . ':</b>';
910 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
911 echo $attachmentsdisplay;
912 echo ' </td></tr></table>';
913 echo ' </td></tr></table>';
915 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
916 $color[4].'"></TD></TR>';
920 /* show attached images inline -- if pref'fed so */
921 if (($attachment_common_show_images) &&
922 is_array($attachment_common_show_images_list)) {
923 foreach ($attachment_common_show_images_list as $img) {
924 $imgurl = SM_PATH
. 'src/download.php' .
926 'passed_id=' . urlencode($img['passed_id']) .
927 '&mailbox=' . urlencode($mailbox) .
928 '&ent_id=' . urlencode($img['ent_id']) .
929 '&absolute_dl=true';
931 echo html_tag( 'table', "\n" .
932 html_tag( 'tr', "\n" .
933 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
936 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
940 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
942 do_hook('read_body_bottom');
943 do_hook('html_bottom');
944 sqimap_logout($imapConnection);
945 /* sessions are written at the end of the script. it's better to register
946 them at the end so we avoid double session_register calls */
947 sqsession_register($messages,'messages');