6 * Copyright (c) 1999-2005 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 include_once(SM_PATH
. 'functions/arrays.php');
33 require_once(SM_PATH
. 'functions/mailbox_display.php');
36 * Given an IMAP message id number, this will look it up in the cached
37 * and sorted msgs array and return the index of the next message
39 * @param int $passed_id The current message UID
40 * @return the index of the next valid message from the array
42 function findNextMessage($uidset,$passed_id='backwards') {
43 if (!is_array($uidset)) {
46 if ($passed_id=='backwards' ||
!is_array($uidset)) { // check for backwards compattibilty gpg plugin
49 $result = sqm_array_get_value_by_offset($uidset,$passed_id,1);
50 if ($result === false) {
58 * Given an IMAP message id number, this will look it up in the cached
59 * and sorted msgs array and return the index of the previous message
61 * @param int $passed_id The current message UID
62 * @return the index of the next valid message from the array
65 function findPreviousMessage($uidset, $passed_id) {
66 if (!is_array($uidset)) {
69 $result = sqm_array_get_value_by_offset($uidset,$passed_id,-1);
70 if ($result === false) {
78 * Displays a link to a page where the message is displayed more
80 * @param string $mailbox Name of current mailbox
81 * @param int $passed_id
83 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
84 global $javascript_on;
87 if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET
) ) {
88 $view_unsafe_images = false;
90 $view_unsafe_images = true;
92 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
93 '&mailbox=' . urlencode($mailbox) .
94 '&passed_id=' . urlencode($passed_id).
95 '&view_unsafe_images='. (bool) $view_unsafe_images;
97 $print_text = _("View Printable Version");
100 /* Output the link. */
101 if ($javascript_on) {
102 $result = '<script language="javascript" type="text/javascript">' . "\n" .
104 " function printFormat() {\n" .
105 ' window.open("../src/printer_friendly_main.php' .
106 $params . '","Print","width=800,height=600");' . "\n".
110 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
112 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
113 "$params\">$print_text</a>\n";
118 function ServerMDNSupport($aFlags) {
119 /* escaping $ doesn't work -> \x36 */
120 return ( in_array('$mdnsent',$aFlags,true) ||
121 in_array('\\*',$aFlags,true) ) ;
124 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
125 global $username, $attachment_dir, $popuser, $username, $color,
126 $version, $squirrelmail_language, $default_charset,
127 $languages, $useSendmail, $domain, $sent_folder;
129 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
131 $header = $message->rfc822_header
;
133 $rfc822_header = new Rfc822Header();
134 $content_type = new ContentType('multipart/report');
135 $content_type->properties
['report-type']='disposition-notification';
138 if ($default_charset) {
139 $content_type->properties
['charset']=$default_charset;
141 $rfc822_header->content_type
= $content_type;
142 $rfc822_header->to
[] = $header->dnt
;
143 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
145 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
146 // This merely comes from compose.php and only happens when there is no
147 // email_addr specified in user's identity (which is the startup config)
148 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
149 $popuser = $usernamedata[1];
150 $domain = $usernamedata[2];
151 unset($usernamedata);
153 $popuser = $username;
157 $ident = get_identities();
158 if(!isset($identity)) $identity = 0;
159 $full_name = $ident[$identity]['full_name'];
160 $from_mail = $ident[$identity]['email_address'];
161 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
162 $reply_to = $ident[$identity]['reply_to'];
165 $from_mail = "$popuser@$domain";
166 $from_addr = $from_mail;
168 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
170 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
174 $senton = getLongDateString( $header->date
);
175 $to_array = $header->to
;
177 foreach ($to_array as $line) {
178 $to .= ' '.$line->getAddress();
180 $now = getLongDateString( time() );
182 $body = _("Your message") . "\r\n\r\n" .
183 "\t" . _("To") . ': ' . decodeHeader($to,false,false) . "\r\n" .
184 "\t" . _("Subject") . ': ' . decodeHeader($header->subject
,false,false) . "\r\n" .
185 "\t" . _("Sent") . ': ' . $senton . "\r\n" .
187 sprintf( _("Was displayed on %s"), $now );
189 $special_encoding = '';
190 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
191 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
192 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body);
193 if (strtolower($default_charset) == 'iso-2022-jp') {
194 if (mb_detect_encoding($body) == 'ASCII') {
195 $special_encoding = '8bit';
197 $body = mb_convert_encoding($body, 'JIS');
198 $special_encoding = '7bit';
201 } elseif (sq_is8bit($body)) {
202 $special_encoding = '8bit';
204 $part1 = new Message();
205 $part1->setBody($body);
206 $mime_header = new MessageHeader
;
207 $mime_header->type0
= 'text';
208 $mime_header->type1
= 'plain';
209 if ($special_encoding) {
210 $mime_header->encoding
= $special_encoding;
212 $mime_header->encoding
= 'us-ascii';
214 if ($default_charset) {
215 $mime_header->parameters
['charset'] = $default_charset;
217 $part1->mime_header
= $mime_header;
220 $original_recipient = $to;
221 $original_message_id = $header->message_id
;
223 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
224 if ($original_recipient != '') {
225 $report .= "Original-Recipient : $original_recipient\r\n";
227 $final_recipient = $sender;
228 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
229 "Original-Message-ID : $original_message_id\r\n" .
230 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
232 $part2 = new Message();
233 $part2->setBody($report);
234 $mime_header = new MessageHeader
;
235 $mime_header->type0
= 'message';
236 $mime_header->type1
= 'disposition-notification';
237 $mime_header->encoding
= 'us-ascii';
238 $part2->mime_header
= $mime_header;
240 $composeMessage = new Message();
241 $composeMessage->rfc822_header
= $rfc822_header;
242 $composeMessage->addEntity($part1);
243 $composeMessage->addEntity($part2);
247 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
248 global $sendmail_path;
249 $deliver = new Deliver_SendMail();
250 $stream = $deliver->initStream($composeMessage,$sendmail_path);
252 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
253 $deliver = new Deliver_SMTP();
254 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
255 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
256 get_smtp_user($user, $pass);
257 $stream = $deliver->initStream($composeMessage,$domain,0,
258 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
262 $length = $deliver->mail($composeMessage, $stream);
263 $success = $deliver->finalizeStream($stream);
266 $msg = $deliver->dlv_msg
. '<br />' .
267 _("Server replied:") . ' ' . $deliver->dlv_ret_nr
. ' ' .
268 $deliver->dlv_server_msg
;
269 require_once(SM_PATH
. 'functions/display_messages.php');
270 plain_error_message($msg, $color);
273 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
274 sqimap_append ($imapConnection, $sent_folder, $length);
275 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
276 $imap_deliver = new Deliver_IMAP();
277 $imap_deliver->mail($composeMessage, $imapConnection);
278 sqimap_append_done ($imapConnection);
279 unset ($imap_deliver);
285 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
287 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
288 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
292 function ClearAttachments() {
293 global $username, $attachments, $attachment_dir;
295 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
297 $rem_attachments = array();
298 if (isset($attachments)) {
299 foreach ($attachments as $info) {
300 if ($info['session'] == -1) {
301 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
302 if (file_exists($attached_file)) {
303 unlink($attached_file);
306 $rem_attachments[] = $info;
310 $attachments = $rem_attachments;
313 function formatRecipientString($recipients, $item ) {
314 global $show_more_cc, $show_more, $show_more_bcc,
318 if ((is_array($recipients)) && (isset($recipients[0]))) {
324 $url = set_url_var($PHP_SELF, 'show_more',0);
326 $url = set_url_var($PHP_SELF, 'show_more',1);
328 } else if ($item == 'cc') {
331 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
333 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
335 } else if ($item == 'bcc') {
336 if ($show_more_bcc) {
338 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
340 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
344 $cnt = count($recipients);
345 foreach($recipients as $r) {
346 $add = decodeHeader($r->getAddress(true));
348 $string .= '<br />' . $add;
352 $string .= ' (<a href="'.$url;
354 $string .= '">'._("less").'</a>)';
356 $string .= '">'._("more").'</a>)';
366 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
367 $color, $FirstTimeSee) {
368 global $default_use_mdn, $default_use_priority,
369 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
370 $squirrelmail_language;
372 $mailbox = $aMailbox['NAME'];
374 $header = $message->rfc822_header
;
376 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
378 $from_name = $header->getAddr_s('from');
380 $from_name = $header->getAddr_s('sender');
382 $env[_("From")] = _("Unknown sender");
384 $env[_("From")] = decodeHeader($from_name);
385 $env[_("Date")] = getLongDateString($header->date
);
386 $env[_("To")] = formatRecipientString($header->to
, "to");
387 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
388 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
389 if ($default_use_priority) {
390 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
392 if ($show_xmailer_default) {
393 $env[_("Mailer")] = decodeHeader($header->xmailer
);
395 if ($default_use_mdn) {
396 if ($mdn_user_support) {
398 if ($message->is_mdnsent
) {
399 $env[_("Read receipt")] = _("sent");
401 $env[_("Read receipt")] = _("requested");
402 if (!(handleAsSent($mailbox) ||
403 $message->is_deleted ||
405 $mdn_url = $PHP_SELF . '&sendreceipt=1';
406 if ($FirstTimeSee && $javascript_on) {
407 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
408 $script .= '<!--'. "\n";
409 $script .= 'if(window.confirm("' .
410 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
414 $script .= '// -->'. "\n";
415 $script .= '</script>'. "\n";
418 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
419 _("Send read receipt now") . ']</a>';
426 $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
427 $s .= ' align="center" bgcolor="'.$color[0].'">';
428 foreach ($env as $key => $val) {
431 $s .= html_tag('td', '<b>' . $key . ': </b>', 'right', '', 'valign="top" width="20%"') . "\n";
432 $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
436 echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
437 ' cellspacing="0" border="0" align="center">'."\n";
438 echo '<tr><td height="5" colspan="2" bgcolor="'.
439 $color[4].'"></td></tr><tr><td align="center">'."\n";
441 do_hook('read_body_header');
442 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
444 echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
449 * Format message toolbar
451 * @param string $mailbox Name of current mailbox
452 * @param int $passed_id UID of current message
453 * @param int $passed_ent_id Id of entity within message
454 * @param object $message Current message object
455 * @param object $mbx_response
457 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
458 global $base_uri, $draft_folder, $where, $what, $color, $sort,
459 $startMessage, $PHP_SELF, $save_as_draft,
460 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
461 $username, $delete_prev_next_display,
462 $compose_new_win, $javascript_on, $compose_width, $compose_height;
464 //FIXME cleanup argument list, use $aMailbox where possible
465 $mailbox = $aMailbox['NAME'];
467 $topbar_delimiter = ' | ';
468 $double_delimiter = ' ';
469 $urlMailbox = urlencode($mailbox);
471 $msgs_url = $base_uri . 'src/';
473 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
474 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
476 // Create Prev & Next links
477 // Handle nested entities first (i.e. Mime Attach parts)
478 if (isset($passed_ent_id) && $passed_ent_id) {
479 // code for navigating through attached message/rfc822 messages
480 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
482 $entity_count = array();
485 foreach($message->parent
->entities
as $ent) {
486 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
488 $entity_count[$c] = $ent->entity_id
;
489 $entities[$ent->entity_id
] = $c;
493 $prev_link = _("Previous");
494 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] > 1) {
495 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
496 $prev_link = '<a href="'
497 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
498 . '">' . $prev_link . '</a>';
501 $next_link = _("Next");
502 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] < $c) {
503 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
504 $next_link = '<a href="'
505 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
506 . '">' . $next_link . '</a>';
509 $par_ent_id = $message->parent
->entity_id
;
512 $par_ent_id = substr($par_ent_id,0,-2);
513 if ( $par_ent_id != 0 ) {
514 $up_link = $topbar_delimiter;
515 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
516 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
520 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
521 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
523 // Prev/Next links for regular messages
524 } else if ( true ) { //!(isset($where) && isset($what)) ) {
525 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
526 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
528 $prev_link = _("Previous");
530 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
531 '&mailbox='.$urlMailbox.'&sort='.$sort.
532 "&where=$where&what=$what" .
533 '&startMessage='.$startMessage.'&show_more=0';
534 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
537 $next_link = _("Next");
539 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
540 '&mailbox='.$urlMailbox.'&sort='.$sort.
541 "&where=$where&what=$what" .
542 '&startMessage='.$startMessage.'&show_more=0';
543 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
546 // Only bother with Delete & Prev and Delete & Next IF
547 // top display is enabled.
548 if ( $delete_prev_next_display == 1 &&
549 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
550 $del_prev_link = _("Delete & Prev");
552 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
553 '&mailbox='.$urlMailbox.'&sort='.$sort.
554 '&startMessage='.$startMessage.'&show_more=0'.
555 "&where=$where&what=$what" .
556 '&delete_id='.$passed_id;
557 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
560 $del_next_link = _("Delete & Next");
562 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
563 '&mailbox='.$urlMailbox.'&sort='.$sort.
564 '&startMessage='.$startMessage.'&show_more=0'.
565 "&where=$where&what=$what" .
566 '&delete_id='.$passed_id;
567 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
571 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
572 if ( isset($del_prev_link) && isset($del_next_link) )
573 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
576 // Start with Search Results or Message List link.
577 $msgs_url .= "$where?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
578 "&startMessage=$startMessage";
579 if ($where == 'search.php') {
580 $msgs_str = _("Search Results");
582 $msgs_str = _("Message List");
584 $nav_row .= $double_delimiter .
585 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
587 $nav_row .= '</small></td></tr>';
590 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
591 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
592 $comp_uri = $base_uri.'src/compose.php' .
593 '?passed_id=' . $passed_id .
594 '&mailbox=' . $urlMailbox .
595 '&startMessage=' . $startMessage .
596 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
598 // Start form for reply/reply all/forward..
601 $method='method="post" ';
603 if ($compose_new_win == '1') {
604 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
605 $compose_width = '640';
607 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
608 $compose_height = '550';
610 if ( $javascript_on ) {
611 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"';
612 $comp_uri = 'javascript:void(0)';
613 $method='method="get" ';
614 $onsubmit = 'onsubmit="return false" ';
616 $target = 'target="_blank"';
620 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '
621 . $method.$target.$onsubmit.' style="display: inline">'."\n";
623 // If Draft folder - create Resume link
624 if (($mailbox == $draft_folder) && ($save_as_draft)) {
625 $new_button = 'smaction_draft';
626 $comp_alt_string = _("Resume Draft");
627 } else if (handleAsSent($mailbox)) {
628 // If in Sent folder, edit as new
629 $new_button = 'smaction_edit_new';
630 $comp_alt_string = _("Edit Message as New");
632 // Show Alt URI for Draft/Sent
633 if (isset($comp_alt_string))
634 $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n";
636 $menu_row .= getButton('submit', 'smaction_reply', _("Reply"), $on_click) . "\n";
637 $menu_row .= getButton('submit', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
638 $menu_row .= getButton('submit', 'smaction_forward', _("Forward"), $on_click);
639 if ($enable_forward_as_attachment)
640 $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .' '."\n";
642 $menu_row .= '</form> ';
644 if ( in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
645 // Form for deletion. Form is handled by the originating display in $where. This is right_main.php or search.php
646 $delete_url = $base_uri . "src/$where";
647 $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">';
649 if (!(isset($passed_ent_id) && $passed_ent_id)) {
650 $menu_row .= addHidden('mailbox', $aMailbox['NAME']);
651 $menu_row .= addHidden('msg[0]', $passed_id);
652 $menu_row .= addHidden('startMessage', $startMessage);
653 $menu_row .= getButton('submit', 'delete', _("Delete"));
654 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
656 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
659 $menu_row .= '</form>';
663 $menu_row .= '</small></td><td align="right">';
664 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
665 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
667 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
670 addHidden('mailbox',$aMailbox['NAME']) .
671 addHidden('msg[0]', $passed_id) . _("Move to:") .
672 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
674 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
675 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
677 $menu_row .= sqimap_mailbox_option_list($imapConnection);
679 $menu_row .= '</select> ';
681 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
683 $menu_row .= '</td></tr>';
685 // echo rows, with hooks
686 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
687 if (is_array($ret)) {
688 if (isset($ret[0]) && !empty($ret[0])) {
691 if (isset($ret[1]) && !empty($ret[1])) {
695 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
696 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
697 echo '</table>'."\n";
698 do_hook('read_body_menu_bottom');
701 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
702 global $base_uri, $where, $what;
704 $urlMailbox = urlencode($mailbox);
705 $urlPassed_id = urlencode($passed_id);
706 $urlPassed_ent_id = urlencode($passed_ent_id);
708 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
710 if (!empty($where)) {
711 $query_string .= '&where=' . urlencode($where);
715 $query_string .= '&what=' . urlencode($what);
718 $url = $base_uri.'src/view_header.php?'.$query_string;
721 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ": </b></td>\n" .
722 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
723 '<a href="'.$url.'">'._("View Full Header").'</a>';
725 /* Output the printer friendly link if we are in subtle mode. */
726 $s .= ' | ' .
727 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
729 do_hook("read_body_header_right");
730 $s = "</small></td>\n" .
739 * @deprecated see form functions available in 1.5.1 and 1.4.3.
740 * @param string $type
741 * @param string $name
742 * @param string $value
744 * @param bool $enabled
746 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
747 $disabled = ( $enabled ?
'' : 'disabled ' );
748 $js = ( $js ?
$js.' ' : '' );
749 return '<input '.$disabled.$js.
753 '" style="padding: 0px; margin: 0px" />';
757 /***************************/
758 /* Main of read_body.php */
759 /***************************/
761 /* get the globals we may need */
763 sqgetGlobalVar('key', $key, SQ_COOKIE
);
764 sqgetGlobalVar('username', $username, SQ_SESSION
);
765 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
766 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
767 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
768 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
769 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
774 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
775 if (!sqgetGlobalVar('where', $where, SQ_GET
) ) {
776 $where = 'right_main.php';
779 * Used as entry key to the list of uid's cached in the mailbox cache
780 * we use the cached uid's to get the next and prev message.
782 if (!sqgetGlobalVar('what', $what, SQ_GET
) ){
785 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
786 $show_more = (int) $temp;
788 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
789 $show_more_cc = (int) $temp;
791 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
792 $show_more_bcc = (int) $temp;
794 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
795 $view_hdr = (int) $temp;
798 if ( sqgetGlobalVar('account', $temp, SQ_GET
) ) {
799 $iAccount = (int) $temp;
805 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
806 sqgetGlobalVar('mailbox', $mailbox);
808 if ( sqgetGlobalVar('passed_id', $temp) ) {
809 $passed_id = (int) $temp;
811 if ( sqgetGlobalVar('sort', $temp) ) {
814 if ( sqgetGlobalVar('startMessage', $temp) ) {
815 $startMessage = (int) $temp;
820 * Retrieve mailbox cache
822 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION
);
824 /* end of get globals */
825 global $sqimap_capabilities, $lastTargetMailbox;
827 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
828 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
831 * Check if cache is still valid, $what contains the key
832 * which gives us acces to the array with uid's. At this moment
833 * 0 is used for a normal message list and search uses 1 as key. This can be
834 * changed / extended in the future.
835 * If on a select of a mailbox we detect that the cache should be invalidated due to
836 * the delete of messages or due to new messages we empty the list with uid's and
837 * that's what we detect below.
839 if (!is_array($aMailbox['UIDSET'][$what])) {
840 fetchMessageHeaders($imapConnection, $aMailbox);
843 $iSetIndex = $aMailbox['SETINDEX'];
844 $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id;
847 * Update the seen state
848 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
850 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
851 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
855 * Process Delete from delete-move-next
856 * but only if delete_id was set
858 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
859 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
863 * $message contains all information about the message
864 * including header and body
867 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
868 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
869 $FirstTimeSee = !$message->is_seen
;
871 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
872 $FirstTimeSee = !$message->is_seen
;
873 $message->is_seen
= true;
874 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
877 if (isset($passed_ent_id) && $passed_ent_id) {
878 $message = $message->getEntity($passed_ent_id);
879 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
880 $message = $message->parent
;
882 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
883 $rfc822_header = new Rfc822Header();
884 $rfc822_header->parseHeader($read);
885 $message->rfc822_header
= $rfc822_header;
886 } else if ($message->type0
== 'message' && $message->type1
== 'rfc822' && isset($message->entities
[0])) {
887 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE);
888 $rfc822_header = new Rfc822Header();
889 $rfc822_header->parseHeader($read);
890 $message->rfc822_header
= $rfc822_header;
894 $header = $message->header
;
896 $header = $message->header
;
899 /****************************************/
900 /* Block for handling incoming url vars */
901 /****************************************/
903 if (isset($sendreceipt)) {
904 if ( !$message->is_mdnsent
) {
905 $final_recipient = '';
906 if ((isset($identity)) && ($identity != 0)) //Main identity
907 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
908 if ($final_recipient == '' )
909 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
910 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
911 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
912 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
913 $message->is_mdnsent
= true;
914 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
919 /***********************************************/
920 /* End of block for handling incoming url vars */
921 /***********************************************/
926 do_hook('read_body_top');
927 if ($show_html_default == 1) {
928 $ent_ar = $message->findDisplayEntity(array());
930 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
932 $cnt = count($ent_ar);
933 for ($i = 0; $i < $cnt; $i++
) {
934 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
936 $messagebody .= '<hr style="height: 1px;" />';
940 displayPageHeader($color, $mailbox);
941 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
942 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
943 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
945 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
947 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
948 echo ' <tr bgcolor="'.$color[4].'"><td>';
949 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
950 echo html_tag( 'table' ,'' , 'left', '', 'width="100%" cellpadding="1" cellspacing="5" border="0"' );
951 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
955 echo ' </table></td></tr>';
959 echo '<tr><td height="5" colspan="2" bgcolor="'.
960 $color[4].'"></td></tr>'."\n";
962 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
963 if ($attachmentsdisplay) {
965 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
967 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
968 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
969 echo ' <b>' . _("Attachments") . ':</b>';
972 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
973 echo $attachmentsdisplay;
974 echo ' </td></tr></table>';
975 echo ' </td></tr></table>';
977 echo '<tr><td height="5" colspan="2" bgcolor="'.
978 $color[4].'"></td></tr>';
982 /* show attached images inline -- if pref'fed so */
983 if (($attachment_common_show_images) &&
984 is_array($attachment_common_show_images_list)) {
985 foreach ($attachment_common_show_images_list as $img) {
986 $imgurl = SM_PATH
. 'src/download.php' .
988 'passed_id=' . urlencode($img['passed_id']) .
989 '&mailbox=' . urlencode($mailbox) .
990 '&ent_id=' . urlencode($img['ent_id']) .
991 '&absolute_dl=true';
993 echo html_tag( 'table', "\n" .
994 html_tag( 'tr', "\n" .
995 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
998 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
1002 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
1004 do_hook('read_body_bottom');
1005 sqimap_logout($imapConnection);
1008 * Write mailbox with updated seen flag information back to cache.
1010 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1011 sqsession_register($mailbox_cache,'mailbox_cache');