96426d34a85b292f23d58f62d34cb86e70f28ae4
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
12 * @package squirrelmail
15 /** Path for SquirrelMail required files. */
16 define('SM_PATH','../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/global.php');
21 require_once(SM_PATH
. 'functions/imap.php');
22 require_once(SM_PATH
. 'functions/mime.php');
23 require_once(SM_PATH
. 'functions/date.php');
24 require_once(SM_PATH
. 'functions/url_parser.php');
25 require_once(SM_PATH
. 'functions/html.php');
26 require_once(SM_PATH
. 'functions/global.php');
27 require_once(SM_PATH
. 'functions/identity.php');
28 require_once(SM_PATH
. 'functions/mailbox_display.php');
31 * Given an IMAP message id number, this will look it up in the cached
32 * and sorted msgs array and return the index of the next message
34 * @param int $passed_id The current message UID
35 * @return the index of the next valid message from the array
37 function findNextMessage($passed_id) {
38 global $msort, $msgs, $sort,
39 $thread_sort_messages, $allow_server_sort,
41 if (!is_array($server_sort_array)) {
42 $thread_sort_messages = 0;
43 $allow_server_sort = FALSE;
46 if ($thread_sort_messages ||
$allow_server_sort) {
47 $count = count($server_sort_array) - 1;
48 foreach($server_sort_array as $key=>$value) {
49 if ($passed_id == $value) {
53 $result = $server_sort_array[$key +
1];
58 if (is_array($msort)) {
59 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
60 if ($passed_id == $msgs[$key]['ID']) {
64 $result = $msgs[$key]['ID'];
75 * Given an IMAP message id number, this will look it up in the cached
76 * and sorted msgs array and return the index of the previous message
78 * @param int $passed_id The current message UID
79 * @return the index of the next valid message from the array
81 function findPreviousMessage($numMessages, $passed_id) {
82 global $msort, $sort, $msgs,
83 $thread_sort_messages,
84 $allow_server_sort, $server_sort_array;
86 if (!is_array($server_sort_array)) {
87 $thread_sort_messages = 0;
88 $allow_server_sort = FALSE;
90 if ($thread_sort_messages ||
$allow_server_sort ) {
91 foreach($server_sort_array as $key=>$value) {
92 if ($passed_id == $value) {
96 $result = $server_sort_array[$key - 1];
101 if (is_array($msort)) {
102 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
103 if ($passed_id == $msgs[$key]['ID']) {
107 $result = $msgs[$key]['ID'];
118 * Displays a link to a page where the message is displayed more
119 * "printer friendly".
120 * @param string $mailbox Name of current mailbox
121 * @param int $passed_id
123 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
124 global $javascript_on, $color;
126 $params = '?passed_ent_id=' . $passed_ent_id .
127 '&mailbox=' . urlencode($mailbox) .
128 '&passed_id=' . $passed_id;
130 $print_text = _("View Printable Version");
133 /* Output the link. */
134 if ($javascript_on) {
135 $result = '<script language="javascript" type="text/javascript">' . "\n" .
137 " function printFormat() {\n" .
138 ' window.open("../src/printer_friendly_main.php' .
139 $params . '","Print","width=800,height=600");' . "\n".
143 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
145 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
146 "$params\">$print_text</a>\n";
151 function ServerMDNSupport($read) {
152 /* escaping $ doesn't work -> \x36 */
153 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
157 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
158 global $username, $attachment_dir,
159 $version, $attachments, $squirrelmail_language, $default_charset,
160 $languages, $useSendmail, $domain, $sent_folder,
161 $popuser, $data_dir, $username;
163 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
165 $header = $message->rfc822_header
;
166 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
168 $rfc822_header = new Rfc822Header();
169 $content_type = new ContentType('multipart/report');
170 $content_type->properties
['report-type']='disposition-notification';
173 if ($default_charset) {
174 $content_type->properties
['charset']=$default_charset;
176 $rfc822_header->content_type
= $content_type;
177 $rfc822_header->to
[] = $header->dnt
;
178 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
180 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
181 // This merely comes from compose.php and only happens when there is no
182 // email_addr specified in user's identity (which is the startup config)
183 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
184 $popuser = $usernamedata[1];
185 $domain = $usernamedata[2];
186 unset($usernamedata);
188 $popuser = $username;
192 $ident = get_identities();
193 if(!isset($identity)) $identity = 0;
194 $full_name = $ident[$identity]['full_name'];
195 $from_mail = $ident[$identity]['email_address'];
196 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
197 $reply_to = $ident[$identity]['reply_to'];
200 $from_mail = "$popuser@$domain";
201 $from_addr = $from_mail;
203 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
205 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
209 $senton = getLongDateString( $header->date
);
210 $to_array = $header->to
;
212 foreach ($to_array as $line) {
213 $to .= ' '.$line->getAddress();
215 $now = getLongDateString( time() );
217 $body = _("Your message") . "\r\n\r\n" .
218 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
219 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
220 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
222 sprintf( _("Was displayed on %s"), $now );
224 $special_encoding = '';
225 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
226 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
227 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
228 if (strtolower($default_charset) == 'iso-2022-jp') {
229 if (mb_detect_encoding($body) == 'ASCII') {
230 $special_encoding = '8bit';
232 $body = mb_convert_encoding($body, 'JIS');
233 $special_encoding = '7bit';
237 $part1 = new Message();
238 $part1->setBody($body);
239 $mime_header = new MessageHeader
;
240 $mime_header->type0
= 'text';
241 $mime_header->type1
= 'plain';
242 if ($special_encoding) {
243 $mime_header->encoding
= $special_encoding;
245 $mime_header->encoding
= 'us-ascii';
247 if ($default_charset) {
248 $mime_header->parameters
['charset'] = $default_charset;
250 $part1->mime_header
= $mime_header;
253 $original_recipient = $to;
254 $original_message_id = $header->message_id
;
256 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
257 if ($original_recipient != '') {
258 $report .= "Original-Recipient : $original_recipient\r\n";
260 $final_recipient = $sender;
261 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
262 "Original-Message-ID : $original_message_id\r\n" .
263 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
265 $part2 = new Message();
266 $part2->setBody($report);
267 $mime_header = new MessageHeader
;
268 $mime_header->type0
= 'message';
269 $mime_header->type1
= 'disposition-notification';
270 $mime_header->encoding
= 'us-ascii';
271 $part2->mime_header
= $mime_header;
273 $composeMessage = new Message();
274 $composeMessage->rfc822_header
= $rfc822_header;
275 $composeMessage->addEntity($part1);
276 $composeMessage->addEntity($part2);
280 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
281 global $sendmail_path;
282 $deliver = new Deliver_SendMail();
283 $stream = $deliver->initStream($composeMessage,$sendmail_path);
285 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
286 $deliver = new Deliver_SMTP();
287 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
288 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
289 get_smtp_user($user, $pass);
290 $stream = $deliver->initStream($composeMessage,$domain,0,
291 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
295 $length = $deliver->mail($composeMessage, $stream);
296 $success = $deliver->finalizeStream($stream);
299 $msg = $deliver->dlv_msg
. '<br>' .
300 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
301 $deliver->dlv_server_msg
;
302 require_once(SM_PATH
. 'functions/display_messages.php');
303 plain_error_message($msg, $color);
306 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
307 sqimap_append ($imapConnection, $sent_folder, $length);
308 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
309 $imap_deliver = new Deliver_IMAP();
310 $imap_deliver->mail($composeMessage, $imapConnection);
311 sqimap_append_done ($imapConnection);
312 unset ($imap_deliver);
318 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
320 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
321 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
322 $readmessage, $uid_support);
325 function ClearAttachments() {
326 global $username, $attachments, $attachment_dir;
328 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
330 $rem_attachments = array();
331 if (isset($attachments)) {
332 foreach ($attachments as $info) {
333 if ($info['session'] == -1) {
334 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
335 if (file_exists($attached_file)) {
336 unlink($attached_file);
339 $rem_attachments[] = $info;
343 $attachments = $rem_attachments;
346 function formatRecipientString($recipients, $item ) {
347 global $show_more_cc, $show_more, $show_more_bcc,
351 if ((is_array($recipients)) && (isset($recipients[0]))) {
357 $url = set_url_var($PHP_SELF, 'show_more',0);
359 $url = set_url_var($PHP_SELF, 'show_more',1);
361 } else if ($item == 'cc') {
364 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
366 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
368 } else if ($item == 'bcc') {
369 if ($show_more_bcc) {
371 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
373 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
377 $cnt = count($recipients);
378 foreach($recipients as $r) {
379 $add = decodeHeader($r->getAddress(true));
381 $string .= '<BR>' . $add;
385 $string .= ' (<A HREF="'.$url;
387 $string .= '">'._("less").'</A>)';
389 $string .= '">'._("more").'</A>)';
399 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
400 $color, $FirstTimeSee) {
401 global $msn_user_support, $default_use_mdn, $default_use_priority,
402 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
403 $squirrelmail_language;
405 $header = $message->rfc822_header
;
407 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
409 $from_name = $header->getAddr_s('from');
411 $from_name = $header->getAddr_s('sender');
413 $env[_("From")] = _("Unknown sender");
415 $env[_("From")] = decodeHeader($from_name);
416 $env[_("Date")] = getLongDateString($header->date
);
417 $env[_("To")] = formatRecipientString($header->to
, "to");
418 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
419 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
420 if ($default_use_priority) {
421 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
423 if ($show_xmailer_default) {
424 $env[_("Mailer")] = decodeHeader($header->xmailer
);
426 if ($default_use_mdn) {
427 if ($mdn_user_support) {
429 if ($message->is_mdnsent
) {
430 $env[_("Read receipt")] = _("sent");
432 $env[_("Read receipt")] = _("requested");
433 if (!(handleAsSent($mailbox) ||
434 $message->is_deleted ||
436 $mdn_url = $PHP_SELF . '&sendreceipt=1';
437 if ($FirstTimeSee && $javascript_on) {
438 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
439 $script .= '<!--'. "\n";
440 $script .= 'if(window.confirm("' .
441 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
445 $script .= '// -->'. "\n";
446 $script .= '</script>'. "\n";
449 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
450 _("Send read receipt now") . ']</a>';
457 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
458 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
459 foreach ($env as $key => $val) {
462 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
463 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
467 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
468 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
469 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
470 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
472 do_hook('read_body_header');
473 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
475 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
480 * Format message toolbar
482 * @param string $mailbox Name of current mailbox
483 * @param int $passed_id UID of current message
484 * @param int $passed_ent_id Id of entity within message
485 * @param object $message Current message object
486 * @param object $mbx_response
488 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
489 global $base_uri, $draft_folder, $where, $what, $color, $sort,
490 $startMessage, $PHP_SELF, $save_as_draft, $uid_support,
491 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
492 $data_dir, $username, $delete_prev_next_display;
494 $topbar_delimiter = ' | ';
495 $double_delimiter = ' ';
496 $urlMailbox = urlencode($mailbox);
498 $comp_uri = 'src/compose.php' .
499 '?passed_id=' . $passed_id .
500 '&mailbox=' . $urlMailbox .
501 '&startMessage=' . $startMessage .
502 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
504 $msgs_url = $base_uri . 'src/';
506 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
507 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
509 // Create Prev & Next links
510 // Handle nested entities first (i.e. Mime Attach parts)
511 if (isset($passed_ent_id) && $passed_ent_id) {
512 // code for navigating through attached message/rfc822 messages
513 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
515 $entity_count = array();
518 foreach($message->parent
->entities
as $ent) {
519 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
521 $entity_count[$c] = $ent->entity_id
;
522 $entities[$ent->entity_id
] = $c;
526 $prev_link = _("Previous");
527 if($entities[$passed_ent_id] > 1) {
528 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
529 $prev_link = '<a href="'
530 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
531 . '">' . $prev_link . '</a>';
534 $next_link = _("Next");
535 if($entities[$passed_ent_id] < $c) {
536 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
537 $next_link = '<a href="'
538 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
539 . '">' . $next_link . '</a>';
542 $par_ent_id = $message->parent
->entity_id
;
545 $par_ent_id = substr($par_ent_id,0,-2);
546 if ( $par_ent_id != 0 ) {
547 $up_link = $topbar_delimiter;
548 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
549 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
553 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
554 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
556 // Prev/Next links for regular messages
557 } else if ( !(isset($where) && isset($what)) ) {
558 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
559 $next = findNextMessage($passed_id);
561 $prev_link = _("Previous");
563 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
564 '&mailbox='.$urlMailbox.'&sort='.$sort.
565 '&startMessage='.$startMessage.'&show_more=0';
566 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
569 $next_link = _("Next");
571 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
572 '&mailbox='.$urlMailbox.'&sort='.$sort.
573 '&startMessage='.$startMessage.'&show_more=0';
574 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
577 // Only bother with Delete & Prev and Delete & Next IF
578 // we have UID support, and top display is enabled.
579 if ( $uid_support && $delete_prev_next_display == 1 ) {
580 $del_prev_link = _("Delete & Prev");
582 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
583 '&mailbox='.$urlMailbox.'&sort='.$sort.
584 '&startMessage='.$startMessage.'&show_more=0'.
585 '&delete_id='.$passed_id;
586 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
589 $del_next_link = _("Delete & Next");
591 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
592 '&mailbox='.$urlMailbox.'&sort='.$sort.
593 '&startMessage='.$startMessage.'&show_more=0'.
594 '&delete_id='.$passed_id;
595 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
599 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
600 if ( isset($del_prev_link) && isset($del_next_link) )
601 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
604 // Start with Search Results or Message List link.
605 if (isset($where) && isset($what)) {
606 $msgs_url .= 'search.php?where=' . urlencode($where) .
607 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
608 $msgs_str = _("Search Results");
610 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
611 $startMessage . '&mailbox=' . $urlMailbox;
612 $msgs_str = _("Message List");
614 $nav_row .= $double_delimiter .
615 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
617 $nav_row .= '</small></td></tr>';
620 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
621 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
623 // If Draft folder - create Resume link
624 if (($mailbox == $draft_folder) && ($save_as_draft)) {
625 $comp_alt_uri = $comp_uri . '&smaction=draft';
626 $comp_alt_string = _("Resume Draft");
627 } else if (handleAsSent($mailbox)) {
628 // If in Sent folder, edit as new
629 $comp_alt_uri = $comp_uri . '&smaction=edit_as_new';
630 $comp_alt_string = _("Edit Message as New");
633 // Show Alt URI for Draft/Sent
634 if (isset($comp_alt_uri)) {
635 $menu_row .= makeComposeLink($comp_alt_uri, $comp_alt_string);
636 $menu_row .= $topbar_delimiter . "\n";
639 $comp_action_uri = $comp_uri . '&smaction=reply';
640 $menu_row .= makeComposeLink($comp_action_uri, _("Reply")) . "\n";
642 $comp_action_uri = $comp_uri . '&smaction=reply_all';
643 $menu_row .= $topbar_delimiter;
644 $menu_row .= makeComposeLink($comp_action_uri, _("Reply All")) . "\n";
647 $comp_action_uri = $comp_uri . '&smaction=forward';
648 $menu_row .= $topbar_delimiter;
649 $menu_row .= makeComposeLink($comp_action_uri, _("Forward")) . "\n";
651 if ($enable_forward_as_attachment) {
652 $comp_action_uri = $comp_uri . '&smaction=forward_as_attachment';
653 $menu_row .= $topbar_delimiter;
654 $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment")) . "\n";
657 $delete_link = _("Delete");
658 if (!(isset($passed_ent_id) && $passed_ent_id)) {
659 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
660 '&message=' . $passed_id . '&';
662 if ($where && $what) {
663 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
665 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
667 $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
668 $delete_link .= ' (<a href="' . $delete_url.'&bypass_trash=1">'
669 ._("Bypass Trash").'</a>)';
672 $menu_row .= $topbar_delimiter.$delete_link . "\n";
676 $menu_row .= '</small></td><td align="right">';
677 if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
678 // If we have a next message, move, and then go to next.
679 // Otherwise, use move_messages to move, and then return to index.
681 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
683 if ( isset($next) && $next >= 0 ) {
684 $action .= 'src/read_body.php?passed_id='.$next.'&';
686 $action .= 'src/move_messages.php?';
688 $action .= $current_box;
690 $menu_row .= '<form action="'.$action.'" method="post">'.
691 '<small><input type="hidden" name="show_more" value="0" />'.
692 '<input type="hidden" name="msg[0]" value="'.$passed_id.'" />'._("Move to:") .
693 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
695 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
696 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
698 $menu_row .= sqimap_mailbox_option_list($imapConnection);
700 $menu_row .= '</select> ';
702 // If we'll be using move_messages.php, also add location to form
703 if ( !isset($next) ||
$next < 0 ) {
704 $menu_row .= '<input type="hidden" name="location" value="'.$base_uri.'src/right_main.php?'.$current_box.'" />';
707 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
709 $menu_row .= '</td></tr>';
711 // echo rows, with hooks
712 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
713 if (is_array($ret)) {
714 if (isset($ret[0]) && !empty($ret[0])) {
717 if (isset($ret[1]) && !empty($ret[1])) {
721 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
722 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
723 echo '</table>'."\n";
724 do_hook('read_body_menu_bottom');
727 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
730 $urlMailbox = urlencode($mailbox);
731 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER
);
732 $url = $base_uri.'src/view_header.php?'.$query_string;
735 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
736 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
737 '<a href="'.$url.'">'._("View Full Header").'</a>';
739 /* Output the printer friendly link if we are in subtle mode. */
740 $s .= ' | ' .
741 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
743 do_hook("read_body_header_right");
744 $s = "</SMALL></TD>\n" .
750 /***************************/
751 /* Main of read_body.php */
752 /***************************/
754 /* get the globals we may need */
756 sqgetGlobalVar('key', $key, SQ_COOKIE
);
757 sqgetGlobalVar('username', $username, SQ_SESSION
);
758 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
759 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
760 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
762 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
763 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
764 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
765 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
766 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
771 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
772 sqgetGlobalVar('where', $where, SQ_GET
);
773 sqgetGlobalVar('what', $what, SQ_GET
);
774 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
775 $show_more = (int) $temp;
777 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
778 $show_more_cc = (int) $temp;
780 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
781 $show_more_bcc = (int) $temp;
783 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
784 $view_hdr = (int) $temp;
788 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
789 sqgetGlobalVar('mailbox', $mailbox);
791 if ( sqgetGlobalVar('passed_id', $temp) ) {
792 $passed_id = (int) $temp;
794 if ( sqgetGlobalVar('sort', $temp) ) {
797 if ( sqgetGlobalVar('startMessage', $temp) ) {
798 $startMessage = (int) $temp;
801 /* end of get globals */
802 global $uid_support, $sqimap_capabilities, $lastTargetMailbox;
804 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
805 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
808 * Process Delete from delete-move-next
809 * but only if delete_id was set
811 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
812 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
814 sqimap_mailbox_expunge_dmn($delete_id);
818 * Process Move from delete-move-next
819 * but only if move_id and target_mailbox were set
821 if ( sqgetGlobalVar('moveButton', $moveButton, SQ_POST
) &&
822 sqgetGlobalVar('msg', $msg, SQ_POST
) &&
823 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST
) &&
824 is_array($msg) && !empty($msg) ) {
829 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
830 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
832 sqimap_mailbox_expunge_dmn($move_id);
834 if ($targetMailbox != $lastTargetMailbox) {
835 $lastTargetMailbox = $targetMailbox;
836 sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
842 * $message contains all information about the message
843 * including header and body
846 $uidvalidity = $mbx_response['UIDVALIDITY'];
848 if (!isset($messages[$uidvalidity])) {
849 $messages[$uidvalidity] = array();
851 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
852 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
853 $FirstTimeSee = !$message->is_seen
;
854 $message->is_seen
= true;
855 $messages[$uidvalidity][$passed_id] = $message;
857 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
858 $message = $messages[$uidvalidity][$passed_id];
859 $FirstTimeSee = !$message->is_seen
;
862 if (isset($passed_ent_id) && $passed_ent_id) {
863 $message = $message->getEntity($passed_ent_id);
864 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
865 $message = $message->parent
;
867 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
868 $rfc822_header = new Rfc822Header();
869 $rfc822_header->parseHeader($read);
870 $message->rfc822_header
= $rfc822_header;
874 $header = $message->header
;
878 /****************************************/
879 /* Block for handling incoming url vars */
880 /****************************************/
882 if (isset($sendreceipt)) {
883 if ( !$message->is_mdnsent
) {
884 $final_recipient = '';
885 if ((isset($identity)) && ($identity != 0)) //Main identity
886 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
887 if ($final_recipient == '' )
888 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
889 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
890 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
891 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
892 $message->is_mdnsent
= true;
893 $messages[$uidvalidity][$passed_id]=$message;
898 /***********************************************/
899 /* End of block for handling incoming url vars */
900 /***********************************************/
902 $msgs[$passed_id]['FLAG_SEEN'] = true;
905 do_hook('read_body_top');
906 if ($show_html_default == 1) {
907 $ent_ar = $message->findDisplayEntity(array());
909 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
911 $cnt = count($ent_ar);
912 for ($i = 0; $i < $cnt; $i++
) {
913 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
915 $messagebody .= '<hr noshade size=1>';
919 displayPageHeader($color, $mailbox);
920 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
921 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
922 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
924 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
926 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
927 echo ' <tr bgcolor="'.$color[4].'"><td>';
928 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
929 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
930 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
934 echo ' </table></td></tr>';
938 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
939 $color[4].'"></TD></TR>'."\n";
941 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
942 if ($attachmentsdisplay) {
944 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
946 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
947 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
948 echo ' <b>' . _("Attachments") . ':</b>';
951 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
952 echo $attachmentsdisplay;
953 echo ' </td></tr></table>';
954 echo ' </td></tr></table>';
956 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
957 $color[4].'"></TD></TR>';
961 /* show attached images inline -- if pref'fed so */
962 if (($attachment_common_show_images) &&
963 is_array($attachment_common_show_images_list)) {
964 foreach ($attachment_common_show_images_list as $img) {
965 $imgurl = SM_PATH
. 'src/download.php' .
967 'passed_id=' . urlencode($img['passed_id']) .
968 '&mailbox=' . urlencode($mailbox) .
969 '&ent_id=' . urlencode($img['ent_id']) .
970 '&absolute_dl=true';
972 echo html_tag( 'table', "\n" .
973 html_tag( 'tr', "\n" .
974 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
977 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
981 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
983 do_hook('read_body_bottom');
984 do_hook('html_bottom');
985 sqimap_logout($imapConnection);
986 /* sessions are written at the end of the script. it's better to register
987 them at the end so we avoid double session_register calls */
988 sqsession_register($messages,'messages');