7e12373efcb5c20c50b35f2441a3ecbf61c26708
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($uidset,$passed_id='backwards') {
41 if ($passed_id=='backwards' ||
!is_array($uidset)) { // check for backwards compattibilty gpg plugin
43 sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION
);
44 $uidset = $server_sort_array;
47 $count = count($uidset) - 1;
48 foreach($uidset as $key=>$value) {
49 if ($passed_id == $value) {
53 $result = $uidset[$key +
1];
61 * Given an IMAP message id number, this will look it up in the cached
62 * and sorted msgs array and return the index of the previous message
64 * @param int $passed_id The current message UID
65 * @return the index of the next valid message from the array
68 function findPreviousMessage($uidset, $passed_id) {
69 if (!is_array($uidset)) { //obsolete check
70 sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION
);
71 $uidset = $server_sort_array;
74 foreach($uidset as $key=>$value) {
75 if ($passed_id == $value) {
77 $result = $uidset[$key - 1];
87 * Displays a link to a page where the message is displayed more
89 * @param string $mailbox Name of current mailbox
90 * @param int $passed_id
92 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
93 global $javascript_on, $color;
95 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
96 '&mailbox=' . urlencode($mailbox) .
97 '&passed_id=' . urlencode($passed_id);
99 $print_text = _("View Printable Version");
102 /* Output the link. */
103 if ($javascript_on) {
104 $result = '<script language="javascript" type="text/javascript">' . "\n" .
106 " function printFormat() {\n" .
107 ' window.open("../src/printer_friendly_main.php' .
108 $params . '","Print","width=800,height=600");' . "\n".
112 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
114 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
115 "$params\">$print_text</a>\n";
120 function ServerMDNSupport($aFlags) {
121 /* escaping $ doesn't work -> \x36 */
122 return ( in_array('$mdnsent',$aFlags,true) ||
123 in_array('\\*',$aFlags,true) ) ;
126 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
127 global $username, $attachment_dir,
128 $version, $attachments, $squirrelmail_language, $default_charset,
129 $languages, $useSendmail, $domain, $sent_folder,
130 $popuser, $data_dir, $username;
132 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
134 $header = $message->rfc822_header
;
135 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
137 $rfc822_header = new Rfc822Header();
138 $content_type = new ContentType('multipart/report');
139 $content_type->properties
['report-type']='disposition-notification';
142 if ($default_charset) {
143 $content_type->properties
['charset']=$default_charset;
145 $rfc822_header->content_type
= $content_type;
146 $rfc822_header->to
[] = $header->dnt
;
147 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
149 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
150 // This merely comes from compose.php and only happens when there is no
151 // email_addr specified in user's identity (which is the startup config)
152 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
153 $popuser = $usernamedata[1];
154 $domain = $usernamedata[2];
155 unset($usernamedata);
157 $popuser = $username;
161 $ident = get_identities();
162 if(!isset($identity)) $identity = 0;
163 $full_name = $ident[$identity]['full_name'];
164 $from_mail = $ident[$identity]['email_address'];
165 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
166 $reply_to = $ident[$identity]['reply_to'];
169 $from_mail = "$popuser@$domain";
170 $from_addr = $from_mail;
172 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
174 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
178 $senton = getLongDateString( $header->date
);
179 $to_array = $header->to
;
181 foreach ($to_array as $line) {
182 $to .= ' '.$line->getAddress();
184 $now = getLongDateString( time() );
186 $body = _("Your message") . "\r\n\r\n" .
187 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
188 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
189 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
191 sprintf( _("Was displayed on %s"), $now );
193 $special_encoding = '';
194 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
195 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
196 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
197 if (strtolower($default_charset) == 'iso-2022-jp') {
198 if (mb_detect_encoding($body) == 'ASCII') {
199 $special_encoding = '8bit';
201 $body = mb_convert_encoding($body, 'JIS');
202 $special_encoding = '7bit';
206 $part1 = new Message();
207 $part1->setBody($body);
208 $mime_header = new MessageHeader
;
209 $mime_header->type0
= 'text';
210 $mime_header->type1
= 'plain';
211 if ($special_encoding) {
212 $mime_header->encoding
= $special_encoding;
214 $mime_header->encoding
= 'us-ascii';
216 if ($default_charset) {
217 $mime_header->parameters
['charset'] = $default_charset;
219 $part1->mime_header
= $mime_header;
222 $original_recipient = $to;
223 $original_message_id = $header->message_id
;
225 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
226 if ($original_recipient != '') {
227 $report .= "Original-Recipient : $original_recipient\r\n";
229 $final_recipient = $sender;
230 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
231 "Original-Message-ID : $original_message_id\r\n" .
232 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
234 $part2 = new Message();
235 $part2->setBody($report);
236 $mime_header = new MessageHeader
;
237 $mime_header->type0
= 'message';
238 $mime_header->type1
= 'disposition-notification';
239 $mime_header->encoding
= 'us-ascii';
240 $part2->mime_header
= $mime_header;
242 $composeMessage = new Message();
243 $composeMessage->rfc822_header
= $rfc822_header;
244 $composeMessage->addEntity($part1);
245 $composeMessage->addEntity($part2);
249 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
250 global $sendmail_path;
251 $deliver = new Deliver_SendMail();
252 $stream = $deliver->initStream($composeMessage,$sendmail_path);
254 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
255 $deliver = new Deliver_SMTP();
256 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
257 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
258 get_smtp_user($user, $pass);
259 $stream = $deliver->initStream($composeMessage,$domain,0,
260 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
264 $length = $deliver->mail($composeMessage, $stream);
265 $success = $deliver->finalizeStream($stream);
268 $msg = $deliver->dlv_msg
. '<br>' .
269 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
270 $deliver->dlv_server_msg
;
271 require_once(SM_PATH
. 'functions/display_messages.php');
272 plain_error_message($msg, $color);
275 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
276 sqimap_append ($imapConnection, $sent_folder, $length);
277 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
278 $imap_deliver = new Deliver_IMAP();
279 $imap_deliver->mail($composeMessage, $imapConnection);
280 sqimap_append_done ($imapConnection);
281 unset ($imap_deliver);
287 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
289 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
290 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
294 function ClearAttachments() {
295 global $username, $attachments, $attachment_dir;
297 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
299 $rem_attachments = array();
300 if (isset($attachments)) {
301 foreach ($attachments as $info) {
302 if ($info['session'] == -1) {
303 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
304 if (file_exists($attached_file)) {
305 unlink($attached_file);
308 $rem_attachments[] = $info;
312 $attachments = $rem_attachments;
315 function formatRecipientString($recipients, $item ) {
316 global $show_more_cc, $show_more, $show_more_bcc,
320 if ((is_array($recipients)) && (isset($recipients[0]))) {
326 $url = set_url_var($PHP_SELF, 'show_more',0);
328 $url = set_url_var($PHP_SELF, 'show_more',1);
330 } else if ($item == 'cc') {
333 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
335 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
337 } else if ($item == 'bcc') {
338 if ($show_more_bcc) {
340 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
342 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
346 $cnt = count($recipients);
347 foreach($recipients as $r) {
348 $add = decodeHeader($r->getAddress(true));
350 $string .= '<BR>' . $add;
354 $string .= ' (<A HREF="'.$url;
356 $string .= '">'._("less").'</A>)';
358 $string .= '">'._("more").'</A>)';
368 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
369 $color, $FirstTimeSee) {
370 global $msn_user_support, $default_use_mdn, $default_use_priority,
371 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
372 $squirrelmail_language;
374 $mailbox = $aMailbox['NAME'] ;
376 $header = $message->rfc822_header
;
378 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
380 $from_name = $header->getAddr_s('from');
382 $from_name = $header->getAddr_s('sender');
384 $env[_("From")] = _("Unknown sender");
386 $env[_("From")] = decodeHeader($from_name);
387 $env[_("Date")] = getLongDateString($header->date
);
388 $env[_("To")] = formatRecipientString($header->to
, "to");
389 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
390 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
391 if ($default_use_priority) {
392 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
394 if ($show_xmailer_default) {
395 $env[_("Mailer")] = decodeHeader($header->xmailer
);
397 if ($default_use_mdn) {
398 if ($mdn_user_support) {
400 if ($message->is_mdnsent
) {
401 $env[_("Read receipt")] = _("sent");
403 $env[_("Read receipt")] = _("requested");
404 if (!(handleAsSent($mailbox) ||
405 $message->is_deleted ||
407 $mdn_url = $PHP_SELF . '&sendreceipt=1';
408 if ($FirstTimeSee && $javascript_on) {
409 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
410 $script .= '<!--'. "\n";
411 $script .= 'if(window.confirm("' .
412 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
416 $script .= '// -->'. "\n";
417 $script .= '</script>'. "\n";
420 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
421 _("Send read receipt now") . ']</a>';
428 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
429 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
430 foreach ($env as $key => $val) {
433 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
434 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
438 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
439 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
440 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
441 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
443 do_hook('read_body_header');
444 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
446 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
451 * Format message toolbar
453 * @param string $mailbox Name of current mailbox
454 * @param int $passed_id UID of current message
455 * @param int $passed_ent_id Id of entity within message
456 * @param object $message Current message object
457 * @param object $mbx_response
459 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
460 global $base_uri, $draft_folder, $where, $what, $color, $sort,
461 $startMessage, $PHP_SELF, $save_as_draft,
462 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
463 $data_dir, $username, $delete_prev_next_display,
464 $compose_new_win, $javascript_on;
466 //FIXME cleanup argument list, use $aMailbox where possible
467 $mailbox = $aMailbox['NAME'];
469 $topbar_delimiter = ' | ';
470 $double_delimiter = ' ';
471 $urlMailbox = urlencode($mailbox);
473 $msgs_url = $base_uri . 'src/';
475 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
476 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
478 // Create Prev & Next links
479 // Handle nested entities first (i.e. Mime Attach parts)
480 if (isset($passed_ent_id) && $passed_ent_id) {
481 // code for navigating through attached message/rfc822 messages
482 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
484 $entity_count = array();
487 foreach($message->parent
->entities
as $ent) {
488 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
490 $entity_count[$c] = $ent->entity_id
;
491 $entities[$ent->entity_id
] = $c;
495 $prev_link = _("Previous");
496 if($entities[$passed_ent_id] > 1) {
497 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
498 $prev_link = '<a href="'
499 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
500 . '">' . $prev_link . '</a>';
503 $next_link = _("Next");
504 if($entities[$passed_ent_id] < $c) {
505 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
506 $next_link = '<a href="'
507 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
508 . '">' . $next_link . '</a>';
511 $par_ent_id = $message->parent
->entity_id
;
514 $par_ent_id = substr($par_ent_id,0,-2);
515 if ( $par_ent_id != 0 ) {
516 $up_link = $topbar_delimiter;
517 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
518 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
522 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
523 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
525 // Prev/Next links for regular messages
526 } else if ( !(isset($where) && isset($what)) ) {
527 $prev = findPreviousMessage($aMailbox['UIDSET'], $passed_id);
528 $next = findNextMessage($aMailbox['UIDSET'],$passed_id);
530 $prev_link = _("Previous");
532 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
533 '&mailbox='.$urlMailbox.'&sort='.$sort.
534 '&startMessage='.$startMessage.'&show_more=0';
535 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
538 $next_link = _("Next");
540 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
541 '&mailbox='.$urlMailbox.'&sort='.$sort.
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', $mbx_response['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 '&delete_id='.$passed_id;
556 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
559 $del_next_link = _("Delete & Next");
561 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
562 '&mailbox='.$urlMailbox.'&sort='.$sort.
563 '&startMessage='.$startMessage.'&show_more=0'.
564 '&delete_id='.$passed_id;
565 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
569 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
570 if ( isset($del_prev_link) && isset($del_next_link) )
571 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
574 // Start with Search Results or Message List link.
575 if (isset($where) && isset($what)) {
576 $msgs_url .= 'search.php?where=' . urlencode($where) .
577 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
578 $msgs_str = _("Search Results");
580 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
581 $startMessage . '&mailbox=' . $urlMailbox;
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[9].'"><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" ';
602 if ($compose_new_win == '1') {
603 if ( $javascript_on ) {
604 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
605 $comp_uri = 'javascript:void(0)';
606 $method='method="get" ';
608 $target = 'target="_blank"';
612 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
614 // If Draft folder - create Resume link
615 if (($mailbox == $draft_folder) && ($save_as_draft)) {
616 $new_button = 'smaction_draft';
617 $comp_alt_string = _("Resume Draft");
618 } else if (handleAsSent($mailbox)) {
619 // If in Sent folder, edit as new
620 $new_button = 'smaction_edit_new';
621 $comp_alt_string = _("Edit Message as New");
623 // Show Alt URI for Draft/Sent
624 if (isset($comp_alt_string))
625 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
627 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
628 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
629 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
630 if ($enable_forward_as_attachment)
631 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .' '."\n";
633 $menu_row .= '</form> ';
635 if ( in_array('\\deleted', $mbx_response['PERMANENTFLAGS'],true) ) {
637 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
638 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
640 if (!(isset($passed_ent_id) && $passed_ent_id)) {
641 $menu_row .= addHidden('message', $passed_id);
643 if ($where && $what) {
644 $menu_row .= addHidden('where', $where);
645 $menu_row .= addHidden('what', $what);
647 $menu_row .= addHidden('sort', $sort);
648 $menu_row .= addHidden('startMessage', $startMessage);
650 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
651 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
654 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
656 $menu_row .= '</form>';
660 $menu_row .= '</small></td><td align="right">';
661 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
662 in_array('\\deleted', $mbx_response['PERMANENTFLAGS'],true) ) {
664 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
666 // Set subsequent location based on whether or not there is a 'next' message.
667 if ( isset($next) && $next >= 0 ) {
668 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
669 } elseif (isset($prev) && $prev >= 0) {
670 $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
672 $location = $base_uri . 'src/right_main.php?';
675 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
677 addHidden('show_more', '0' ).
678 addHidden('dmn', '1').
679 addHidden('location', $location.$current_box).
680 addHidden('msg[0]', $passed_id) . _("Move to:") .
681 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
683 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
684 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
686 $menu_row .= sqimap_mailbox_option_list($imapConnection);
688 $menu_row .= '</select> ';
690 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
692 $menu_row .= '</td></tr>';
694 // echo rows, with hooks
695 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
696 if (is_array($ret)) {
697 if (isset($ret[0]) && !empty($ret[0])) {
700 if (isset($ret[1]) && !empty($ret[1])) {
704 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
705 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
706 echo '</table>'."\n";
707 do_hook('read_body_menu_bottom');
710 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
711 global $base_uri, $where, $what;
713 $urlMailbox = urlencode($mailbox);
714 $urlPassed_id = urlencode($passed_id);
715 $urlPassed_ent_id = urlencode($passed_ent_id);
717 $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id;
719 if (!empty($where)) {
720 $query_string .= '&where=' . urlencode($where);
724 $query_string .= '&what=' . urlencode($what);
727 $url = $base_uri.'src/view_header.php?'.$query_string;
730 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
731 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
732 '<a href="'.$url.'">'._("View Full Header").'</a>';
734 /* Output the printer friendly link if we are in subtle mode. */
735 $s .= ' | ' .
736 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
738 do_hook("read_body_header_right");
739 $s = "</SMALL></TD>\n" .
745 /***************************/
746 /* Main of read_body.php */
747 /***************************/
749 /* get the globals we may need */
751 sqgetGlobalVar('key', $key, SQ_COOKIE
);
752 sqgetGlobalVar('username', $username, SQ_SESSION
);
753 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
754 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
755 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
757 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
758 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
759 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
760 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
761 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
766 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
767 sqgetGlobalVar('where', $where, SQ_GET
);
768 sqgetGlobalVar('what', $what, SQ_GET
);
769 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
770 $show_more = (int) $temp;
772 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
773 $show_more_cc = (int) $temp;
775 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
776 $show_more_bcc = (int) $temp;
778 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
779 $view_hdr = (int) $temp;
783 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
784 sqgetGlobalVar('mailbox', $mailbox);
786 if ( sqgetGlobalVar('passed_id', $temp) ) {
787 $passed_id = (int) $temp;
789 if ( sqgetGlobalVar('sort', $temp) ) {
792 if ( sqgetGlobalVar('startMessage', $temp) ) {
793 $startMessage = (int) $temp;
796 /* end of get globals */
797 global $sqimap_capabilities, $lastTargetMailbox;
799 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
800 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
802 global $allow_thread_sort, $auto_expunge;
804 if ($allow_thread_sort && getPref($data_dir, $username, "thread_$mailbox",0)) {
805 $aMailbox['SORT_METHOD'] = 'THREAD';
806 } else if ($allow_server_sort) {
807 $aMailbox['SORT_METHOD'] = 'SERVER';
809 $aMailbox['SORT_METHOD'] = 'SQUIRREL';
811 sqgetGlobalVar('aLastSelectedMailbox',$aMailbox,SQ_SESSION
);
812 $aMailbox['UIDSET'] = $server_sort_array;
813 $aMailbox['SORT'] = $sort;
814 $aMailbox['NAME'] = $mailbox;
815 $aMailbox['EXISTS'] = $mbx_response['EXISTS'];
816 $aMailbox['AUTO_EXPUNGE'] = $auto_expunge;
817 $aMailbox['MSG_HEADERS'] = $msgs;
821 * Process Delete from delete-move-next
822 * but only if delete_id was set
824 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
825 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
826 sqimap_mailbox_expunge_dmn($imapConnection,$aMailbox,$delete_id);
830 * $message contains all information about the message
831 * including header and body
834 $uidvalidity = $mbx_response['UIDVALIDITY'];
836 if (!isset($messages[$uidvalidity])) {
837 $messages[$uidvalidity] = array();
839 if (!isset($messages[$uidvalidity][$passed_id]) ||
$delete_id) {
840 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
841 $FirstTimeSee = !$message->is_seen
;
842 $message->is_seen
= true;
843 $messages[$uidvalidity][$passed_id] = $message;
845 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
846 $message = $messages[$uidvalidity][$passed_id];
847 $FirstTimeSee = !$message->is_seen
;
850 if (isset($passed_ent_id) && $passed_ent_id) {
851 $message = $message->getEntity($passed_ent_id);
852 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
853 $message = $message->parent
;
855 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
856 $rfc822_header = new Rfc822Header();
857 $rfc822_header->parseHeader($read);
858 $message->rfc822_header
= $rfc822_header;
862 $header = $message->header
;
866 /****************************************/
867 /* Block for handling incoming url vars */
868 /****************************************/
870 if (isset($sendreceipt)) {
871 if ( !$message->is_mdnsent
) {
872 $final_recipient = '';
873 if ((isset($identity)) && ($identity != 0)) //Main identity
874 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
875 if ($final_recipient == '' )
876 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
877 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
878 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
879 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
880 $message->is_mdnsent
= true;
881 $messages[$uidvalidity][$passed_id]=$message;
886 /***********************************************/
887 /* End of block for handling incoming url vars */
888 /***********************************************/
890 $msgs[$passed_id]['FLAG_SEEN'] = true;
893 do_hook('read_body_top');
894 if ($show_html_default == 1) {
895 $ent_ar = $message->findDisplayEntity(array());
897 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
899 $cnt = count($ent_ar);
900 for ($i = 0; $i < $cnt; $i++
) {
901 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
903 $messagebody .= '<hr noshade size=1>';
907 displayPageHeader($color, $mailbox);
908 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
909 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
910 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
912 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
914 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
915 echo ' <tr bgcolor="'.$color[4].'"><td>';
916 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
917 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
918 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
922 echo ' </table></td></tr>';
926 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
927 $color[4].'"></TD></TR>'."\n";
929 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
930 if ($attachmentsdisplay) {
932 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
934 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
935 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
936 echo ' <b>' . _("Attachments") . ':</b>';
939 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
940 echo $attachmentsdisplay;
941 echo ' </td></tr></table>';
942 echo ' </td></tr></table>';
944 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
945 $color[4].'"></TD></TR>';
949 /* show attached images inline -- if pref'fed so */
950 if (($attachment_common_show_images) &&
951 is_array($attachment_common_show_images_list)) {
952 foreach ($attachment_common_show_images_list as $img) {
953 $imgurl = SM_PATH
. 'src/download.php' .
955 'passed_id=' . urlencode($img['passed_id']) .
956 '&mailbox=' . urlencode($mailbox) .
957 '&ent_id=' . urlencode($img['ent_id']) .
958 '&absolute_dl=true';
960 echo html_tag( 'table', "\n" .
961 html_tag( 'tr', "\n" .
962 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
965 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
969 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
971 do_hook('read_body_bottom');
972 do_hook('html_bottom');
973 sqimap_logout($imapConnection);
974 /* sessions are written at the end of the script. it's better to register
975 them at the end so we avoid double session_register calls */
976 sqsession_register($messages,'messages');