5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
12 * @package squirrelmail
16 * Path for SquirrelMail required files.
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/global.php');
24 require_once(SM_PATH
. 'functions/imap.php');
25 require_once(SM_PATH
. 'functions/mime.php');
26 require_once(SM_PATH
. 'functions/date.php');
27 require_once(SM_PATH
. 'functions/url_parser.php');
28 require_once(SM_PATH
. 'functions/html.php');
29 require_once(SM_PATH
. 'functions/global.php');
30 require_once(SM_PATH
. 'functions/identity.php');
31 require_once(SM_PATH
. 'functions/mailbox_display.php');
34 * Given an IMAP message id number, this will look it up in the cached
35 * and sorted msgs array and return the index of the next message
37 * @param int $passed_id The current message UID
38 * @return the index of the next valid message from the array
40 function findNextMessage($passed_id) {
41 global $msort, $msgs, $sort,
42 $thread_sort_messages, $allow_server_sort,
44 if (!is_array($server_sort_array)) {
45 $thread_sort_messages = 0;
46 $allow_server_sort = FALSE;
49 if ($thread_sort_messages ||
$allow_server_sort) {
50 $count = count($server_sort_array) - 1;
51 foreach($server_sort_array as $key=>$value) {
52 if ($passed_id == $value) {
56 $result = $server_sort_array[$key +
1];
61 if (is_array($msort)) {
62 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
63 if ($passed_id == $msgs[$key]['ID']) {
67 $result = $msgs[$key]['ID'];
78 * Given an IMAP message id number, this will look it up in the cached
79 * and sorted msgs array and return the index of the previous message
81 * @param int $passed_id The current message UID
82 * @return the index of the next valid message from the array
84 function findPreviousMessage($numMessages, $passed_id) {
85 global $msort, $sort, $msgs,
86 $thread_sort_messages,
87 $allow_server_sort, $server_sort_array;
89 if (!is_array($server_sort_array)) {
90 $thread_sort_messages = 0;
91 $allow_server_sort = FALSE;
93 if ($thread_sort_messages ||
$allow_server_sort ) {
94 foreach($server_sort_array as $key=>$value) {
95 if ($passed_id == $value) {
97 $result = $server_sort_array[$key - 1];
103 if (is_array($msort)) {
104 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
105 if ($passed_id == $msgs[$key]['ID']) {
109 $result = $msgs[$key]['ID'];
120 * Displays a link to a page where the message is displayed more
121 * "printer friendly".
122 * @param string $mailbox Name of current mailbox
123 * @param int $passed_id
125 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
126 global $javascript_on, $color;
128 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
129 '&mailbox=' . urlencode($mailbox) .
130 '&passed_id=' . urlencode($passed_id);
132 $print_text = _("View Printable Version");
135 /* Output the link. */
136 if ($javascript_on) {
137 $result = '<script language="javascript" type="text/javascript">' . "\n" .
139 " function printFormat() {\n" .
140 ' window.open("../src/printer_friendly_main.php' .
141 $params . '","Print","width=800,height=600");' . "\n".
145 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
147 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
148 "$params\">$print_text</a>\n";
153 function ServerMDNSupport($aFlags) {
154 /* escaping $ doesn't work -> \x36 */
155 return (array_search('$mdnsent',$aFlags,true) !== false ||
156 array_search('\\*',$aFlags,true) !== false) ?
true : false;
157 //$ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
161 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
162 global $username, $attachment_dir,
163 $version, $attachments, $squirrelmail_language, $default_charset,
164 $languages, $useSendmail, $domain, $sent_folder,
165 $popuser, $data_dir, $username;
167 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
169 $header = $message->rfc822_header
;
170 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
172 $rfc822_header = new Rfc822Header();
173 $content_type = new ContentType('multipart/report');
174 $content_type->properties
['report-type']='disposition-notification';
177 if ($default_charset) {
178 $content_type->properties
['charset']=$default_charset;
180 $rfc822_header->content_type
= $content_type;
181 $rfc822_header->to
[] = $header->dnt
;
182 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
184 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
185 // This merely comes from compose.php and only happens when there is no
186 // email_addr specified in user's identity (which is the startup config)
187 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
188 $popuser = $usernamedata[1];
189 $domain = $usernamedata[2];
190 unset($usernamedata);
192 $popuser = $username;
196 $ident = get_identities();
197 if(!isset($identity)) $identity = 0;
198 $full_name = $ident[$identity]['full_name'];
199 $from_mail = $ident[$identity]['email_address'];
200 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
201 $reply_to = $ident[$identity]['reply_to'];
204 $from_mail = "$popuser@$domain";
205 $from_addr = $from_mail;
207 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
209 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
213 $senton = getLongDateString( $header->date
);
214 $to_array = $header->to
;
216 foreach ($to_array as $line) {
217 $to .= ' '.$line->getAddress();
219 $now = getLongDateString( time() );
221 $body = _("Your message") . "\r\n\r\n" .
222 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
223 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
224 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
226 sprintf( _("Was displayed on %s"), $now );
228 $special_encoding = '';
229 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
230 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
231 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
232 if (strtolower($default_charset) == 'iso-2022-jp') {
233 if (mb_detect_encoding($body) == 'ASCII') {
234 $special_encoding = '8bit';
236 $body = mb_convert_encoding($body, 'JIS');
237 $special_encoding = '7bit';
241 $part1 = new Message();
242 $part1->setBody($body);
243 $mime_header = new MessageHeader
;
244 $mime_header->type0
= 'text';
245 $mime_header->type1
= 'plain';
246 if ($special_encoding) {
247 $mime_header->encoding
= $special_encoding;
249 $mime_header->encoding
= 'us-ascii';
251 if ($default_charset) {
252 $mime_header->parameters
['charset'] = $default_charset;
254 $part1->mime_header
= $mime_header;
257 $original_recipient = $to;
258 $original_message_id = $header->message_id
;
260 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
261 if ($original_recipient != '') {
262 $report .= "Original-Recipient : $original_recipient\r\n";
264 $final_recipient = $sender;
265 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
266 "Original-Message-ID : $original_message_id\r\n" .
267 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
269 $part2 = new Message();
270 $part2->setBody($report);
271 $mime_header = new MessageHeader
;
272 $mime_header->type0
= 'message';
273 $mime_header->type1
= 'disposition-notification';
274 $mime_header->encoding
= 'us-ascii';
275 $part2->mime_header
= $mime_header;
277 $composeMessage = new Message();
278 $composeMessage->rfc822_header
= $rfc822_header;
279 $composeMessage->addEntity($part1);
280 $composeMessage->addEntity($part2);
284 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
285 global $sendmail_path;
286 $deliver = new Deliver_SendMail();
287 $stream = $deliver->initStream($composeMessage,$sendmail_path);
289 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
290 $deliver = new Deliver_SMTP();
291 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
292 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
293 get_smtp_user($user, $pass);
294 $stream = $deliver->initStream($composeMessage,$domain,0,
295 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
299 $length = $deliver->mail($composeMessage, $stream);
300 $success = $deliver->finalizeStream($stream);
303 $msg = $deliver->dlv_msg
. '<br>' .
304 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
305 $deliver->dlv_server_msg
;
306 require_once(SM_PATH
. 'functions/display_messages.php');
307 plain_error_message($msg, $color);
310 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
311 sqimap_append ($imapConnection, $sent_folder, $length);
312 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
313 $imap_deliver = new Deliver_IMAP();
314 $imap_deliver->mail($composeMessage, $imapConnection);
315 sqimap_append_done ($imapConnection);
316 unset ($imap_deliver);
322 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
324 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
325 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
329 function ClearAttachments() {
330 global $username, $attachments, $attachment_dir;
332 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
334 $rem_attachments = array();
335 if (isset($attachments)) {
336 foreach ($attachments as $info) {
337 if ($info['session'] == -1) {
338 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
339 if (file_exists($attached_file)) {
340 unlink($attached_file);
343 $rem_attachments[] = $info;
347 $attachments = $rem_attachments;
350 function formatRecipientString($recipients, $item ) {
351 global $show_more_cc, $show_more, $show_more_bcc,
355 if ((is_array($recipients)) && (isset($recipients[0]))) {
361 $url = set_url_var($PHP_SELF, 'show_more',0);
363 $url = set_url_var($PHP_SELF, 'show_more',1);
365 } else if ($item == 'cc') {
368 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
370 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
372 } else if ($item == 'bcc') {
373 if ($show_more_bcc) {
375 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
377 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
381 $cnt = count($recipients);
382 foreach($recipients as $r) {
383 $add = decodeHeader($r->getAddress(true));
385 $string .= '<BR>' . $add;
389 $string .= ' (<A HREF="'.$url;
391 $string .= '">'._("less").'</A>)';
393 $string .= '">'._("more").'</A>)';
403 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
404 $color, $FirstTimeSee) {
405 global $msn_user_support, $default_use_mdn, $default_use_priority,
406 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
407 $squirrelmail_language;
409 $header = $message->rfc822_header
;
411 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
413 $from_name = $header->getAddr_s('from');
415 $from_name = $header->getAddr_s('sender');
417 $env[_("From")] = _("Unknown sender");
419 $env[_("From")] = decodeHeader($from_name);
420 $env[_("Date")] = getLongDateString($header->date
);
421 $env[_("To")] = formatRecipientString($header->to
, "to");
422 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
423 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
424 if ($default_use_priority) {
425 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
427 if ($show_xmailer_default) {
428 $env[_("Mailer")] = decodeHeader($header->xmailer
);
430 if ($default_use_mdn) {
431 if ($mdn_user_support) {
433 if ($message->is_mdnsent
) {
434 $env[_("Read receipt")] = _("sent");
436 $env[_("Read receipt")] = _("requested");
437 if (!(handleAsSent($mailbox) ||
438 $message->is_deleted ||
440 $mdn_url = $PHP_SELF . '&sendreceipt=1';
441 if ($FirstTimeSee && $javascript_on) {
442 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
443 $script .= '<!--'. "\n";
444 $script .= 'if(window.confirm("' .
445 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
449 $script .= '// -->'. "\n";
450 $script .= '</script>'. "\n";
453 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
454 _("Send read receipt now") . ']</a>';
461 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
462 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
463 foreach ($env as $key => $val) {
466 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
467 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
471 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
472 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
473 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
474 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
476 do_hook('read_body_header');
477 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
479 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
484 * Format message toolbar
486 * @param string $mailbox Name of current mailbox
487 * @param int $passed_id UID of current message
488 * @param int $passed_ent_id Id of entity within message
489 * @param object $message Current message object
490 * @param object $mbx_response
492 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
493 global $base_uri, $draft_folder, $where, $what, $color, $sort,
494 $startMessage, $PHP_SELF, $save_as_draft,
495 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
496 $data_dir, $username, $delete_prev_next_display,
497 $compose_new_win, $javascript_on;
499 $topbar_delimiter = ' | ';
500 $double_delimiter = ' ';
501 $urlMailbox = urlencode($mailbox);
503 $msgs_url = $base_uri . 'src/';
505 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
506 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
508 // Create Prev & Next links
509 // Handle nested entities first (i.e. Mime Attach parts)
510 if (isset($passed_ent_id) && $passed_ent_id) {
511 // code for navigating through attached message/rfc822 messages
512 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
514 $entity_count = array();
517 foreach($message->parent
->entities
as $ent) {
518 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
520 $entity_count[$c] = $ent->entity_id
;
521 $entities[$ent->entity_id
] = $c;
525 $prev_link = _("Previous");
526 if($entities[$passed_ent_id] > 1) {
527 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
528 $prev_link = '<a href="'
529 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
530 . '">' . $prev_link . '</a>';
533 $next_link = _("Next");
534 if($entities[$passed_ent_id] < $c) {
535 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
536 $next_link = '<a href="'
537 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
538 . '">' . $next_link . '</a>';
541 $par_ent_id = $message->parent
->entity_id
;
544 $par_ent_id = substr($par_ent_id,0,-2);
545 if ( $par_ent_id != 0 ) {
546 $up_link = $topbar_delimiter;
547 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
548 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
552 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
553 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
555 // Prev/Next links for regular messages
556 } else if ( !(isset($where) && isset($what)) ) {
557 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
558 $next = findNextMessage($passed_id);
560 $prev_link = _("Previous");
562 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
563 '&mailbox='.$urlMailbox.'&sort='.$sort.
564 '&startMessage='.$startMessage.'&show_more=0';
565 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
568 $next_link = _("Next");
570 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
571 '&mailbox='.$urlMailbox.'&sort='.$sort.
572 '&startMessage='.$startMessage.'&show_more=0';
573 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
576 // Only bother with Delete & Prev and Delete & Next IF
577 // top display is enabled.
578 if ( $delete_prev_next_display == 1 &&
579 array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
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>';
622 $comp_uri = $base_uri.'src/compose.php' .
623 '?passed_id=' . $passed_id .
624 '&mailbox=' . $urlMailbox .
625 '&startMessage=' . $startMessage .
626 (isset($passed_ent_id) ?
'&passed_ent_id='.$passed_ent_id : '');
628 // Start form for reply/reply all/forward..
631 $method='method="post" ';
632 if ($compose_new_win == '1') {
633 if ( $javascript_on ) {
634 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
635 $comp_uri = 'javascript:void(0)';
636 $method='method="get" ';
638 $target = 'target="_blank"';
642 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
644 // If Draft folder - create Resume link
645 if (($mailbox == $draft_folder) && ($save_as_draft)) {
646 $new_button = 'smaction_draft';
647 $comp_alt_string = _("Resume Draft");
648 } else if (handleAsSent($mailbox)) {
649 // If in Sent folder, edit as new
650 $new_button = 'smaction_edit_new';
651 $comp_alt_string = _("Edit Message as New");
653 // Show Alt URI for Draft/Sent
654 if (isset($comp_alt_string))
655 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
657 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
658 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
659 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
660 if ($enable_forward_as_attachment)
661 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .' '."\n";
663 $menu_row .= '</form> ';
665 if (array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
667 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
668 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
670 if (!(isset($passed_ent_id) && $passed_ent_id)) {
671 $menu_row .= addHidden('message', $passed_id);
673 if ($where && $what) {
674 $menu_row .= addHidden('where', $where);
675 $menu_row .= addHidden('what', $what);
677 $menu_row .= addHidden('sort', $sort);
678 $menu_row .= addHidden('startMessage', $startMessage);
680 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
681 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
684 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
686 $menu_row .= '</form>';
690 $menu_row .= '</small></td><td align="right">';
691 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
692 array_search('\\deleted', $mbx_response['PERMANENTFLAGS'],true) !== false) {
694 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
696 // Set subsequent location based on whether or not there is a 'next' message.
697 if ( isset($next) && $next >= 0 ) {
698 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
699 } elseif (isset($prev) && $prev >= 0) {
700 $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
702 $location = $base_uri . 'src/right_main.php?';
705 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
707 addHidden('show_more', '0' ).
708 addHidden('dmn', '1').
709 addHidden('location', $location.$current_box).
710 addHidden('msg[0]', $passed_id) . _("Move to:") .
711 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
713 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
714 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
716 $menu_row .= sqimap_mailbox_option_list($imapConnection);
718 $menu_row .= '</select> ';
720 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
722 $menu_row .= '</td></tr>';
724 // echo rows, with hooks
725 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
726 if (is_array($ret)) {
727 if (isset($ret[0]) && !empty($ret[0])) {
730 if (isset($ret[1]) && !empty($ret[1])) {
734 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
735 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
736 echo '</table>'."\n";
737 do_hook('read_body_menu_bottom');
740 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
741 global $base_uri, $where, $what;
743 $urlMailbox = urlencode($mailbox);
744 $urlPassed_id = urlencode($passed_id);
745 $urlPassed_ent_id = urlencode($passed_ent_id);
747 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
749 if (!empty($where)) {
750 $query_string .= '&where=' . urlencode($where);
754 $query_string .= '&what=' . urlencode($what);
757 $url = $base_uri.'src/view_header.php?'.$query_string;
760 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
761 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
762 '<a href="'.$url.'">'._("View Full Header").'</a>';
764 /* Output the printer friendly link if we are in subtle mode. */
765 $s .= ' | ' .
766 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
768 do_hook("read_body_header_right");
769 $s = "</SMALL></TD>\n" .
775 /***************************/
776 /* Main of read_body.php */
777 /***************************/
779 /* get the globals we may need */
781 sqgetGlobalVar('key', $key, SQ_COOKIE
);
782 sqgetGlobalVar('username', $username, SQ_SESSION
);
783 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
784 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
785 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
787 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
788 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
789 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
790 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
791 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
796 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
797 sqgetGlobalVar('where', $where, SQ_GET
);
798 sqgetGlobalVar('what', $what, SQ_GET
);
799 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
800 $show_more = (int) $temp;
802 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
803 $show_more_cc = (int) $temp;
805 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
806 $show_more_bcc = (int) $temp;
808 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
809 $view_hdr = (int) $temp;
813 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
814 sqgetGlobalVar('mailbox', $mailbox);
816 if ( sqgetGlobalVar('passed_id', $temp) ) {
817 $passed_id = (int) $temp;
819 if ( sqgetGlobalVar('sort', $temp) ) {
822 if ( sqgetGlobalVar('startMessage', $temp) ) {
823 $startMessage = (int) $temp;
826 /* end of get globals */
827 global $sqimap_capabilities, $lastTargetMailbox;
829 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
830 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
833 * Process Delete from delete-move-next
834 * but only if delete_id was set
836 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
837 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
838 sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
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]) ||
$delete_id) {
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, TRUE);
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);
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');