f35c80b9336656047afe9134061f660534c6ad8b
6 * This file is used for reading the msgs array and displaying
7 * the resulting emails in the right frame.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
16 * Include the SquirrelMail initialization file.
18 require('../include/init.php');
20 /* SquirrelMail required files. */
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/imap_asearch.php'); // => move to mailbox_display
23 require_once(SM_PATH
. 'functions/mime.php');
24 require_once(SM_PATH
. 'functions/date.php');
25 require_once(SM_PATH
. 'functions/url_parser.php');
26 require_once(SM_PATH
. 'functions/identity.php');
27 require_once(SM_PATH
. 'functions/mailbox_display.php');
28 require_once(SM_PATH
. 'functions/forms.php');
29 require_once(SM_PATH
. 'functions/attachment_common.php');
32 * Given an IMAP message id number, this will look it up in the cached
33 * and sorted msgs array and return the index of the next message
35 * @param int $passed_id The current message UID
36 * @return the index of the next valid message from the array
38 function findNextMessage($uidset,$passed_id='backwards') {
39 if (!is_array($uidset)) {
42 if ($passed_id=='backwards' ||
!is_array($uidset)) { // check for backwards compattibilty gpg plugin
45 $result = sqm_array_get_value_by_offset($uidset,$passed_id,1);
46 if ($result === false) {
54 * Given an IMAP message id number, this will look it up in the cached
55 * and sorted msgs array and return the index of the previous message
57 * @param int $passed_id The current message UID
58 * @return the index of the next valid message from the array
61 function findPreviousMessage($uidset, $passed_id) {
62 if (!is_array($uidset)) {
65 $result = sqm_array_get_value_by_offset($uidset,$passed_id,-1);
66 if ($result === false) {
73 function html_toggle_href ($mailbox, $passed_id, $passed_ent_id, $message) {
74 global $base_uri, $show_html_default;
77 if ($message->header
->type0
== 'message' && $message->header
->type1
== 'rfc822') {
78 $type0 = $message->rfc822_header
->content_type
->type0
;
79 $type1 = $message->rfc822_header
->content_type
->type1
;
81 $type0 = $message->header
->type0
;
82 $type1 = $message->header
->type1
;
84 if($type0 == 'multipart' &&
85 ($type1 == 'alternative' ||
$type1 == 'mixed' ||
$type1 == 'related' ||
$type1=='signed')) {
86 if ($message->findDisplayEntity(array(), array('text/html'), true)) {
91 * Normal single part message so check its type.
94 if($type0 == 'text' && $type1 == 'html') {
98 if($has_html == true) {
99 $vars = array('passed_ent_id', 'show_more', 'show_more_cc', 'override_type0', 'override_type1', 'startMessage','where', 'what');
101 $new_link = $base_uri . 'src/read_body.php?passed_id=' . urlencode($passed_id) .
102 '&passed_ent_id=' . urlencode($passed_ent_id) .
103 '&mailbox=' . urlencode($mailbox);
104 foreach($vars as $var) {
105 if(sqgetGlobalVar($var, $temp)) {
106 $new_link .= '&' . $var . '=' . urlencode($temp);
110 if($show_html_default == 1) {
111 $new_link .= '&show_html_default=0';
113 $new_link .= '&show_html_default=1';
120 function ServerMDNSupport($aFlags) {
121 /* escaping $ doesn't work -> \x36 */
122 return ( in_array('$mdnsent',$aFlags,true) ||
123 in_array('\\*',$aFlags,true) ) ;
126 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
127 global $username, $attachment_dir, $popuser, $username, $color,
128 $version, $squirrelmail_language, $default_charset,
129 $languages, $useSendmail, $domain, $sent_folder;
131 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
133 $header = $message->rfc822_header
;
135 $rfc822_header = new Rfc822Header();
136 $content_type = new ContentType('multipart/report');
137 $content_type->properties
['report-type']='disposition-notification';
140 if ($default_charset) {
141 $content_type->properties
['charset']=$default_charset;
143 $rfc822_header->content_type
= $content_type;
144 $rfc822_header->to
[] = $header->dnt
;
145 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
147 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
148 // This merely comes from compose.php and only happens when there is no
149 // email_addr specified in user's identity (which is the startup config)
150 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
151 $popuser = $usernamedata[1];
152 $domain = $usernamedata[2];
153 unset($usernamedata);
155 $popuser = $username;
159 $ident = get_identities();
160 if(!isset($identity)) $identity = 0;
161 $full_name = $ident[$identity]['full_name'];
162 $from_mail = $ident[$identity]['email_address'];
163 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
164 $reply_to = $ident[$identity]['reply_to'];
167 $from_mail = "$popuser@$domain";
168 $from_addr = $from_mail;
170 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
172 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
176 $senton = getLongDateString( $header->date
);
177 $to_array = $header->to
;
179 foreach ($to_array as $line) {
180 $to .= ' '.$line->getAddress();
182 $now = getLongDateString( time() );
184 $body = _("Your message") . "\r\n\r\n" .
185 "\t" . _("To") . ': ' . decodeHeader($to,false,false) . "\r\n" .
186 "\t" . _("Subject") . ': ' . decodeHeader($header->subject
,false,false) . "\r\n" .
187 "\t" . _("Sent") . ': ' . $senton . "\r\n" .
189 sprintf( _("Was displayed on %s"), $now );
191 $special_encoding = '';
192 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
193 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
194 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body);
195 if (strtolower($default_charset) == 'iso-2022-jp') {
196 if (mb_detect_encoding($body) == 'ASCII') {
197 $special_encoding = '8bit';
199 $body = mb_convert_encoding($body, 'JIS');
200 $special_encoding = '7bit';
203 } elseif (sq_is8bit($body)) {
204 $special_encoding = '8bit';
206 $part1 = new Message();
207 $part1->setBody($body);
208 $mime_header = new MessageHeader
;
209 $mime_header->type0
= 'text';
210 $mime_header->type1
= 'plain';
211 if ($special_encoding) {
212 $mime_header->encoding
= $special_encoding;
214 $mime_header->encoding
= 'us-ascii';
216 if ($default_charset) {
217 $mime_header->parameters
['charset'] = $default_charset;
219 $part1->mime_header
= $mime_header;
222 $original_recipient = $to;
223 $original_message_id = $header->message_id
;
225 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
226 if ($original_recipient != '') {
227 $report .= "Original-Recipient : $original_recipient\r\n";
229 $final_recipient = $sender;
230 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
231 "Original-Message-ID : $original_message_id\r\n" .
232 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
234 $part2 = new Message();
235 $part2->setBody($report);
236 $mime_header = new MessageHeader
;
237 $mime_header->type0
= 'message';
238 $mime_header->type1
= 'disposition-notification';
239 $mime_header->encoding
= 'us-ascii';
240 $part2->mime_header
= $mime_header;
242 $composeMessage = new Message();
243 $composeMessage->rfc822_header
= $rfc822_header;
244 $composeMessage->addEntity($part1);
245 $composeMessage->addEntity($part2);
249 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
250 global $sendmail_path, $sendmail_args;
251 // Check for outdated configuration
252 if (!isset($sendmail_args)) {
253 if ($sendmail_path=='/var/qmail/bin/qmail-inject') {
256 $sendmail_args = '-i -t';
259 $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args));
260 $stream = $deliver->initStream($composeMessage,$sendmail_path);
262 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
263 $deliver = new Deliver_SMTP();
264 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
265 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
266 get_smtp_user($user, $pass);
267 $stream = $deliver->initStream($composeMessage,$domain,0,
268 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
272 $length = $deliver->mail($composeMessage, $stream);
273 $success = $deliver->finalizeStream($stream);
276 $msg = $deliver->dlv_msg
;
277 if (! empty($deliver->dlv_server_msg
)) {
279 _("Server replied:") . ' ' . $deliver->dlv_ret_nr
. ' ' .
280 nl2br(htmlspecialchars($deliver->dlv_server_msg
));
282 plain_error_message($msg, $color);
285 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
286 $sid = sqimap_append ($imapConnection, $sent_folder, $length);
287 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
288 $imap_deliver = new Deliver_IMAP();
289 $imap_deliver->mail($composeMessage, $imapConnection);
290 sqimap_append_done ($imapConnection, $sent_folder);
291 unset ($imap_deliver);
297 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
299 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
300 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
304 function formatRecipientString($recipients, $item ) {
305 global $show_more_cc, $show_more, $show_more_bcc,
306 $PHP_SELF, $oTemplate;
309 if ((is_array($recipients)) && (isset($recipients[0]))) {
315 $url = set_url_var($PHP_SELF, 'show_more',0);
317 $url = set_url_var($PHP_SELF, 'show_more',1);
319 } else if ($item == 'cc') {
322 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
324 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
326 } else if ($item == 'bcc') {
327 if ($show_more_bcc) {
329 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
331 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
336 foreach ($recipients as $r) {
338 'Name' => htmlspecialchars($r->getAddress(false)),
339 'Email' => htmlspecialchars($r->getEmail()),
340 'Full' => htmlspecialchars($r->getAddress(true))
344 $oTemplate->assign('which_field', $item);
345 $oTemplate->assign('recipients', $a);
346 $oTemplate->assign('more_less_toggle_href', $url);
347 $oTemplate->assign('show_more', $show);
349 $string = $oTemplate->fetch('read_recipient_list.tpl');
354 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
355 $color, $FirstTimeSee) {
356 global $default_use_mdn, $default_use_priority,
357 $show_xmailer_default, $mdn_user_support, $PHP_SELF,
358 $squirrelmail_language, $oTemplate;
360 $mailbox = $aMailbox['NAME'];
362 $header = $message->rfc822_header
;
364 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
366 $from_name = $header->getAddr_s('from');
368 $from_name = $header->getAddr_s('sender');
370 $env[_("From")] = _("Unknown sender");
372 $env[_("From")] = decodeHeader($from_name);
373 $env[_("Date")] = getLongDateString($header->date
);
374 $env[_("To")] = formatRecipientString($header->to
, "to");
375 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
376 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
377 if ($default_use_priority) {
378 $oTemplate->assign('message_priority', $header->priority
);
379 $env[_("Priority")] = $oTemplate->fetch('read_message_priority.tpl');
381 if ($show_xmailer_default) {
382 $oTemplate->assign('xmailer', decodeHeader($header->xmailer
));
383 $env[_("Mailer")] = $oTemplate->fetch('read_xmailer.tpl');
385 if ($default_use_mdn) {
386 if ($mdn_user_support) {
388 $mdn_url = $PHP_SELF;
389 $mdn_url = set_url_var($PHP_SELF, 'mailbox', urlencode($mailbox));
390 $mdn_url = set_url_var($PHP_SELF, 'passed_id', $passed_id);
391 $mdn_url = set_url_var($PHP_SELF, 'passed_ent_id', $passed_ent_id);
392 $mdn_url = set_url_var($PHP_SELF, 'sendreceipt', 1);
394 $oTemplate->assign('read_receipt_sent', $message->is_mdnsent
);
395 $oTemplate->assign('first_time_reading', $FirstTimeSee);
396 $oTemplate->assign('send_receipt_href', $mdn_url);
398 $env[_("Read Receipt")] = $oTemplate->fetch('read_handle_receipt.tpl');
404 if ( $message->is_deleted
) {
405 $statuses[] = _("deleted");
407 if ( $message->is_answered
) {
408 $statuses[] = _("answered");
410 if ( $message->is_draft
) {
411 $statuses[] = _("draft");
413 if ( $message->is_flagged
) {
414 $statuses[] = _("flagged");
416 if ( count($statuses) ) {
417 $env[_("Status")] = implode(', ', $statuses);
420 $env[_("Options")] = formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
423 $oTemplate->assign('headers_to_display', $env);
425 $oTemplate->display('read_headers.tpl');
429 * Format message toolbar
431 * @param string $mailbox Name of current mailbox
432 * @param int $passed_id UID of current message
433 * @param int $passed_ent_id Id of entity within message
434 * @param object $message Current message object
435 * @param object $mbx_response
437 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
438 global $base_uri, $draft_folder, $where, $what, $sort,
439 $startMessage, $PHP_SELF, $save_as_draft,
440 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
441 $delete_prev_next_display, $show_copy_buttons,
442 $compose_new_win, $compose_width, $compose_height,
445 //FIXME cleanup argument list, use $aMailbox where possible
446 $mailbox = $aMailbox['NAME'];
448 $urlMailbox = urlencode($mailbox);
450 $msgs_url = $base_uri . 'src/';
452 // Create Prev & Next links
453 // Handle nested entities first (i.e. Mime Attach parts)
454 $prev_href = $next_href = $up_href = $del_href = $del_prev_href = $del_next_href = '';
455 $msg_list_href = $search_href = $view_msg_href = '';
456 if (isset($passed_ent_id) && $passed_ent_id) {
457 // code for navigating through attached message/rfc822 messages
458 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
460 $entity_count = array();
463 foreach($message->parent
->entities
as $ent) {
464 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
467 $entity_count[$c] = $ent->entity_id
;
468 $entities[$ent->entity_id
] = $c;
472 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] > 1) {
473 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
474 $prev_href = set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id);
477 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] < $c) {
478 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
479 $next_href = set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id);
482 $par_ent_id = $message->parent
->entity_id
;
484 $par_ent_id = substr($par_ent_id,0,-2);
485 if ( $par_ent_id != 0 ) {
486 $up_href = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
490 $view_msg_href = $url;
492 // Prev/Next links for regular messages
493 } else if ( true ) { //!(isset($where) && isset($what)) ) {
494 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
495 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
498 $prev_href = $base_uri . 'src/read_body.php?passed_id='.$prev.
499 '&mailbox='.$urlMailbox.'&sort='.$sort.
500 "&where=$where&what=$what" .
501 '&startMessage='.$startMessage.'&show_more=0';
505 $next_href = $base_uri . 'src/read_body.php?passed_id='.$next.
506 '&mailbox='.$urlMailbox.'&sort='.$sort.
507 "&where=$where&what=$what" .
508 '&startMessage='.$startMessage.'&show_more=0';
511 // Only bother with Delete & Prev and Delete & Next IF
512 // top display is enabled.
513 if ( $delete_prev_next_display == 1 &&
514 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
516 $del_prev_href = $base_uri . 'src/read_body.php?passed_id='.$prev.
517 '&mailbox='.$urlMailbox.'&sort='.$sort.
518 '&startMessage='.$startMessage.'&show_more=0'.
519 "&where=$where&what=$what" .
520 '&delete_id='.$passed_id;
524 $del_next_href = $base_uri . 'src/read_body.php?passed_id='.$next.
525 '&mailbox='.$urlMailbox.'&sort='.$sort.
526 '&startMessage='.$startMessage.'&show_more=0'.
527 "&where=$where&what=$what" .
528 '&delete_id='.$passed_id;
533 // Start with Search Results or Message List link.
534 $list_xtra = "?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
535 "&startMessage=$startMessage";
536 $msg_list_href = $base_uri .'src/right_main.php'. $list_xtra;
537 $search_href = $where=='search.php' ?
$base_uri .'src/search.php?'.$list_xtra : '';
539 $comp_uri = $base_uri.'src/compose.php' .
540 '?passed_id=' . $passed_id .
541 '&mailbox=' . $urlMailbox .
542 '&startMessage=' . $startMessage .
543 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
545 // Start form for reply/reply all/forward..
548 $method='method="post" ';
550 if ($compose_new_win == '1') {
551 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
552 $compose_width = '640';
554 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
555 $compose_height = '550';
557 if ( checkForJavascript() ) {
558 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"';
559 $comp_uri = 'javascript:void(0)';
560 $method='method="get" ';
561 $onsubmit = 'onsubmit="return false" ';
563 $target = 'target="_blank"';
567 $oTemplate->assign('nav_on_top', $nav_on_top);
569 $oTemplate->assign('prev_href', $prev_href);
570 $oTemplate->assign('up_href', $up_href);
571 $oTemplate->assign('next_href', $next_href);
572 $oTemplate->assign('del_prev_href', $del_prev_href);
573 $oTemplate->assign('del_next_href', $del_next_href);
574 $oTemplate->assign('view_msg_href', $view_msg_href);
576 $oTemplate->assign('message_list_href', $msg_list_href);
577 $oTemplate->assign('search_href', $search_href);
579 $oTemplate->assign('form_extra', $method . $target . $onsubmit);
580 $oTemplate->assign('compose_href', $comp_uri);
581 $oTemplate->assign('button_onclick', $on_click);
582 $oTemplate->assign('forward_as_attachment_enabled', $enable_forward_as_attachment==1);
584 //FIXME: I am surprised these aren't already given to the template; probably needs to be given at a higher level, so I have NO IDEA if this is the right place to do this... adding them so template can construct its own API calls... we can build those herein too if preferrable
585 $oTemplate->assign('mailbox', $aMailbox['NAME']);
586 $oTemplate->assign('passed_id', $passed_id);
587 $oTemplate->assign('what', $what);
589 // If Draft folder - create Resume link
590 $resume_draft = $edit_as_new = false;
591 if (($mailbox == $draft_folder) && ($save_as_draft)) {
592 $resume_draft = true; 'smaction_draft';
593 } else if (handleAsSent($mailbox)) {
596 $oTemplate->assign('can_resume_draft', $resume_draft);
597 $oTemplate->assign('can_edit_as_new', $edit_as_new);
599 $oTemplate->assign('mailboxes', sqimap_mailbox_option_array($imapConnection));
600 if (in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true)) {
601 $delete_url = $base_uri . "src/$where";
602 $oTemplate->assign('can_be_deleted', true);
603 $oTemplate->assign('move_delete_form_action', $base_uri.'src/'.$where);
604 $oTemplate->assign('delete_form_extra', addHidden('mailbox', $aMailbox['NAME'])."\n" .
605 addHidden('msg[0]', $passed_id)."\n" .
606 addHidden('startMessage', $startMessage)."\n" );
607 if (!(isset($passed_ent_id) && $passed_ent_id)) {
608 $oTemplate->assign('can_be_moved', true);
609 $oTemplate->assign('move_form_extra', addHidden('mailbox', $aMailbox['NAME'])."\n" .
610 addHidden('msg[0]', $passed_id)."\n" );
611 $oTemplate->assign('last_move_target', isset($lastTargetMailbox) && !empty($lastTargetMailbox) ?
$lastTargetMailbox : '');
612 $oTemplate->assign('can_be_copied', $show_copy_buttons==1);
614 $oTemplate->assign('can_be_moved', false);
615 $oTemplate->assign('move_form_extra', '');
616 $oTemplate->assign('last_move_target', '');
617 $oTemplate->assign('can_be_copied', false);
620 $oTemplate->assign('can_be_deleted', false);
621 $oTemplate->assign('move_delete_form_action', '');
622 $oTemplate->assign('delete_form_extra', '');
623 $oTemplate->assign('can_be_moved', false);
624 $oTemplate->assign('move_form_extra', '');
625 $oTemplate->assign('last_move_target', '');
626 $oTemplate->assign('can_be_copied', false);
630 $oTemplate->display('read_menubar_nav.tpl');
631 $oTemplate->display('read_menubar_buttons.tpl');
633 $oTemplate->display('read_menubar_buttons.tpl');
634 $oTemplate->display('read_menubar_nav.tpl');
638 do_hook('read_body_menu_bottom', $null);
641 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
642 global $base_uri, $where, $what, $show_html_default,
643 $oTemplate, $download_href,
644 $unsafe_image_toggle_href, $unsafe_image_toggle_text;
646 $urlMailbox = urlencode($mailbox);
647 $urlPassed_id = urlencode($passed_id);
648 $urlPassed_ent_id = urlencode($passed_ent_id);
650 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
651 if (!empty($where)) {
652 $query_string .= '&where=' . urlencode($where);
655 $query_string .= '&what=' . urlencode($what);
657 $url = $base_uri.'src/view_header.php?'.$query_string;
660 // Build the printer friend link
662 if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET
) ) {
663 $view_unsafe_images = false;
665 $view_unsafe_images = true;
667 $pf_params = '?passed_ent_id=' . $urlPassed_ent_id .
668 '&mailbox=' . $urlMailbox .
669 '&passed_id=' . $urlPassed_id .
670 '&view_unsafe_images='. (bool) $view_unsafe_images .
671 '&show_html_default=' . $show_html_default;
675 'Text' => _("View Full Header")
679 'Text' => _("View Printable Version")
682 'URL' => $download_href,
683 'Text' => _("Download this as a file")
685 $toggle = html_toggle_href($mailbox, $passed_id, $passed_ent_id, $message);
686 if (!empty($toggle)) {
689 'Text' => $show_html_default==1 ?
_("View as plain text") : _("View as HTML")
692 if (!empty($unsafe_image_toggle_href)) {
694 'URL' => $unsafe_image_toggle_href,
695 'Text' => $unsafe_image_toggle_text
699 do_hook('read_body_header_right', $links);
701 $oTemplate->assign('links', $links);
703 return $oTemplate->fetch('read_toolbar.tpl');
706 /***************************/
707 /* Main of read_body.php */
708 /***************************/
710 /* get the globals we may need */
712 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
713 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
714 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
717 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION
);
718 if (is_array($delayed_errors)) {
719 $oErrorHandler->AssignDelayedErrors($delayed_errors);
720 sqsession_unregister("delayed_errors");
723 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
724 if (!sqgetGlobalVar('where', $where, SQ_GET
) ) {
725 $where = 'right_main.php';
728 * Used as entry key to the list of uid's cached in the mailbox cache
729 * we use the cached uid's to get the next and prev message.
731 if (!sqgetGlobalVar('what', $what, SQ_GET
) ){
734 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
735 $show_more = (int) $temp;
737 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
738 $show_more_cc = (int) $temp;
740 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
741 $show_more_bcc = (int) $temp;
743 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
744 $view_hdr = (int) $temp;
747 if ( sqgetGlobalVar('account', $temp, SQ_GET
) ) {
748 $iAccount = (int) $temp;
754 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
755 sqgetGlobalVar('mailbox', $mailbox);
757 if ( sqgetGlobalVar('passed_id', $temp) ) {
758 $passed_id = (int) $temp;
760 if ( sqgetGlobalVar('sort', $temp) ) {
763 if ( sqgetGlobalVar('startMessage', $temp) ) {
764 $startMessage = (int) $temp;
768 if(sqgetGlobalVar('show_html_default', $temp)) {
769 $show_html_default = (int) $temp;
772 if(sqgetGlobalVar('view_unsafe_images', $temp)) {
773 $view_unsafe_images = (int) $temp;
774 if($view_unsafe_images == 1) {
775 $show_html_default = 1;
778 $view_unsafe_images = 0;
781 * Retrieve mailbox cache
783 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
785 /* end of get globals */
786 global $sqimap_capabilities, $lastTargetMailbox;
788 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
789 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
793 Start code to set the columns to fetch in case of hitting the next/prev link
794 The reason for this is the fact that the cache can be invalidated which means that the headers
795 to fetch aren't there anymore. Before they got calculated when the messagelist was shown.
797 Todo, better central handling of setting the mailbox options so we do not need to do the stuff below
801 * Replace From => To in case it concerns a draft or sent folder
804 if (($mailbox == $sent_folder ||
$mailbox == $draft_folder) &&
805 !in_array(SQM_COL_TO
,$index_order)) {
806 $aNewOrder = array(); // nice var name ;)
807 foreach($index_order as $iCol) {
808 if ($iCol == SQM_COL_FROM
) {
811 $aColumns[$iCol] = array();
814 foreach ($index_order as $iCol) {
815 $aColumns[$iCol] = array();
820 'columns' => $aColumns, // columns bound settings
822 'highlight_list' => $message_highlight_list, // row highlighting rules
823 'trash_folder' => $trash_folder,
824 'sent_folder' => $sent_folder,
825 'draft_folder' => $draft_folder));
827 calcFetchColumns($aMailbox,$aProps);
830 End code to set the columns to fetch in case of hitting the next/prev link
836 * Check if cache is still valid, $what contains the key
837 * which gives us acces to the array with uid's. At this moment
838 * 0 is used for a normal message list and search uses 1 as key. This can be
839 * changed / extended in the future.
840 * If on a select of a mailbox we detect that the cache should be invalidated due to
841 * the delete of messages or due to new messages we empty the list with uid's and
842 * that's what we detect below.
844 if (!is_array($aMailbox['UIDSET'][$what])) {
845 fetchMessageHeaders($imapConnection, $aMailbox);
848 $iSetIndex = $aMailbox['SETINDEX'];
849 $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id;
852 * Update the seen state
853 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
855 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
856 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
860 * Process Delete from delete-move-next
861 * but only if delete_id was set
863 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
864 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
868 * $message contains all information about the message
869 * including header and body
872 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
873 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
874 $FirstTimeSee = !$message->is_seen
;
876 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
877 $FirstTimeSee = !$message->is_seen
;
878 $message->is_seen
= true;
879 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
881 if (isset($passed_ent_id) && $passed_ent_id) {
882 $message = $message->getEntity($passed_ent_id);
883 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
884 $message = $message->parent
;
886 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
887 $rfc822_header = new Rfc822Header();
888 $rfc822_header->parseHeader($read);
889 $message->rfc822_header
= $rfc822_header;
890 } else if ($message->type0
== 'message' && $message->type1
== 'rfc822' && isset($message->entities
[0])) {
891 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE);
892 $rfc822_header = new Rfc822Header();
893 $rfc822_header->parseHeader($read);
894 $message->rfc822_header
= $rfc822_header;
898 $header = $message->header
;
901 /****************************************/
902 /* Block for handling incoming url vars */
903 /****************************************/
905 if (isset($sendreceipt)) {
906 if ( !$message->is_mdnsent
) {
907 $final_recipient = '';
908 if ((isset($identity)) && ($identity != 0)) //Main identity
909 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
910 if ($final_recipient == '' )
911 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
912 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
913 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
914 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
915 $message->is_mdnsent
= true;
916 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
920 /***********************************************/
921 /* End of block for handling incoming url vars */
922 /***********************************************/
925 do_hook('read_body_top', $null);
926 if ($show_html_default == 1) {
927 $ent_ar = $message->findDisplayEntity(array());
929 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
931 $cnt = count($ent_ar);
932 for ($i = 0; $i < $cnt; $i++
) {
933 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
935 $messagebody .= '<hr />';
940 * Write mailbox with updated seen flag information back to cache.
942 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
943 sqsession_register($mailbox_cache,'mailbox_cache');
944 $_SESSION['mailbox_cache'] = $mailbox_cache;
946 displayPageHeader($color, $mailbox,'','');
947 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
948 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
950 $oTemplate->assign('message_body', $messagebody);
951 $oTemplate->display('read_message_body.tpl');
953 formatAttachments($message,$ent_ar,$mailbox, $passed_id);
955 /* show attached images inline -- if pref'fed so */
956 if ($attachment_common_show_images && is_array($attachment_common_show_images_list)) {
958 foreach ($attachment_common_show_images_list as $img) {
959 $imgurl = SM_PATH
. 'src/download.php' .
961 'passed_id=' . urlencode($img['passed_id']) .
962 '&mailbox=' . urlencode($mailbox) .
963 '&ent_id=' . urlencode($img['ent_id']) .
964 '&absolute_dl=true';
966 $a['Name'] = $img['name'];
967 $a['DisplayURL'] = $imgurl;
968 $a['DownloadURL'] = $img['download_href'];
972 $oTemplate->assign('images', $images);
973 $oTemplate->display('read_display_images_inline.tpl');
976 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
978 do_hook('read_body_bottom', $null);
979 sqimap_logout($imapConnection);
980 $oTemplate->display('footer.tpl');