6 * Copyright (c) 1999-2004 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.
13 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/mime.php');
27 require_once(SM_PATH
. 'functions/date.php');
28 require_once(SM_PATH
. 'functions/url_parser.php');
29 require_once(SM_PATH
. 'functions/html.php');
30 require_once(SM_PATH
. 'functions/global.php');
31 require_once(SM_PATH
. 'functions/identity.php');
32 require_once(SM_PATH
. 'functions/mailbox_display.php');
35 * Given an IMAP message id number, this will look it up in the cached
36 * and sorted msgs array and return the index of the next message
38 * @param int $passed_id The current message UID
39 * @return the index of the next valid message from the array
41 function findNextMessage($uidset,$passed_id='backwards') {
42 if (!is_array($uidset)) {
45 if ($passed_id=='backwards' ||
!is_array($uidset)) { // check for backwards compattibilty gpg plugin
49 $count = count($uidset) - 1;
50 foreach($uidset as $key=>$value) {
51 if ($passed_id == $value) {
55 $result = $uidset[$key +
1];
63 * Given an IMAP message id number, this will look it up in the cached
64 * and sorted msgs array and return the index of the previous message
66 * @param int $passed_id The current message UID
67 * @return the index of the next valid message from the array
70 function findPreviousMessage($uidset, $passed_id) {
71 if (!is_array($uidset)) {
75 foreach($uidset as $key=>$value) {
76 if ($passed_id == $value) {
78 $result = $uidset[$key - 1];
88 * Displays a link to a page where the message is displayed more
90 * @param string $mailbox Name of current mailbox
91 * @param int $passed_id
93 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
94 global $javascript_on;
96 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
97 '&mailbox=' . urlencode($mailbox) .
98 '&passed_id=' . urlencode($passed_id);
100 $print_text = _("View Printable Version");
103 /* Output the link. */
104 if ($javascript_on) {
105 $result = '<script language="javascript" type="text/javascript">' . "\n" .
107 " function printFormat() {\n" .
108 ' window.open("../src/printer_friendly_main.php' .
109 $params . '","Print","width=800,height=600");' . "\n".
113 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
115 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
116 "$params\">$print_text</a>\n";
121 function ServerMDNSupport($aFlags) {
122 /* escaping $ doesn't work -> \x36 */
123 return ( in_array('$mdnsent',$aFlags,true) ||
124 in_array('\\*',$aFlags,true) ) ;
127 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
128 global $username, $attachment_dir, $popuser, $username,
129 $version, $squirrelmail_language, $default_charset,
130 $languages, $useSendmail, $domain, $sent_folder;
132 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
134 $header = $message->rfc822_header
;
135 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
137 $rfc822_header = new Rfc822Header();
138 $content_type = new ContentType('multipart/report');
139 $content_type->properties
['report-type']='disposition-notification';
142 if ($default_charset) {
143 $content_type->properties
['charset']=$default_charset;
145 $rfc822_header->content_type
= $content_type;
146 $rfc822_header->to
[] = $header->dnt
;
147 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
149 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
150 // This merely comes from compose.php and only happens when there is no
151 // email_addr specified in user's identity (which is the startup config)
152 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
153 $popuser = $usernamedata[1];
154 $domain = $usernamedata[2];
155 unset($usernamedata);
157 $popuser = $username;
161 $ident = get_identities();
162 if(!isset($identity)) $identity = 0;
163 $full_name = $ident[$identity]['full_name'];
164 $from_mail = $ident[$identity]['email_address'];
165 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
166 $reply_to = $ident[$identity]['reply_to'];
169 $from_mail = "$popuser@$domain";
170 $from_addr = $from_mail;
172 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
174 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
178 $senton = getLongDateString( $header->date
);
179 $to_array = $header->to
;
181 foreach ($to_array as $line) {
182 $to .= ' '.$line->getAddress();
184 $now = getLongDateString( time() );
186 $body = _("Your message") . "\r\n\r\n" .
187 "\t" . _("To") . ': ' . decodeHeader($to,false,false) . "\r\n" .
188 "\t" . _("Subject") . ': ' . decodeHeader($header->subject
,false,false) . "\r\n" .
189 "\t" . _("Sent") . ': ' . $senton . "\r\n" .
191 sprintf( _("Was displayed on %s"), $now );
193 $special_encoding = '';
194 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
195 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
196 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body);
197 if (strtolower($default_charset) == 'iso-2022-jp') {
198 if (mb_detect_encoding($body) == 'ASCII') {
199 $special_encoding = '8bit';
201 $body = mb_convert_encoding($body, 'JIS');
202 $special_encoding = '7bit';
205 } elseif (sq_is8bit($body)) {
206 $special_encoding = '8bit';
208 $part1 = new Message();
209 $part1->setBody($body);
210 $mime_header = new MessageHeader
;
211 $mime_header->type0
= 'text';
212 $mime_header->type1
= 'plain';
213 if ($special_encoding) {
214 $mime_header->encoding
= $special_encoding;
216 $mime_header->encoding
= 'us-ascii';
218 if ($default_charset) {
219 $mime_header->parameters
['charset'] = $default_charset;
221 $part1->mime_header
= $mime_header;
224 $original_recipient = $to;
225 $original_message_id = $header->message_id
;
227 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
228 if ($original_recipient != '') {
229 $report .= "Original-Recipient : $original_recipient\r\n";
231 $final_recipient = $sender;
232 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
233 "Original-Message-ID : $original_message_id\r\n" .
234 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
236 $part2 = new Message();
237 $part2->setBody($report);
238 $mime_header = new MessageHeader
;
239 $mime_header->type0
= 'message';
240 $mime_header->type1
= 'disposition-notification';
241 $mime_header->encoding
= 'us-ascii';
242 $part2->mime_header
= $mime_header;
244 $composeMessage = new Message();
245 $composeMessage->rfc822_header
= $rfc822_header;
246 $composeMessage->addEntity($part1);
247 $composeMessage->addEntity($part2);
251 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
252 global $sendmail_path;
253 $deliver = new Deliver_SendMail();
254 $stream = $deliver->initStream($composeMessage,$sendmail_path);
256 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
257 $deliver = new Deliver_SMTP();
258 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
259 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
260 get_smtp_user($user, $pass);
261 $stream = $deliver->initStream($composeMessage,$domain,0,
262 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
266 $length = $deliver->mail($composeMessage, $stream);
267 $success = $deliver->finalizeStream($stream);
270 $msg = $deliver->dlv_msg
. '<br />' .
271 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
272 $deliver->dlv_server_msg
;
273 require_once(SM_PATH
. 'functions/display_messages.php');
274 plain_error_message($msg, $color);
277 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
278 sqimap_append ($imapConnection, $sent_folder, $length);
279 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
280 $imap_deliver = new Deliver_IMAP();
281 $imap_deliver->mail($composeMessage, $imapConnection);
282 sqimap_append_done ($imapConnection);
283 unset ($imap_deliver);
289 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
291 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
292 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
296 function ClearAttachments() {
297 global $username, $attachments, $attachment_dir;
299 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
301 $rem_attachments = array();
302 if (isset($attachments)) {
303 foreach ($attachments as $info) {
304 if ($info['session'] == -1) {
305 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
306 if (file_exists($attached_file)) {
307 unlink($attached_file);
310 $rem_attachments[] = $info;
314 $attachments = $rem_attachments;
317 function formatRecipientString($recipients, $item ) {
318 global $show_more_cc, $show_more, $show_more_bcc,
322 if ((is_array($recipients)) && (isset($recipients[0]))) {
328 $url = set_url_var($PHP_SELF, 'show_more',0);
330 $url = set_url_var($PHP_SELF, 'show_more',1);
332 } else if ($item == 'cc') {
335 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
337 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
339 } else if ($item == 'bcc') {
340 if ($show_more_bcc) {
342 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
344 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
348 $cnt = count($recipients);
349 foreach($recipients as $r) {
350 $add = decodeHeader($r->getAddress(true));
352 $string .= '<br />' . $add;
356 $string .= ' (<a href="'.$url;
358 $string .= '">'._("less").'</a>)';
360 $string .= '">'._("more").'</a>)';
370 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
371 $color, $FirstTimeSee) {
372 global $default_use_mdn, $default_use_priority,
373 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
374 $squirrelmail_language;
376 $mailbox = $aMailbox['NAME'];
378 $header = $message->rfc822_header
;
380 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
382 $from_name = $header->getAddr_s('from');
384 $from_name = $header->getAddr_s('sender');
386 $env[_("From")] = _("Unknown sender");
388 $env[_("From")] = decodeHeader($from_name);
389 $env[_("Date")] = getLongDateString($header->date
);
390 $env[_("To")] = formatRecipientString($header->to
, "to");
391 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
392 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
393 if ($default_use_priority) {
394 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
396 if ($show_xmailer_default) {
397 $env[_("Mailer")] = decodeHeader($header->xmailer
);
399 if ($default_use_mdn) {
400 if ($mdn_user_support) {
402 if ($message->is_mdnsent
) {
403 $env[_("Read receipt")] = _("sent");
405 $env[_("Read receipt")] = _("requested");
406 if (!(handleAsSent($mailbox) ||
407 $message->is_deleted ||
409 $mdn_url = $PHP_SELF . '&sendreceipt=1';
410 if ($FirstTimeSee && $javascript_on) {
411 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
412 $script .= '<!--'. "\n";
413 $script .= 'if(window.confirm("' .
414 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
418 $script .= '// -->'. "\n";
419 $script .= '</script>'. "\n";
422 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
423 _("Send read receipt now") . ']</a>';
430 $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
431 $s .= ' align="center" bgcolor="'.$color[0].'">';
432 foreach ($env as $key => $val) {
435 $s .= html_tag('td', '<b>' . $key . ': </b>', 'right', '', 'valign="top" width="20%"') . "\n";
436 $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
440 echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
441 ' cellspacing="0" border="0" align="center">'."\n";
442 echo '<tr><td height="5" colspan="2" bgcolor="'.
443 $color[4].'"></td></tr><tr><td align="center">'."\n";
445 do_hook('read_body_header');
446 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
448 echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
453 * Format message toolbar
455 * @param string $mailbox Name of current mailbox
456 * @param int $passed_id UID of current message
457 * @param int $passed_ent_id Id of entity within message
458 * @param object $message Current message object
459 * @param object $mbx_response
461 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
462 global $base_uri, $draft_folder, $where, $what, $color, $sort,
463 $startMessage, $PHP_SELF, $save_as_draft,
464 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
465 $username, $delete_prev_next_display,
466 $compose_new_win, $javascript_on;
468 //FIXME cleanup argument list, use $aMailbox where possible
469 $mailbox = $aMailbox['NAME'];
471 $topbar_delimiter = ' | ';
472 $double_delimiter = ' ';
473 $urlMailbox = urlencode($mailbox);
475 $msgs_url = $base_uri . 'src/';
477 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
478 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
480 // Create Prev & Next links
481 // Handle nested entities first (i.e. Mime Attach parts)
482 if (isset($passed_ent_id) && $passed_ent_id) {
483 // code for navigating through attached message/rfc822 messages
484 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
486 $entity_count = array();
489 foreach($message->parent
->entities
as $ent) {
490 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
492 $entity_count[$c] = $ent->entity_id
;
493 $entities[$ent->entity_id
] = $c;
497 $prev_link = _("Previous");
498 if($entities[$passed_ent_id] > 1) {
499 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
500 $prev_link = '<a href="'
501 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
502 . '">' . $prev_link . '</a>';
505 $next_link = _("Next");
506 if($entities[$passed_ent_id] < $c) {
507 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
508 $next_link = '<a href="'
509 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
510 . '">' . $next_link . '</a>';
513 $par_ent_id = $message->parent
->entity_id
;
516 $par_ent_id = substr($par_ent_id,0,-2);
517 if ( $par_ent_id != 0 ) {
518 $up_link = $topbar_delimiter;
519 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
520 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
524 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
525 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
527 // Prev/Next links for regular messages
528 } else if ( true ) { //!(isset($where) && isset($what)) ) {
530 * Check if cache is still valid
532 if (!is_array($aMailbox['UIDSET'][$what])) {
533 fetchMessageHeaders($imapConnection, $aMailbox);
535 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
536 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
538 $prev_link = _("Previous");
540 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
541 '&mailbox='.$urlMailbox.'&sort='.$sort.
542 "&where=$where&what=$what" .
543 '&startMessage='.$startMessage.'&show_more=0';
544 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
547 $next_link = _("Next");
549 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
550 '&mailbox='.$urlMailbox.'&sort='.$sort.
551 "&where=$where&what=$what" .
552 '&startMessage='.$startMessage.'&show_more=0';
553 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
556 // Only bother with Delete & Prev and Delete & Next IF
557 // top display is enabled.
558 if ( $delete_prev_next_display == 1 &&
559 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
560 $del_prev_link = _("Delete & Prev");
562 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
563 '&mailbox='.$urlMailbox.'&sort='.$sort.
564 '&startMessage='.$startMessage.'&show_more=0'.
565 "&where=$where&what=$what" .
566 '&delete_id='.$passed_id;
567 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
570 $del_next_link = _("Delete & Next");
572 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
573 '&mailbox='.$urlMailbox.'&sort='.$sort.
574 '&startMessage='.$startMessage.'&show_more=0'.
575 "&where=$where&what=$what" .
576 '&delete_id='.$passed_id;
577 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
581 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
582 if ( isset($del_prev_link) && isset($del_next_link) )
583 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
586 // Start with Search Results or Message List link.
587 $msgs_url .= "$where?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
588 "&startMessage=$startMessage";
589 if ($where == 'search.php') {
590 $msgs_str = _("Search Results");
592 $msgs_str = _("Message List");
594 $nav_row .= $double_delimiter .
595 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
597 $nav_row .= '</small></td></tr>';
600 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
601 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
602 $comp_uri = $base_uri.'src/compose.php' .
603 '?passed_id=' . $passed_id .
604 '&mailbox=' . $urlMailbox .
605 '&startMessage=' . $startMessage .
606 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
608 // Start form for reply/reply all/forward..
611 $method='method="post" ';
612 if ($compose_new_win == '1') {
613 if ( $javascript_on ) {
614 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
615 $comp_uri = 'javascript:void(0)';
616 $method='method="get" ';
618 $target = 'target="_blank"';
622 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
624 // If Draft folder - create Resume link
625 if (($mailbox == $draft_folder) && ($save_as_draft)) {
626 $new_button = 'smaction_draft';
627 $comp_alt_string = _("Resume Draft");
628 } else if (handleAsSent($mailbox)) {
629 // If in Sent folder, edit as new
630 $new_button = 'smaction_edit_new';
631 $comp_alt_string = _("Edit Message as New");
633 // Show Alt URI for Draft/Sent
634 if (isset($comp_alt_string))
635 $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n";
637 $menu_row .= getButton('submit', 'smaction_reply', _("Reply"), $on_click) . "\n";
638 $menu_row .= getButton('submit', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
639 $menu_row .= getButton('submit', 'smaction_forward', _("Forward"), $on_click);
640 if ($enable_forward_as_attachment)
641 $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .' '."\n";
643 $menu_row .= '</form> ';
645 if ( in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
646 // Form for deletion. Form is handled by the originating display in $where. This is right_main.php or search.php
647 $delete_url = $base_uri . "src/$where";
648 $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">';
650 if (!(isset($passed_ent_id) && $passed_ent_id)) {
651 $menu_row .= addHidden('mailbox', $aMailbox['NAME']);
652 $menu_row .= addHidden('msg[0]', $passed_id);
653 $menu_row .= addHidden('startMessage', $startMessage);
654 $menu_row .= getButton('submit', 'delete', _("Delete"));
655 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
657 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
660 $menu_row .= '</form>';
664 $menu_row .= '</small></td><td align="right">';
665 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
666 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
668 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
671 addHidden('mailbox',$aMailbox['NAME']) .
672 addHidden('msg[0]', $passed_id) . _("Move to:") .
673 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
675 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
676 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
678 $menu_row .= sqimap_mailbox_option_list($imapConnection);
680 $menu_row .= '</select> ';
682 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
684 $menu_row .= '</td></tr>';
686 // echo rows, with hooks
687 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
688 if (is_array($ret)) {
689 if (isset($ret[0]) && !empty($ret[0])) {
692 if (isset($ret[1]) && !empty($ret[1])) {
696 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
697 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
698 echo '</table>'."\n";
699 do_hook('read_body_menu_bottom');
702 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
703 global $base_uri, $where, $what;
705 $urlMailbox = urlencode($mailbox);
706 $urlPassed_id = urlencode($passed_id);
707 $urlPassed_ent_id = urlencode($passed_ent_id);
709 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
711 if (!empty($where)) {
712 $query_string .= '&where=' . urlencode($where);
716 $query_string .= '&what=' . urlencode($what);
719 $url = $base_uri.'src/view_header.php?'.$query_string;
722 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ": </b></td>\n" .
723 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
724 '<a href="'.$url.'">'._("View Full Header").'</a>';
726 /* Output the printer friendly link if we are in subtle mode. */
727 $s .= ' | ' .
728 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
730 do_hook("read_body_header_right");
731 $s = "</small></td>\n" .
737 /***************************/
738 /* Main of read_body.php */
739 /***************************/
741 /* get the globals we may need */
743 sqgetGlobalVar('key', $key, SQ_COOKIE
);
744 sqgetGlobalVar('username', $username, SQ_SESSION
);
745 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
746 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
747 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
748 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
749 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
754 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
755 if (!sqgetGlobalVar('where', $where, SQ_GET
) ) {
756 $where = 'right_main.php';
758 if (!sqgetGlobalVar('what', $what, SQ_GET
) ){
761 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
762 $show_more = (int) $temp;
764 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
765 $show_more_cc = (int) $temp;
767 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
768 $show_more_bcc = (int) $temp;
770 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
771 $view_hdr = (int) $temp;
775 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
776 sqgetGlobalVar('mailbox', $mailbox);
778 if ( sqgetGlobalVar('passed_id', $temp) ) {
779 $passed_id = (int) $temp;
781 if ( sqgetGlobalVar('sort', $temp) ) {
784 if ( sqgetGlobalVar('startMessage', $temp) ) {
785 $startMessage = (int) $temp;
790 * Retrieve mailbox cache
792 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
794 /* end of get globals */
795 global $sqimap_capabilities, $lastTargetMailbox;
797 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
798 $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox,array('setindex' => $what),array());
801 * Update the seen state
802 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
804 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
805 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
809 * Process Delete from delete-move-next
810 * but only if delete_id was set
812 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
813 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
814 // sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
815 // sqimap_mailbox_expunge_dmn($imapConnection,$aMailbox,$delete_id);
819 * $message contains all information about the message
820 * including header and body
823 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
824 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
825 $FirstTimeSee = !$message->is_seen
;
827 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
828 $FirstTimeSee = !$message->is_seen
;
829 $message->is_seen
= true;
830 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
833 if (isset($passed_ent_id) && $passed_ent_id) {
834 $message = $message->getEntity($passed_ent_id);
835 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
836 $message = $message->parent
;
838 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
839 $rfc822_header = new Rfc822Header();
840 $rfc822_header->parseHeader($read);
841 $message->rfc822_header
= $rfc822_header;
845 $header = $message->header
;
848 /****************************************/
849 /* Block for handling incoming url vars */
850 /****************************************/
852 if (isset($sendreceipt)) {
853 if ( !$message->is_mdnsent
) {
854 $final_recipient = '';
855 if ((isset($identity)) && ($identity != 0)) //Main identity
856 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
857 if ($final_recipient == '' )
858 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
859 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
860 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
861 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
862 $message->is_mdnsent
= true;
863 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
868 /***********************************************/
869 /* End of block for handling incoming url vars */
870 /***********************************************/
875 do_hook('read_body_top');
876 if ($show_html_default == 1) {
877 $ent_ar = $message->findDisplayEntity(array());
879 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
881 $cnt = count($ent_ar);
882 for ($i = 0; $i < $cnt; $i++
) {
883 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
885 $messagebody .= '<hr style="height: 1px;" />';
889 displayPageHeader($color, $mailbox);
890 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
891 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
892 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
894 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
896 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
897 echo ' <tr bgcolor="'.$color[4].'"><td>';
898 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
899 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
900 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
904 echo ' </table></td></tr>';
908 echo '<tr><td height="5" colspan="2" bgcolor="'.
909 $color[4].'"></td></tr>'."\n";
911 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
912 if ($attachmentsdisplay) {
914 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
916 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
917 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
918 echo ' <b>' . _("Attachments") . ':</b>';
921 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
922 echo $attachmentsdisplay;
923 echo ' </td></tr></table>';
924 echo ' </td></tr></table>';
926 echo '<tr><td height="5" colspan="2" bgcolor="'.
927 $color[4].'"></td></tr>';
931 /* show attached images inline -- if pref'fed so */
932 if (($attachment_common_show_images) &&
933 is_array($attachment_common_show_images_list)) {
934 foreach ($attachment_common_show_images_list as $img) {
935 $imgurl = SM_PATH
. 'src/download.php' .
937 'passed_id=' . urlencode($img['passed_id']) .
938 '&mailbox=' . urlencode($mailbox) .
939 '&ent_id=' . urlencode($img['ent_id']) .
940 '&absolute_dl=true';
942 echo html_tag( 'table', "\n" .
943 html_tag( 'tr', "\n" .
944 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
947 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
951 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
953 do_hook('read_body_bottom');
954 sqimap_logout($imapConnection);
955 /* sessions are written at the end of the script. it's better to register
956 them at the end so we avoid double session_register calls */
957 /* add the mailbox to the cache */
958 $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
959 sqsession_register($mailbox_cache,'mailbox_cache');