6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
13 * @package squirrelmail
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'include/validate.php');
21 require_once(SM_PATH
. 'functions/global.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/mime.php');
24 require_once(SM_PATH
. 'functions/date.php');
25 require_once(SM_PATH
. 'functions/url_parser.php');
26 require_once(SM_PATH
. 'functions/html.php');
27 require_once(SM_PATH
. 'functions/global.php');
28 require_once(SM_PATH
. 'functions/identity.php');
29 require_once(SM_PATH
. 'functions/mailbox_display.php');
32 * Given an IMAP message id number, this will look it up in the cached
33 * and sorted msgs array and return the index of the next message
35 * @param int $passed_id The current message UID
36 * @return the index of the next valid message from the array
38 function findNextMessage($passed_id) {
39 global $msort, $msgs, $sort,
40 $thread_sort_messages, $allow_server_sort,
42 if (!is_array($server_sort_array)) {
43 $thread_sort_messages = 0;
44 $allow_server_sort = FALSE;
47 if ($thread_sort_messages ||
$allow_server_sort) {
48 $count = count($server_sort_array) - 1;
49 foreach($server_sort_array as $key=>$value) {
50 if ($passed_id == $value) {
54 $result = $server_sort_array[$key +
1];
59 if (is_array($msort)) {
60 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
61 if ($passed_id == $msgs[$key]['ID']) {
65 $result = $msgs[$key]['ID'];
76 * Given an IMAP message id number, this will look it up in the cached
77 * and sorted msgs array and return the index of the previous message
79 * @param int $passed_id The current message UID
80 * @return the index of the next valid message from the array
82 function findPreviousMessage($numMessages, $passed_id) {
83 global $msort, $sort, $msgs,
84 $thread_sort_messages,
85 $allow_server_sort, $server_sort_array;
87 if (!is_array($server_sort_array)) {
88 $thread_sort_messages = 0;
89 $allow_server_sort = FALSE;
91 if ($thread_sort_messages ||
$allow_server_sort ) {
92 foreach($server_sort_array as $key=>$value) {
93 if ($passed_id == $value) {
97 $result = $server_sort_array[$key - 1];
102 if (is_array($msort)) {
103 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
104 if ($passed_id == $msgs[$key]['ID']) {
108 $result = $msgs[$key]['ID'];
119 * Displays a link to a page where the message is displayed more
120 * "printer friendly".
121 * @param string $mailbox Name of current mailbox
122 * @param int $passed_id
124 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
125 global $javascript_on, $color;
127 $params = '?passed_ent_id=' . $passed_ent_id .
128 '&mailbox=' . urlencode($mailbox) .
129 '&passed_id=' . $passed_id;
131 $print_text = _("View Printable Version");
134 /* Output the link. */
135 if ($javascript_on) {
136 $result = '<script language="javascript" type="text/javascript">' . "\n" .
138 " function printFormat() {\n" .
139 ' window.open("../src/printer_friendly_main.php' .
140 $params . '","Print","width=800,height=600");' . "\n".
144 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
146 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
147 "$params\">$print_text</a>\n";
152 function ServerMDNSupport($read) {
153 /* escaping $ doesn't work -> \x36 */
154 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
158 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
159 global $username, $attachment_dir,
160 $version, $attachments, $squirrelmail_language, $default_charset,
161 $languages, $useSendmail, $domain, $sent_folder,
162 $popuser, $data_dir, $username;
164 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
166 $header = $message->rfc822_header
;
167 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169 $rfc822_header = new Rfc822Header();
170 $content_type = new ContentType('multipart/report');
171 $content_type->properties
['report-type']='disposition-notification';
174 if ($default_charset) {
175 $content_type->properties
['charset']=$default_charset;
177 $rfc822_header->content_type
= $content_type;
178 $rfc822_header->to
[] = $header->dnt
;
179 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
181 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
182 // This merely comes from compose.php and only happens when there is no
183 // email_addr specified in user's identity (which is the startup config)
184 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
185 $popuser = $usernamedata[1];
186 $domain = $usernamedata[2];
187 unset($usernamedata);
189 $popuser = $username;
193 $ident = get_identities();
194 if(!isset($identity)) $identity = 0;
195 $full_name = $ident[$identity]['full_name'];
196 $from_mail = $ident[$identity]['email_address'];
197 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
198 $reply_to = $ident[$identity]['reply_to'];
201 $from_mail = "$popuser@$domain";
202 $from_addr = $from_mail;
204 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
206 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
210 $senton = getLongDateString( $header->date
);
211 $to_array = $header->to
;
213 foreach ($to_array as $line) {
214 $to .= ' '.$line->getAddress();
216 $now = getLongDateString( time() );
218 $body = _("Your message") . "\r\n\r\n" .
219 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
220 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
221 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
223 sprintf( _("Was displayed on %s"), $now );
225 $special_encoding = '';
226 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
227 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
228 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
229 if (strtolower($default_charset) == 'iso-2022-jp') {
230 if (mb_detect_encoding($body) == 'ASCII') {
231 $special_encoding = '8bit';
233 $body = mb_convert_encoding($body, 'JIS');
234 $special_encoding = '7bit';
238 $part1 = new Message();
239 $part1->setBody($body);
240 $mime_header = new MessageHeader
;
241 $mime_header->type0
= 'text';
242 $mime_header->type1
= 'plain';
243 if ($special_encoding) {
244 $mime_header->encoding
= $special_encoding;
246 $mime_header->encoding
= 'us-ascii';
248 if ($default_charset) {
249 $mime_header->parameters
['charset'] = $default_charset;
251 $part1->mime_header
= $mime_header;
254 $original_recipient = $to;
255 $original_message_id = $header->message_id
;
257 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
258 if ($original_recipient != '') {
259 $report .= "Original-Recipient : $original_recipient\r\n";
261 $final_recipient = $sender;
262 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
263 "Original-Message-ID : $original_message_id\r\n" .
264 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
266 $part2 = new Message();
267 $part2->setBody($report);
268 $mime_header = new MessageHeader
;
269 $mime_header->type0
= 'message';
270 $mime_header->type1
= 'disposition-notification';
271 $mime_header->encoding
= 'us-ascii';
272 $part2->mime_header
= $mime_header;
274 $composeMessage = new Message();
275 $composeMessage->rfc822_header
= $rfc822_header;
276 $composeMessage->addEntity($part1);
277 $composeMessage->addEntity($part2);
281 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
282 global $sendmail_path;
283 $deliver = new Deliver_SendMail();
284 $stream = $deliver->initStream($composeMessage,$sendmail_path);
286 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
287 $deliver = new Deliver_SMTP();
288 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
289 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
290 get_smtp_user($user, $pass);
291 $stream = $deliver->initStream($composeMessage,$domain,0,
292 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
296 $length = $deliver->mail($composeMessage, $stream);
297 $success = $deliver->finalizeStream($stream);
300 $msg = $deliver->dlv_msg
. '<br>' .
301 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
302 $deliver->dlv_server_msg
;
303 require_once(SM_PATH
. 'functions/display_messages.php');
304 plain_error_message($msg, $color);
307 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
308 sqimap_append ($imapConnection, $sent_folder, $length);
309 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
310 $imap_deliver = new Deliver_IMAP();
311 $imap_deliver->mail($composeMessage, $imapConnection);
312 sqimap_append_done ($imapConnection);
313 unset ($imap_deliver);
319 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
321 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
322 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
323 $readmessage, $uid_support);
326 function ClearAttachments() {
327 global $username, $attachments, $attachment_dir;
329 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
331 $rem_attachments = array();
332 if (isset($attachments)) {
333 foreach ($attachments as $info) {
334 if ($info['session'] == -1) {
335 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
336 if (file_exists($attached_file)) {
337 unlink($attached_file);
340 $rem_attachments[] = $info;
344 $attachments = $rem_attachments;
347 function formatRecipientString($recipients, $item ) {
348 global $show_more_cc, $show_more, $show_more_bcc,
352 if ((is_array($recipients)) && (isset($recipients[0]))) {
358 $url = set_url_var($PHP_SELF, 'show_more',0);
360 $url = set_url_var($PHP_SELF, 'show_more',1);
362 } else if ($item == 'cc') {
365 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
367 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
369 } else if ($item == 'bcc') {
370 if ($show_more_bcc) {
372 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
378 $cnt = count($recipients);
379 foreach($recipients as $r) {
380 $add = decodeHeader($r->getAddress(true));
382 $string .= '<BR>' . $add;
386 $string .= ' (<A HREF="'.$url;
388 $string .= '">'._("less").'</A>)';
390 $string .= '">'._("more").'</A>)';
400 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
401 $color, $FirstTimeSee) {
402 global $msn_user_support, $default_use_mdn, $default_use_priority,
403 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
404 $squirrelmail_language;
406 $header = $message->rfc822_header
;
408 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
410 $from_name = $header->getAddr_s('from');
412 $from_name = $header->getAddr_s('sender');
414 $env[_("From")] = _("Unknown sender");
416 $env[_("From")] = decodeHeader($from_name);
417 $env[_("Date")] = getLongDateString($header->date
);
418 $env[_("To")] = formatRecipientString($header->to
, "to");
419 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
420 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
421 if ($default_use_priority) {
422 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
424 if ($show_xmailer_default) {
425 $env[_("Mailer")] = decodeHeader($header->xmailer
);
427 if ($default_use_mdn) {
428 if ($mdn_user_support) {
430 if ($message->is_mdnsent
) {
431 $env[_("Read receipt")] = _("sent");
433 $env[_("Read receipt")] = _("requested");
434 if (!(handleAsSent($mailbox) ||
435 $message->is_deleted ||
437 $mdn_url = $PHP_SELF . '&sendreceipt=1';
438 if ($FirstTimeSee && $javascript_on) {
439 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
440 $script .= '<!--'. "\n";
441 $script .= 'if(window.confirm("' .
442 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
446 $script .= '// -->'. "\n";
447 $script .= '</script>'. "\n";
450 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
451 _("Send read receipt now") . ']</a>';
458 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
459 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
460 foreach ($env as $key => $val) {
463 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
464 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
468 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
469 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
470 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
471 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
473 do_hook('read_body_header');
474 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
476 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
481 * Format message toolbar
483 * @param string $mailbox Name of current mailbox
484 * @param int $passed_id UID of current message
485 * @param int $passed_ent_id Id of entity within message
486 * @param object $message Current message object
487 * @param object $mbx_response
489 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
490 global $base_uri, $draft_folder, $where, $what, $color, $sort,
491 $startMessage, $PHP_SELF, $save_as_draft, $uid_support,
492 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
493 $data_dir, $username, $delete_prev_next_display;
495 $topbar_delimiter = ' | ';
496 $double_delimiter = ' ';
497 $urlMailbox = urlencode($mailbox);
499 $comp_uri = 'src/compose.php' .
500 '?passed_id=' . $passed_id .
501 '&mailbox=' . $urlMailbox .
502 '&startMessage=' . $startMessage .
503 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
505 $msgs_url = $base_uri . 'src/';
507 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
508 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
510 // Create Prev & Next links
511 // Handle nested entities first (i.e. Mime Attach parts)
512 if (isset($passed_ent_id) && $passed_ent_id) {
513 // code for navigating through attached message/rfc822 messages
514 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
516 $entity_count = array();
519 foreach($message->parent
->entities
as $ent) {
520 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
522 $entity_count[$c] = $ent->entity_id
;
523 $entities[$ent->entity_id
] = $c;
527 $prev_link = _("Previous");
528 if($entities[$passed_ent_id] > 1) {
529 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
530 $prev_link = '<a href="'
531 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
532 . '">' . $prev_link . '</a>';
535 $next_link = _("Next");
536 if($entities[$passed_ent_id] < $c) {
537 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
538 $next_link = '<a href="'
539 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
540 . '">' . $next_link . '</a>';
543 $par_ent_id = $message->parent
->entity_id
;
546 $par_ent_id = substr($par_ent_id,0,-2);
547 if ( $par_ent_id != 0 ) {
548 $up_link = $topbar_delimiter;
549 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
550 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
554 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
555 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
557 // Prev/Next links for regular messages
558 } else if ( !(isset($where) && isset($what)) ) {
559 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
560 $next = findNextMessage($passed_id);
562 $prev_link = _("Previous");
564 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
565 '&mailbox='.$urlMailbox.'&sort='.$sort.
566 '&startMessage='.$startMessage.'&show_more=0';
567 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
570 $next_link = _("Next");
572 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
573 '&mailbox='.$urlMailbox.'&sort='.$sort.
574 '&startMessage='.$startMessage.'&show_more=0';
575 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
578 // Only bother with Delete & Prev and Delete & Next IF
579 // we have UID support, and top display is enabled.
580 if ( $uid_support && $delete_prev_next_display == 1 ) {
581 $del_prev_link = _("Delete & Prev");
583 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
584 '&mailbox='.$urlMailbox.'&sort='.$sort.
585 '&startMessage='.$startMessage.'&show_more=0'.
586 '&delete_id='.$passed_id;
587 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
590 $del_next_link = _("Delete & Next");
592 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
593 '&mailbox='.$urlMailbox.'&sort='.$sort.
594 '&startMessage='.$startMessage.'&show_more=0'.
595 '&delete_id='.$passed_id;
596 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
600 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
601 if ( isset($del_prev_link) && isset($del_next_link) )
602 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
605 // Start with Search Results or Message List link.
606 if (isset($where) && isset($what)) {
607 $msgs_url .= 'search.php?where=' . urlencode($where) .
608 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
609 $msgs_str = _("Search Results");
611 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
612 $startMessage . '&mailbox=' . $urlMailbox;
613 $msgs_str = _("Message List");
615 $nav_row .= $double_delimiter .
616 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
618 $nav_row .= '</small></td></tr>';
621 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
622 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
624 // If Draft folder - create Resume link
625 if (($mailbox == $draft_folder) && ($save_as_draft)) {
626 $comp_alt_uri = $comp_uri . '&smaction=draft';
627 $comp_alt_string = _("Resume Draft");
628 } else if (handleAsSent($mailbox)) {
629 // If in Sent folder, edit as new
630 $comp_alt_uri = $comp_uri . '&smaction=edit_as_new';
631 $comp_alt_string = _("Edit Message as New");
634 // Show Alt URI for Draft/Sent
635 if (isset($comp_alt_uri)) {
636 $menu_row .= $topbar_delimiter;
637 $menu_row .= makeComposeLink($comp_alt_uri, $comp_alt_string);
638 $menu_row .= $topbar_delimiter;
641 $comp_action_uri = $comp_uri . '&smaction=reply';
642 $menu_row .= makeComposeLink($comp_action_uri, _("Reply"));
644 $comp_action_uri = $comp_uri . '&smaction=reply_all';
645 $menu_row .= $topbar_delimiter;
646 $menu_row .= makeComposeLink($comp_action_uri, _("Reply All"));
649 $comp_action_uri = $comp_uri . '&smaction=forward';
650 $menu_row .= $topbar_delimiter;
651 $menu_row .= makeComposeLink($comp_action_uri, _("Forward"));
653 if ($enable_forward_as_attachment) {
654 $comp_action_uri = $comp_uri . '&smaction=forward_as_attachment';
655 $menu_row .= $topbar_delimiter;
656 $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
659 $delete_link = _("Delete");
660 if (!(isset($passed_ent_id) && $passed_ent_id)) {
661 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
662 '&message=' . $passed_id . '&';
664 if ($where && $what) {
665 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
667 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
669 $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
670 $delete_link .= ' (<a href="' . $delete_url.'&bypass_trash=1">'
671 ._("Bypass Trash").'</a>)';
674 $menu_row .= $topbar_delimiter.$delete_link;
678 $menu_row .= '</small></td><td align="right">';
679 if (!(isset($passed_ent_id) && $passed_ent_id)) {
680 $menu_row .= '<form action="read_body.php?mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage.'&passed_id='.$next.'" method="post">'.
681 '<small><input type="hidden" name="show_more" value="0" />'.
682 '<input type="hidden" name="move_id" value="'.$passed_id.'" />'._("Move to:") .
683 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
684 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
685 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
687 $menu_row .= sqimap_mailbox_option_list($imapConnection);
689 $menu_row .= '</select> '.
690 '<input type="submit" value="' . _("Move") . '" style="padding: 0px; margin: 0px"/>'.
693 $menu_row .= '</td></tr>';
695 // echo rows, with hooks
696 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
697 if (!empty($ret[0])) {
700 if (!empty($ret[1])) {
703 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
704 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
705 echo '</table>'."\n";
706 do_hook('read_body_menu_bottom');
709 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
712 $urlMailbox = urlencode($mailbox);
713 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER
);
714 $url = $base_uri.'src/view_header.php?'.$query_string;
717 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
718 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
719 '<a href="'.$url.'">'._("View Full Header").'</a>';
721 /* Output the printer friendly link if we are in subtle mode. */
722 $s .= ' | ' .
723 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
725 do_hook("read_body_header_right");
726 $s = "</SMALL></TD>\n" .
732 /***************************/
733 /* Main of read_body.php */
734 /***************************/
736 /* get the globals we may need */
738 sqgetGlobalVar('key', $key, SQ_COOKIE
);
739 sqgetGlobalVar('username', $username, SQ_SESSION
);
740 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
741 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
742 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
744 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
745 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
746 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
747 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
748 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
753 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
754 sqgetGlobalVar('where', $where, SQ_GET
);
755 sqgetGlobalVar('what', $what, SQ_GET
);
756 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
757 $show_more = (int) $temp;
759 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
760 $show_more_cc = (int) $temp;
762 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
763 $show_more_bcc = (int) $temp;
765 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
766 $view_hdr = (int) $temp;
770 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
771 sqgetGlobalVar('mailbox', $mailbox);
773 if ( sqgetGlobalVar('passed_id', $temp) ) {
774 $passed_id = (int) $temp;
776 if ( sqgetGlobalVar('sort', $temp) ) {
779 if ( sqgetGlobalVar('startMessage', $temp) ) {
780 $startMessage = (int) $temp;
783 /* end of get globals */
784 global $uid_support, $sqimap_capabilities, $lastTargetMailbox;
786 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
787 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
790 * Process Delete from delete-move-next
791 * but only if delete_id was set
793 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
794 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
796 sqimap_mailbox_expunge_dmn($delete_id);
800 * Process Move from delete-move-next
801 * but only if move_id and target_mailbox were set
803 if ( sqgetGlobalVar('move_id', $move_id, SQ_POST
) &&
804 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST
) ) {
806 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
807 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
809 sqimap_mailbox_expunge_dmn($move_id);
811 if ($targetMailbox != $lastTargetMailbox) {
812 $lastTargetMailbox = $targetMailbox;
813 sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
819 * $message contains all information about the message
820 * including header and body
823 $uidvalidity = $mbx_response['UIDVALIDITY'];
825 if (!isset($messages[$uidvalidity])) {
826 $messages[$uidvalidity] = array();
828 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
829 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
830 $FirstTimeSee = !$message->is_seen
;
831 $message->is_seen
= true;
832 $messages[$uidvalidity][$passed_id] = $message;
834 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
835 $message = $messages[$uidvalidity][$passed_id];
836 $FirstTimeSee = !$message->is_seen
;
839 if (isset($passed_ent_id) && $passed_ent_id) {
840 $message = $message->getEntity($passed_ent_id);
841 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
842 $message = $message->parent
;
844 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
845 $rfc822_header = new Rfc822Header();
846 $rfc822_header->parseHeader($read);
847 $message->rfc822_header
= $rfc822_header;
851 $header = $message->header
;
855 /****************************************/
856 /* Block for handling incoming url vars */
857 /****************************************/
859 if (isset($sendreceipt)) {
860 if ( !$message->is_mdnsent
) {
861 $final_recipient = '';
862 if ((isset($identity)) && ($identity != 0)) //Main identity
863 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
864 if ($final_recipient == '' )
865 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
866 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
867 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
868 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
869 $message->is_mdnsent
= true;
870 $messages[$uidvalidity][$passed_id]=$message;
875 /***********************************************/
876 /* End of block for handling incoming url vars */
877 /***********************************************/
879 $msgs[$passed_id]['FLAG_SEEN'] = true;
882 do_hook('read_body_top');
883 if ($show_html_default == 1) {
884 $ent_ar = $message->findDisplayEntity(array());
886 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
888 $cnt = count($ent_ar);
889 for ($i = 0; $i < $cnt; $i++
) {
890 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
892 $messagebody .= '<hr noshade size=1>';
896 displayPageHeader($color, $mailbox);
897 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
898 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
899 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
901 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
903 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
904 echo ' <tr bgcolor="'.$color[4].'"><td>';
905 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
906 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
907 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
911 echo ' </table></td></tr>';
915 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
916 $color[4].'"></TD></TR>'."\n";
918 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
919 if ($attachmentsdisplay) {
921 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
923 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
924 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
925 echo ' <b>' . _("Attachments") . ':</b>';
928 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
929 echo $attachmentsdisplay;
930 echo ' </td></tr></table>';
931 echo ' </td></tr></table>';
933 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
934 $color[4].'"></TD></TR>';
938 /* show attached images inline -- if pref'fed so */
939 if (($attachment_common_show_images) &&
940 is_array($attachment_common_show_images_list)) {
941 foreach ($attachment_common_show_images_list as $img) {
942 $imgurl = SM_PATH
. 'src/download.php' .
944 'passed_id=' . urlencode($img['passed_id']) .
945 '&mailbox=' . urlencode($mailbox) .
946 '&ent_id=' . urlencode($img['ent_id']) .
947 '&absolute_dl=true';
949 echo html_tag( 'table', "\n" .
950 html_tag( 'tr', "\n" .
951 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
954 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
958 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
960 do_hook('read_body_bottom');
961 do_hook('html_bottom');
962 sqimap_logout($imapConnection);
963 /* sessions are written at the end of the script. it's better to register
964 them at the end so we avoid double session_register calls */
965 sqsession_register($messages,'messages');