Source for file read_body.php

Documentation is available at read_body.php

  1. <?php
  2.  
  3. /**
  4.  * read_body.php
  5.  *
  6.  * This file is used for reading the msgs array and displaying
  7.  * the resulting emails in the right frame.
  8.  *
  9.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: read_body.php,v 1.386 2006/10/06 21:58:17 stevetruckstuff Exp $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /**
  16.  * Include the SquirrelMail initialization file.
  17.  */
  18. require('../include/init.php');
  19.  
  20. /* SquirrelMail required files. */
  21. require_once(SM_PATH 'functions/imap.php');
  22. require_once(SM_PATH 'functions/imap_asearch.php')// => move to mailbox_display
  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/identity.php');
  27. require_once(SM_PATH 'functions/mailbox_display.php');
  28. require_once(SM_PATH 'functions/forms.php');
  29. require_once(SM_PATH 'functions/attachment_common.php');
  30.  
  31. /**
  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
  34.  *
  35.  * @param int $passed_id The current message UID
  36.  * @return the index of the next valid message from the array
  37.  */
  38. function findNextMessage($uidset,$passed_id='backwards'{
  39.     if (!is_array($uidset)) {
  40.         return -1;
  41.     }
  42.     if ($passed_id=='backwards' || !is_array($uidset)) // check for backwards compattibilty gpg plugin
  43.         $passed_id $uidset;
  44.     }
  45.     $result sqm_array_get_value_by_offset($uidset,$passed_id,1);
  46.     if ($result === false{
  47.         return -1;
  48.     else {
  49.         return $result;
  50.     }
  51. }
  52.  
  53. /**
  54.  * Given an IMAP message id number, this will look it up in the cached
  55.  * and sorted msgs array and return the index of the previous message
  56.  *
  57.  * @param int $passed_id The current message UID
  58.  * @return the index of the next valid message from the array
  59.  */
  60.  
  61. function findPreviousMessage($uidset$passed_id{
  62.     if (!is_array($uidset)) {
  63.         return -1;
  64.     }
  65.     $result sqm_array_get_value_by_offset($uidset,$passed_id,-1);
  66.     if ($result === false{
  67.         return -1;
  68.     else {
  69.         return $result;
  70.     }
  71. }
  72.  
  73. function html_toggle_href ($mailbox$passed_id$passed_ent_id$message{
  74.     global $base_uri$show_html_default;
  75.  
  76.     $has_html false;
  77.     if ($message->header->type0 == 'message' && $message->header->type1 == 'rfc822'{
  78.         $type0 $message->rfc822_header->content_type->type0;
  79.         $type1 $message->rfc822_header->content_type->type1;
  80.     else {
  81.         $type0 $message->header->type0;
  82.         $type1 $message->header->type1;
  83.     }
  84.     if($type0 == 'multipart' &&
  85.        ($type1 == 'alternative' || $type1 == 'mixed' || $type1 == 'related' || $type1=='signed')) {
  86.         if ($message->findDisplayEntity(array()array('text/html')true)) {
  87.             $has_html true;
  88.         }
  89.     }
  90.     /*
  91.      * Normal single part message so check its type.
  92.      */
  93.     else {
  94.         if($type0 == 'text' && $type1 == 'html'{
  95.             $has_html true;
  96.         }
  97.     }
  98.     if($has_html == true{
  99.         $vars array('passed_ent_id''show_more''show_more_cc''override_type0''override_type1''startMessage','where''what');
  100.  
  101.         $new_link $base_uri 'src/read_body.php?passed_id=' urlencode($passed_id.
  102.                     '&amp;passed_ent_id=' urlencode($passed_ent_id.
  103.                     '&amp;mailbox=' urlencode($mailbox);
  104.         foreach($vars as $var{
  105.             if(sqgetGlobalVar($var$temp)) {
  106.                 $new_link .= '&amp;' $var '=' urlencode($temp);
  107.             }
  108.         }
  109.  
  110.         if($show_html_default == 1{
  111.             $new_link .= '&amp;show_html_default=0';
  112.         else {
  113.             $new_link .= '&amp;show_html_default=1';
  114.         }
  115.         return $new_link;
  116.     }
  117.     return '';
  118. }
  119.  
  120. function ServerMDNSupport($aFlags{
  121.     /* escaping $ doesn't work -> \x36 */
  122.     return in_array('$mdnsent',$aFlags,true||
  123.              in_array('\\*',$aFlags,true) ) ;
  124. }
  125.  
  126. function SendMDN $mailbox$passed_id$sender$message$imapConnection{
  127.     global $username$attachment_dir$popuser$username$color,
  128.            $version$squirrelmail_language$default_charset,
  129.            $languages$useSendmail$domain$sent_folder;
  130.  
  131.     sqgetGlobalVar('SERVER_NAME'$SERVER_NAMESQ_SERVER);
  132.  
  133.     $header $message->rfc822_header;
  134.  
  135.     $rfc822_header new Rfc822Header();
  136.     $content_type  new ContentType('multipart/report');
  137.     $content_type->properties['report-type']='disposition-notification';
  138.  
  139.     set_my_charset();
  140.     if ($default_charset{
  141.         $content_type->properties['charset']=$default_charset;
  142.     }
  143.     $rfc822_header->content_type $content_type;
  144.     $rfc822_header->to[$header->dnt;
  145.     $rfc822_header->subject _("Read:"' ' encodeHeader($header->subject);
  146.  
  147.     // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
  148.     // This merely comes from compose.php and only happens when there is no
  149.     // email_addr specified in user's identity (which is the startup config)
  150.     if (ereg("^([^@%/]+)[@%/](.+)$"$username$usernamedata)) {
  151.        $popuser $usernamedata[1];
  152.        $domain  $usernamedata[2];
  153.        unset($usernamedata);
  154.     else {
  155.        $popuser $username;
  156.     }
  157.  
  158.     $reply_to '';
  159.     $ident get_identities();
  160.     if(!isset($identity)) $identity 0;
  161.     $full_name $ident[$identity]['full_name'];
  162.     $from_mail $ident[$identity]['email_address'];
  163.     $from_addr '"'.$full_name.'" <'.$from_mail.'>';
  164.     $reply_to  $ident[$identity]['reply_to'];
  165.  
  166.     if (!$from_mail{
  167.        $from_mail "$popuser@$domain";
  168.        $from_addr $from_mail;
  169.     }
  170.     $rfc822_header->from $rfc822_header->parseAddress($from_addr,true);
  171.     if ($reply_to{
  172.        $rfc822_header->reply_to $rfc822_header->parseAddress($reply_to,true);
  173.     }
  174.  
  175.     // part 1 (RFC2298)
  176.     $senton getLongDateString$header->date );
  177.     $to_array $header->to;
  178.     $to '';
  179.     foreach ($to_array as $line{
  180.         $to .= ' '.$line->getAddress();
  181.     }
  182.     $now getLongDateStringtime() );
  183.     set_my_charset();
  184.     $body _("Your message""\r\n\r\n" .
  185.             "\t" _("To"': ' decodeHeader($to,false,false"\r\n" .
  186.             "\t" _("Subject"': ' decodeHeader($header->subject,false,false"\r\n" .
  187.             "\t" _("Sent"': ' $senton "\r\n" .
  188.             "\r\n" .
  189.             sprintf_("Was displayed on %s")$now );
  190.  
  191.     $special_encoding '';
  192.     if (isset($languages[$squirrelmail_language]['XTRA_CODE']&&
  193.         function_exists($languages[$squirrelmail_language]['XTRA_CODE''_encode')) {
  194.         $body call_user_func($languages[$squirrelmail_language]['XTRA_CODE''_encode'$body);
  195.         if (strtolower($default_charset== 'iso-2022-jp'{
  196.             if (mb_detect_encoding($body== 'ASCII'{
  197.                 $special_encoding '8bit';
  198.             else {
  199.                 $body mb_convert_encoding($body'JIS');
  200.                 $special_encoding '7bit';
  201.             }
  202.         }
  203.     elseif (sq_is8bit($body)) {
  204.         $special_encoding '8bit';
  205.     }
  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;
  213.     else {
  214.         $mime_header->encoding 'us-ascii';
  215.     }
  216.     if ($default_charset{
  217.         $mime_header->parameters['charset'$default_charset;
  218.     }
  219.     $part1->mime_header $mime_header;
  220.  
  221.     // part2  (RFC2298)
  222.     $original_recipient  $to;
  223.     $original_message_id $header->message_id;
  224.  
  225.     $report "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
  226.     if ($original_recipient != ''{
  227.         $report .= "Original-Recipient : $original_recipient\r\n";
  228.     }
  229.     $final_recipient $sender;
  230.     $report .= "Final-Recipientrfc822$final_recipient\r\n.
  231.               "Original-Message-ID : $original_message_id\r\n.
  232.               "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
  233.  
  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;
  241.  
  242.     $composeMessage new Message();
  243.     $composeMessage->rfc822_header $rfc822_header;
  244.     $composeMessage->addEntity($part1);
  245.     $composeMessage->addEntity($part2);
  246.  
  247.  
  248.     if ($useSendmail{
  249.         require_once(SM_PATH 'class/deliver/Deliver_SendMail.class.php');
  250.         global $sendmail_path$sendmail_args;
  251.         // Check for outdated configuration
  252.         if (!isset($sendmail_args)) {
  253.             if ($sendmail_path=='/var/qmail/bin/qmail-inject'{
  254.                 $sendmail_args '';
  255.             else {
  256.                 $sendmail_args '-i -t';
  257.             }
  258.         }
  259.         $deliver new Deliver_SendMail(array('sendmail_args'=>$sendmail_args));
  260.         $stream $deliver->initStream($composeMessage,$sendmail_path);
  261.     else {
  262.         require_once(SM_PATH 'class/deliver/Deliver_SMTP.class.php');
  263.         $deliver new Deliver_SMTP();
  264.         global $smtpServerAddress$smtpPort$pop_before_smtp;
  265.         $authPop (isset($pop_before_smtp&& $pop_before_smtptrue false;
  266.         get_smtp_user($user$pass);
  267.         $stream $deliver->initStream($composeMessage,$domain,0,
  268.                                        $smtpServerAddress$smtpPort$user$pass$authPop);
  269.     }
  270.     $success false;
  271.     if ($stream{
  272.         $length  $deliver->mail($composeMessage$stream);
  273.         $success $deliver->finalizeStream($stream);
  274.     }
  275.     if (!$success{
  276.         $msg $deliver->dlv_msg;
  277.         if (empty($deliver->dlv_server_msg)) {
  278.             $msg.= '<br />' .
  279.                 _("Server replied:"' ' $deliver->dlv_ret_nr ' ' .
  280.                 nl2br(htmlspecialchars($deliver->dlv_server_msg));
  281.         }
  282.         plain_error_message($msg$color);
  283.     else {
  284.         unset ($deliver);
  285.         if (sqimap_mailbox_exists ($imapConnection$sent_folder)) {
  286.             $sid sqimap_append ($imapConnection$sent_folder$length);
  287.             require_once(SM_PATH 'class/deliver/Deliver_IMAP.class.php');
  288.             $imap_deliver new Deliver_IMAP();
  289.             $imap_deliver->mail($composeMessage$imapConnection);
  290.             sqimap_append_done ($imapConnection$sent_folder);
  291.             unset ($imap_deliver);
  292.         }
  293.     }
  294.     return $success;
  295. }
  296.  
  297. function ToggleMDNflag ($set ,$imapConnection$mailbox$passed_id{
  298.     $sg   =  $set?'+':'-';
  299.     $cmd  'STORE ' $passed_id ' ' $sg 'FLAGS ($MDNSent)';
  300.     $read sqimap_run_command ($imapConnection$cmdtrue$response,
  301.                                 $readmessageTRUE);
  302. }
  303.  
  304. function formatRecipientString($recipients$item {
  305.     global $show_more_cc$show_more$show_more_bcc,
  306.            $PHP_SELF$oTemplate;
  307.  
  308.     $string '';
  309.     if ((is_array($recipients)) && (isset($recipients[0]))) {
  310.         $show false;
  311.  
  312.         if ($item == 'to'{
  313.             if ($show_more{
  314.                 $show true;
  315.                 $url set_url_var($PHP_SELF'show_more',0);
  316.             else {
  317.                 $url set_url_var($PHP_SELF'show_more',1);
  318.             }
  319.         else if ($item == 'cc'{
  320.             if ($show_more_cc{
  321.                 $show true;
  322.                 $url set_url_var($PHP_SELF'show_more_cc',0);
  323.             else {
  324.                 $url set_url_var($PHP_SELF'show_more_cc',1);
  325.             }
  326.         else if ($item == 'bcc'{
  327.             if ($show_more_bcc{
  328.                 $show true;
  329.                 $url set_url_var($PHP_SELF'show_more_bcc',0);
  330.             else {
  331.                 $url set_url_var($PHP_SELF'show_more_bcc',1);
  332.             }
  333.         }
  334.         
  335.         $a array();
  336.         foreach ($recipients as $r{
  337.             $a[array(
  338.                             'Name'  => htmlspecialchars($r->getAddress(false)),
  339.                             'Email' => htmlspecialchars($r->getEmail()),
  340.                             'Full'  => htmlspecialchars($r->getAddress(true))
  341.                         );
  342.         }
  343.         
  344.         $oTemplate->assign('which_field'$item);
  345.         $oTemplate->assign('recipients'$a);
  346.         $oTemplate->assign('more_less_toggle_href'$url);
  347.         $oTemplate->assign('show_more'$show);
  348.         
  349.         $string $oTemplate->fetch('read_recipient_list.tpl');
  350.     }
  351.     return $string;
  352. }
  353.  
  354. function formatEnvheader($aMailbox$passed_id$passed_ent_id$message,
  355.                          $color$FirstTimeSee{
  356.            $show_xmailer_default$mdn_user_support$PHP_SELF$javascript_on,
  357.            $squirrelmail_language$oTemplate;
  358.  
  359.     $mailbox $aMailbox['NAME'];
  360.  
  361.     $header $message->rfc822_header;
  362.     $env array();
  363.     $env[_("Subject")str_replace("&nbsp;"," ",decodeHeader($header->subject));
  364.  
  365.     $from_name $header->getAddr_s('from');
  366.     if (!$from_name)
  367.         $from_name $header->getAddr_s('sender');
  368.     if (!$from_name)
  369.         $env[_("From")_("Unknown sender");
  370.     else
  371.         $env[_("From")decodeHeader($from_name);
  372.     $env[_("Date")getLongDateString($header->date);
  373.     $env[_("To")formatRecipientString($header->to"to");
  374.     $env[_("Cc")formatRecipientString($header->cc"cc");
  375.     $env[_("Bcc")formatRecipientString($header->bcc"bcc");
  376.     if ($default_use_priority{
  377.         $oTemplate->assign('message_priority'$header->priority);
  378.         $env[_("Priority")$oTemplate->fetch('read_message_priority.tpl');
  379.     }
  380.     if ($show_xmailer_default{
  381.         $oTemplate->assign('xmailer'decodeHeader($header->xmailer));
  382.         $env[_("Mailer")$oTemplate->fetch('read_xmailer.tpl');
  383.     }
  384.     if ($default_use_mdn{
  385.         if ($mdn_user_support{
  386.             if ($header->dnt{
  387.                 $mdn_url $PHP_SELF;
  388.                 $mdn_url set_url_var($PHP_SELF'mailbox'urlencode($mailbox));
  389.                 $mdn_url set_url_var($PHP_SELF'passed_id'$passed_id);
  390.                 $mdn_url set_url_var($PHP_SELF'passed_ent_id'$passed_ent_id);
  391.                 $mdn_url set_url_var($PHP_SELF'sendreceipt'1);
  392.  
  393.                 $oTemplate->assign('read_receipt_sent'$message->is_mdnsent);
  394.                 $oTemplate->assign('first_time_reading'$FirstTimeSee);
  395.                 $oTemplate->assign('send_receipt_href'$mdn_url);
  396.                 
  397.                 $env[_("Read Receipt")$oTemplate->fetch('read_handle_receipt.tpl');
  398.             }
  399.         }
  400.     }
  401.     $env[_("Options")formatToolbar($mailbox$passed_id$passed_ent_id$message$color);
  402.  
  403.     $oTemplate->assign('headers_to_display'$env);
  404.     
  405.     $oTemplate->display('read_headers.tpl');
  406. }
  407.  
  408. /**
  409.  * Format message toolbar
  410.  *
  411.  * @param string $mailbox Name of current mailbox
  412.  * @param int $passed_id UID of current message
  413.  * @param int $passed_ent_id Id of entity within message
  414.  * @param object $message Current message object
  415.  * @param object $mbx_response 
  416.  */
  417. function formatMenubar($aMailbox$passed_id$passed_ent_id$message$removedVar$nav_on_top TRUE{
  418.     global $base_uri$draft_folder$where$what$sort,
  419.            $startMessage$PHP_SELF$save_as_draft,
  420.            $enable_forward_as_attachment$imapConnection$lastTargetMailbox,
  421.            $delete_prev_next_display$show_copy_buttons,
  422.            $compose_new_win$javascript_on$compose_width$compose_height,
  423.            $oTemplate;
  424.  
  425.     //FIXME cleanup argument list, use $aMailbox where possible
  426.     $mailbox $aMailbox['NAME'];
  427.  
  428.     $urlMailbox urlencode($mailbox);
  429.  
  430.     $msgs_url $base_uri 'src/';
  431.  
  432.     // Create Prev & Next links
  433.     // Handle nested entities first (i.e. Mime Attach parts)
  434.     $prev_href $next_href $up_href $del_href $del_prev_href $del_next_href '';
  435.     $msg_list_href $search_href $view_msg_href ''
  436.     if (isset($passed_ent_id&& $passed_ent_id{
  437.         // code for navigating through attached message/rfc822 messages
  438.         $url set_url_var($PHP_SELF'passed_ent_id',0);
  439.         $entities     array();
  440.         $entity_count array();
  441.         $c 0;
  442.  
  443.         foreach($message->parent->entities as $ent{
  444.             if ($ent->type0 == 'message' && $ent->type1 == 'rfc822'{
  445.                 
  446.                 $c++;
  447.                 $entity_count[$c$ent->entity_id;
  448.                 $entities[$ent->entity_id$c;
  449.             }
  450.         }
  451.  
  452.         if(isset($entities[$passed_ent_id]&& $entities[$passed_ent_id1{
  453.             $prev_ent_id $entity_count[$entities[$passed_ent_id1];
  454.             $prev_href set_url_var($PHP_SELF'passed_ent_id'$prev_ent_id);
  455.         }
  456.  
  457.         if(isset($entities[$passed_ent_id]&& $entities[$passed_ent_id$c{
  458.             $next_ent_id $entity_count[$entities[$passed_ent_id1];
  459.             $next_href set_url_var($PHP_SELF'passed_ent_id'$next_ent_id);
  460.         }
  461.  
  462.         $par_ent_id $message->parent->entity_id;
  463.         if ($par_ent_id{
  464.             $par_ent_id substr($par_ent_id,0,-2);
  465.             if $par_ent_id != {
  466.                 $up_href set_url_var($PHP_SELF'passed_ent_id',$par_ent_id);
  467.             }
  468.         }
  469.  
  470.         $view_msg_href $url;
  471.  
  472.     // Prev/Next links for regular messages
  473.     else if true //!(isset($where) && isset($what)) ) {
  474.         $prev findPreviousMessage($aMailbox['UIDSET'][$what]$passed_id);
  475.         $next findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
  476.  
  477.         if ($prev >= 0{
  478.             $prev_href $base_uri 'src/read_body.php?passed_id='.$prev.
  479.                    '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  480.                    "&amp;where=$where&amp;what=$what.
  481.                    '&amp;startMessage='.$startMessage.'&amp;show_more=0';
  482.         }
  483.  
  484.         if ($next >= 0{
  485.             $next_href $base_uri 'src/read_body.php?passed_id='.$next.
  486.                    '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  487.                    "&amp;where=$where&amp;what=$what.
  488.                    '&amp;startMessage='.$startMessage.'&amp;show_more=0';
  489.         }
  490.  
  491.         // Only bother with Delete & Prev and Delete & Next IF
  492.         // top display is enabled.
  493.         if $delete_prev_next_display == &&
  494.                in_array('\\deleted'$aMailbox['PERMANENTFLAGS'],true) ) {
  495.             if ($prev >= 0{
  496.                 $del_prev_href $base_uri 'src/read_body.php?passed_id='.$prev.
  497.                        '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  498.                        '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
  499.                        "&amp;where=$where&amp;what=$what.
  500.                        '&amp;delete_id='.$passed_id;
  501.             }
  502.  
  503.             if ($next >= 0{
  504.                 $del_next_href $base_uri 'src/read_body.php?passed_id='.$next.
  505.                        '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  506.                        '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
  507.                        "&amp;where=$where&amp;what=$what.
  508.                        '&amp;delete_id='.$passed_id;
  509.             }
  510.         }
  511.     }
  512.  
  513.     // Start with Search Results or Message List link.
  514.     $list_xtra "?where=read_body.php&amp;what=$what&amp;mailbox=$urlMailbox.
  515.                  "&amp;startMessage=$startMessage";
  516.     $msg_list_href $base_uri .'src/right_main.php'$list_xtra;
  517.     $search_href $where=='search.php' $base_uri .'src/search.php?'.$list_xtra '';
  518.  
  519.     $comp_uri $base_uri.'src/compose.php' .
  520.                 '?passed_id=' $passed_id .
  521.                 '&amp;mailbox=' $urlMailbox .
  522.                 '&amp;startMessage=' $startMessage .
  523.                  (isset($passed_ent_id'&amp;passed_ent_id='.$passed_ent_id '');
  524.  
  525.     // Start form for reply/reply all/forward..
  526.     $target '';
  527.     $on_click='';
  528.     $method='method="post" ';
  529.     $onsubmit='';
  530.     if ($compose_new_win == '1'{
  531.         if (!preg_match("/^[0-9]{3,4}$/"$compose_width)) {
  532.             $compose_width '640';
  533.         }
  534.         if (!preg_match("/^[0-9]{3,4}$/"$compose_height)) {
  535.             $compose_height '550';
  536.         }
  537.         if $javascript_on {
  538.           $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'$compose_width .',' $compose_height .')"';
  539.           $comp_uri 'javascript:void(0)';
  540.           $method='method="get" ';
  541.           $onsubmit 'onsubmit="return false" ';
  542.         else {
  543.           $target 'target="_blank"';
  544.         }
  545.     }
  546.  
  547.     $oTemplate->assign('nav_on_top'$nav_on_top);
  548.  
  549.     $oTemplate->assign('prev_href'$prev_href);
  550.     $oTemplate->assign('up_href'$up_href);
  551.     $oTemplate->assign('next_href'$next_href);
  552.     $oTemplate->assign('del_prev_href'$del_prev_href);
  553.     $oTemplate->assign('del_next_href'$del_next_href);
  554.     $oTemplate->assign('view_msg_href'$view_msg_href);
  555.  
  556.     $oTemplate->assign('message_list_href'$msg_list_href);
  557.     $oTemplate->assign('search_href'$search_href);
  558.  
  559.     $oTemplate->assign('form_extra'$method $target $onsubmit);
  560.     $oTemplate->assign('compose_href'$comp_uri);
  561.     $oTemplate->assign('button_onclick'$on_click);
  562.     $oTemplate->assign('forward_as_attachment_enabled'$enable_forward_as_attachment==1);
  563.     
  564.     // If Draft folder - create Resume link
  565.     $resume_draft $edit_as_new false;    
  566.     if (($mailbox == $draft_folder&& ($save_as_draft)) {
  567.         $resume_draft true'smaction_draft';
  568.     else if (handleAsSent($mailbox)) {
  569.         $edit_as_new true;
  570.     }
  571.     $oTemplate->assign('can_resume_draft'$resume_draft);
  572.     $oTemplate->assign('can_edit_as_new'$edit_as_new);    
  573.     
  574.     $oTemplate->assign('mailboxes'sqimap_mailbox_option_array($imapConnection));
  575.     if (in_array('\\deleted'$aMailbox['PERMANENTFLAGS'],true)) {
  576.         $delete_url $base_uri "src/$where";
  577.         $oTemplate->assign('can_be_deleted'true);
  578.         $oTemplate->assign('move_delete_form_action'$base_uri.'src/'.$where);
  579.         $oTemplate->assign('delete_form_extra'addHidden('mailbox'$aMailbox['NAME'])."\n" .
  580.                                                 addHidden('msg[0]'$passed_id)."\n" .
  581.                                                 addHidden('startMessage'$startMessage)."\n" );
  582.         if (!(isset($passed_ent_id&& $passed_ent_id)) {
  583.             $oTemplate->assign('can_be_moved'true);
  584.             $oTemplate->assign('move_form_extra'addHidden('mailbox'$aMailbox['NAME'])."\n" .
  585.                                                   addHidden('msg[0]'$passed_id)."\n" );
  586.             $oTemplate->assign('last_move_target'isset($lastTargetMailbox&& !empty($lastTargetMailbox$lastTargetMailbox '');
  587.             $oTemplate->assign('can_be_copied'$show_copy_buttons==1);
  588.         else {
  589.             $oTemplate->assign('can_be_moved'false);
  590.             $oTemplate->assign('move_form_extra''');
  591.             $oTemplate->assign('last_move_target''');
  592.             $oTemplate->assign('can_be_copied'false);
  593.         }
  594.     else {
  595.         $oTemplate->assign('can_be_deleted'false);
  596.         $oTemplate->assign('move_delete_form_action''');
  597.         $oTemplate->assign('delete_form_extra''');
  598.         $oTemplate->assign('can_be_moved'false);
  599.         $oTemplate->assign('move_form_extra''');
  600.         $oTemplate->assign('last_move_target''');
  601.         $oTemplate->assign('can_be_copied'false);
  602.     }
  603.     
  604.     if ($nav_on_top{
  605.         $oTemplate->display('read_menubar_nav.tpl');
  606.         $oTemplate->display('read_menubar_buttons.tpl');
  607.     else {
  608.         $oTemplate->display('read_menubar_buttons.tpl');
  609.         $oTemplate->display('read_menubar_nav.tpl');
  610.     }
  611.     
  612.     do_hook('read_body_menu_bottom');
  613. }
  614.  
  615. function formatToolbar($mailbox$passed_id$passed_ent_id$message$color{
  616.     global $base_uri$where$what$show_html_default,
  617.            $oTemplate$javascript_on$download_href
  618.            $unsafe_image_toggle_href$unsafe_image_toggle_text;
  619.  
  620.     $urlMailbox urlencode($mailbox);
  621.     $urlPassed_id urlencode($passed_id);
  622.     $urlPassed_ent_id urlencode($passed_ent_id);
  623.  
  624.     $query_string 'mailbox=' $urlMailbox '&amp;passed_id=' $urlPassed_id '&amp;passed_ent_id=' $urlPassed_ent_id;
  625.     if (!empty($where)) {
  626.         $query_string .= '&amp;where=' urlencode($where);
  627.     }
  628.     if (!empty($what)) {
  629.         $query_string .= '&amp;what=' urlencode($what);
  630.     }
  631.     $url $base_uri.'src/view_header.php?'.$query_string;
  632.  
  633.  
  634.     // Build the printer friend link
  635.     /* hackydiehack */
  636.     if!sqgetGlobalVar('view_unsafe_images'$view_unsafe_imagesSQ_GET) ) {
  637.         $view_unsafe_images false;
  638.     else {
  639.         $view_unsafe_images true;
  640.     }
  641.     $pf_params '?passed_ent_id=' $urlPassed_ent_id .
  642.                  '&mailbox=' $urlMailbox .
  643.                  '&passed_id=' $urlPassed_id .
  644.                  '&view_unsafe_images='. (bool) $view_unsafe_images .
  645.                  '&show_html_default=' $show_html_default;    
  646.     $links array();
  647.     $links[array (
  648.                         'URL'   => $url,
  649.                         'Text'  => _("View Full Header")
  650.                      );
  651.     $links[array (
  652.                         'URL'   => $pf_params,
  653.                         'Text'  => _("View Printable Version")
  654.                      );
  655.     $links[array (
  656.                         'URL'   => $download_href,
  657.                         'Text'  => _("Download this is a file")
  658.                      );
  659.     $toggle html_toggle_href($mailbox$passed_id$passed_ent_id$message);
  660.     if (!empty($toggle)) {
  661.         $links[array (
  662.                             'URL'   => $toggle,
  663.                             'Text'  => $show_html_default==_("View as plain text"_("View as HTML")
  664.                          );
  665.     }
  666.     if (!empty($unsafe_image_toggle_href)) {
  667.         $links[array (
  668.                             'URL'   => $unsafe_image_toggle_href,
  669.                             'Text'  => $unsafe_image_toggle_text
  670.                          );
  671.     }
  672.  
  673.     do_hook('read_body_header_right'$links);
  674.  
  675.     $oTemplate->assign('links'$links);
  676.     
  677.     return $oTemplate->fetch('read_toolbar.tpl');
  678. }
  679.  
  680. /***************************/
  681. /*   Main of read_body.php */
  682. /***************************/
  683.  
  684. /* get the globals we may need */
  685.  
  686. sqgetGlobalVar('delimiter'$delimiter,     SQ_SESSION);
  687. sqgetGlobalVar('lastTargetMailbox'$lastTargetMailboxSQ_SESSION);
  688. if (!sqgetGlobalVar('messages'$messagesSQ_SESSION) ) {
  689.     $messages array();
  690. }
  691. sqgetGlobalVar('delayed_errors',  $delayed_errors,  SQ_SESSION);
  692. if (is_array($delayed_errors)) {
  693.     $oErrorHandler->AssignDelayedErrors($delayed_errors);
  694.     sqsession_unregister("delayed_errors");
  695. }
  696. /** GET VARS */
  697. sqgetGlobalVar('sendreceipt',   $sendreceipt,   SQ_GET);
  698. if (!sqgetGlobalVar('where',         $where,         SQ_GET) ) {
  699.     $where 'right_main.php';
  700. }
  701. /*
  702.  * Used as entry key to the list of uid's cached in the mailbox cache
  703.  * we use the cached uid's to get the next and prev  message.
  704.  */
  705. if (!sqgetGlobalVar('what',          $what,          SQ_GET) ){
  706.     $what 0;
  707. }
  708. if sqgetGlobalVar('show_more'$temp,  SQ_GET) ) {
  709.     $show_more = (int) $temp;
  710. }
  711. if sqgetGlobalVar('show_more_cc'$temp,  SQ_GET) ) {
  712.     $show_more_cc = (int) $temp;
  713. }
  714. if sqgetGlobalVar('show_more_bcc'$temp,  SQ_GET) ) {
  715.     $show_more_bcc = (int) $temp;
  716. }
  717. if sqgetGlobalVar('view_hdr'$temp,  SQ_GET) ) {
  718.     $view_hdr = (int) $temp;
  719. }
  720.  
  721. if sqgetGlobalVar('account'$temp,  SQ_GET) ) {
  722.     $iAccount = (int) $temp;
  723. else {
  724.     $iAccount 0;
  725. }
  726.  
  727. /** GET/POST VARS */
  728. sqgetGlobalVar('passed_ent_id'$passed_ent_id);
  729. sqgetGlobalVar('mailbox',       $mailbox);
  730.  
  731. if sqgetGlobalVar('passed_id'$temp) ) {
  732.     $passed_id = (int) $temp;
  733. }
  734. if sqgetGlobalVar('sort'$temp) ) {
  735.     $sort = (int) $temp;
  736. }
  737. if sqgetGlobalVar('startMessage'$temp) ) {
  738.     $startMessage = (int) $temp;
  739. else {
  740.     $startMessage 1;
  741. }
  742. if(sqgetGlobalVar('show_html_default'$temp)) {
  743.     $show_html_default = (int) $temp;
  744. }
  745.  
  746. if(sqgetGlobalVar('view_unsafe_images'$temp)) {
  747.     $view_unsafe_images = (int) $temp;
  748.     if($view_unsafe_images == 1{
  749.         $show_html_default 1;
  750.     }
  751. else {
  752.     $view_unsafe_images 0;
  753. }
  754. /**
  755.  * Retrieve mailbox cache
  756.  */
  757. sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
  758.  
  759. /* end of get globals */
  760. global $sqimap_capabilities$lastTargetMailbox;
  761.  
  762. $imapConnection sqimap_login($usernamefalse$imapServerAddress$imapPort0);
  763. $aMailbox sqm_api_mailbox_select($imapConnection$iAccount$mailbox,array('setindex' => $what'offset' => $startMessage),array());
  764.  
  765.  
  766. /**
  767.  Start code to set the columns to fetch in case of hitting the next/prev link
  768.  The reason for this is the fact that the cache can be invalidated which means that the headers
  769.  to fetch aren't there anymore. Before they got calculated when the messagelist was shown.
  770.  
  771.  Todo, better central handling of setting the mailbox options so we do not need to do the stuff below
  772. */
  773.  
  774. /**
  775.  * Replace From => To  in case it concerns a draft or sent folder
  776.  */
  777. $aColumns array();
  778. if (($mailbox == $sent_folder || $mailbox == $draft_folder&&
  779.     !in_array(SQM_COL_TO,$index_order)) {
  780.     $aNewOrder array()// nice var name ;)
  781.         foreach($index_order as $iCol{
  782.         if ($iCol == SQM_COL_FROM{
  783.             $iCol SQM_COL_TO;
  784.         }
  785.         $aColumns[$iColarray();
  786.    }
  787. else {
  788.    foreach ($index_order as $iCol{
  789.        $aColumns[$iColarray();
  790.    }
  791. }
  792.  
  793. $aProps array(
  794.     'columns' => $aColumns// columns bound settings
  795.         'config'  => array(
  796.                         'highlight_list'        => $message_highlight_list// row highlighting rules
  797.                                                 'trash_folder'          => $trash_folder,
  798.                         'sent_folder'           => $sent_folder,
  799.                         'draft_folder'          => $draft_folder));
  800.  
  801. calcFetchColumns($aMailbox,$aProps);
  802.  
  803. /**
  804.  End code to set the columns to fetch in case of hitting the next/prev link
  805. */
  806.  
  807.  
  808.  
  809. /**
  810.  * Check if cache is still valid, $what contains the key
  811.  * which gives us acces to the array with uid's. At this moment
  812.  * 0 is used for a normal message list and search uses 1 as key. This can be
  813.  * changed / extended in the future.
  814.  * If on a select of a mailbox we detect that the cache should be invalidated due to
  815.  * the delete of messages or due to new messages we empty the list with uid's and
  816.  * that's what we detect below.
  817.  */
  818. if (!is_array($aMailbox['UIDSET'][$what])) {
  819.     fetchMessageHeaders($imapConnection$aMailbox);
  820. }
  821.  
  822. $iSetIndex $aMailbox['SETINDEX'];
  823. $aMailbox['CURRENT_MSG'][$iSetIndex$passed_id;
  824.  
  825. /**
  826.  * Update the seen state
  827.  * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
  828.  */
  829. if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
  830.     $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'true;
  831. }
  832.  
  833. /**
  834.  * Process Delete from delete-move-next
  835.  * but only if delete_id was set
  836.  */
  837. if sqgetGlobalVar('delete_id'$delete_idSQ_GET) ) {
  838.     handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted'array($delete_id));
  839. }
  840.  
  841. /**
  842.  * $message contains all information about the message
  843.  * including header and body
  844.  */
  845.  
  846. if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
  847.     $message $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
  848.     $FirstTimeSee !$message->is_seen;
  849. else {
  850.     $message sqimap_get_message($imapConnection$passed_id$mailbox);
  851.     $FirstTimeSee !$message->is_seen;
  852.     $message->is_seen true;
  853.     $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'$message;
  854. }
  855. if (isset($passed_ent_id&& $passed_ent_id{
  856.     $message $message->getEntity($passed_ent_id);
  857.     if ($message->type0 != 'message'  && $message->type1 != 'rfc822'{
  858.         $message $message->parent;
  859.     }
  860.     $read sqimap_run_command ($imapConnection"FETCH $passed_id BODY[$passed_ent_id.HEADER]"true$response$msgTRUE);
  861.     $rfc822_header new Rfc822Header();
  862.     $rfc822_header->parseHeader($read);
  863.     $message->rfc822_header $rfc822_header;
  864. else if ($message->type0 == 'message'  && $message->type1 == 'rfc822' && isset($message->entities[0])) {
  865.     $read sqimap_run_command ($imapConnection"FETCH $passed_id BODY[1.HEADER]"true$response$msgTRUE);
  866.     $rfc822_header new Rfc822Header();
  867.     $rfc822_header->parseHeader($read);
  868.     $message->rfc822_header $rfc822_header;
  869. else {
  870.     $passed_ent_id 0;
  871. }
  872. $header $message->header;
  873.  
  874.  
  875. /****************************************/
  876. /* Block for handling incoming url vars */
  877. /****************************************/
  878.  
  879. if (isset($sendreceipt)) {
  880.    if !$message->is_mdnsent {
  881.       $final_recipient '';
  882.       if ((isset($identity)) && ($identity != 0)) //Main identity
  883.                   $final_recipient trim(getPref($data_dir$username'email_address' $identity'' ));
  884.       if ($final_recipient == '' )
  885.          $final_recipient trim(getPref($data_dir$username'email_address''' ));
  886.       $supportMDN ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
  887.       if SendMDN$mailbox$passed_id$final_recipient$message$imapConnection && $supportMDN {
  888.          ToggleMDNflagtrue$imapConnection$mailbox$passed_id);
  889.          $message->is_mdnsent true;
  890.          $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'$message;
  891.       }
  892.    }
  893. }
  894. /***********************************************/
  895. /* End of block for handling incoming url vars */
  896. /***********************************************/
  897.  
  898. $messagebody '';
  899. do_hook('read_body_top');
  900. if ($show_html_default == 1{
  901.     $ent_ar $message->findDisplayEntity(array());
  902. else {
  903.     $ent_ar $message->findDisplayEntity(array()array('text/plain'));
  904. }
  905. $cnt count($ent_ar);
  906. for ($i 0$i $cnt$i++{
  907.    $messagebody .= formatBody($imapConnection$message$color$wrap_at$ent_ar[$i]$passed_id$mailbox);
  908.    if ($i != $cnt-1{
  909.        $messagebody .= '<hr />';
  910.    }
  911. }
  912.  
  913. /**
  914.  * Write mailbox with updated seen flag information back to cache.
  915.  */
  916. $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] $aMailbox;
  917. sqsession_register($mailbox_cache,'mailbox_cache');
  918. $_SESSION['mailbox_cache'$mailbox_cache;
  919.  
  920. displayPageHeader($color$mailbox,'','');
  921. formatMenuBar($aMailbox$passed_id$passed_ent_id$message,false);
  922. formatEnvheader($aMailbox$passed_id$passed_ent_id$message$color$FirstTimeSee);
  923.  
  924. $oTemplate->assign('message_body'$messagebody);
  925. $oTemplate->display('read_message_body.tpl');
  926.  
  927. formatAttachments($message,$ent_ar,$mailbox$passed_id);
  928.  
  929. /* show attached images inline -- if pref'fed so */
  930. if ($attachment_common_show_images && is_array($attachment_common_show_images_list)) {
  931.     $images array();
  932.     foreach ($attachment_common_show_images_list as $img{
  933.         $imgurl SM_PATH 'src/download.php' .
  934.                 '?' .
  935.                 'passed_id='     urlencode($img['passed_id'].
  936.                 '&amp;mailbox='       urlencode($mailbox.
  937.                 '&amp;ent_id=' urlencode($img['ent_id'].
  938.                 '&amp;absolute_dl=true';
  939.         $a array();
  940.         $a['Name'$img['name'];
  941.         $a['DisplayURL'$imgurl;
  942.         $a['DownloadURL'$img['download_href'];
  943.         $images[$a;
  944.     }
  945.     
  946.     $oTemplate->assign('images'$images);
  947.     $oTemplate->display('read_display_images_inline.tpl');
  948. }
  949.  
  950. formatMenuBar($aMailbox$passed_id$passed_ent_id$messagefalseFALSE);
  951.  
  952. do_hook('read_body_bottom');
  953. sqimap_logout($imapConnection);
  954. $oTemplate->display('footer.tpl');
  955. ?>

Documentation generated on Sat, 07 Oct 2006 16:13:14 +0300 by phpDocumentor 1.3.0RC6