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.283.2.31 2006/08/01 05:47:32 tokul Exp $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /**
  16.  * Path for SquirrelMail required files.
  17.  * @ignore
  18.  */
  19. define('SM_PATH','../');
  20.  
  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.  
  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. Used for finding the next
  34.  * and previous messages.
  35.  *
  36.  * @return the index of the next valid message from the array
  37.  */
  38. function findNextMessage($passed_id{
  39.     global $msort$msgs$sort,
  40.            $thread_sort_messages$allow_server_sort,
  41.            $server_sort_array;
  42.     if (!is_array($server_sort_array)) {
  43.         $thread_sort_messages 0;
  44.         $allow_server_sort FALSE;
  45.     }
  46.     $result = -1;
  47.     if ($thread_sort_messages || $allow_server_sort{
  48.         $count count($server_sort_array1;
  49.         foreach($server_sort_array as $key=>$value{
  50.             if ($passed_id == $value{
  51.                 if ($key == $count{
  52.                     break;
  53.                 }
  54.                 $result $server_sort_array[$key 1];
  55.                 break;
  56.             }
  57.         }
  58.     else {
  59.         if (is_array($msort)) {
  60.             for (reset($msort)($key key($msort))(isset($key))next($msort)) {
  61.                 if ($passed_id == $msgs[$key]['ID']{
  62.                     next($msort);
  63.                     $key key($msort);
  64.                     if (isset($key)){
  65.                         $result $msgs[$key]['ID'];
  66.                         break;
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     return $result;
  73. }
  74.  
  75. /** returns the index of the previous message from the array. */
  76. function findPreviousMessage($numMessages$passed_id{
  77.     global $msort$sort$msgs,
  78.            $thread_sort_messages,
  79.            $allow_server_sort$server_sort_array;
  80.     $result = -1;
  81.     if (!is_array($server_sort_array)) {
  82.         $thread_sort_messages 0;
  83.         $allow_server_sort FALSE;
  84.     }
  85.     if ($thread_sort_messages || $allow_server_sort {
  86.         foreach($server_sort_array as $key=>$value{
  87.             if ($passed_id == $value{
  88.                 if ($key == 0{
  89.                     break;
  90.                 }
  91.                 $result $server_sort_array[$key 1];
  92.                 break;
  93.             }
  94.         }
  95.     else {
  96.         if (is_array($msort)) {
  97.             for (reset($msort)($key key($msort))(isset($key))next($msort)) {
  98.                 if ($passed_id == $msgs[$key]['ID']{
  99.                     prev($msort);
  100.                     $key key($msort);
  101.                     if (isset($key)) {
  102.                         $result $msgs[$key]['ID'];
  103.                         break;
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     }
  109.     return $result;
  110. }
  111.  
  112. /**
  113.  * Displays a link to a page where the message is displayed more
  114.  * "printer friendly".
  115.  */
  116. function printer_friendly_link($mailbox$passed_id$passed_ent_id$color{
  117.     global $javascript_on;
  118.  
  119.     /* hackydiehack */
  120.     if!sqgetGlobalVar('view_unsafe_images'$view_unsafe_imagesSQ_GET) ) {
  121.         $view_unsafe_images false;
  122.     else {
  123.         $view_unsafe_images true;
  124.     }
  125.  
  126.     $params '?passed_ent_id=' urlencode($passed_ent_id.
  127.               '&mailbox=' urlencode($mailbox.
  128.               '&passed_id=' urlencode($passed_id).
  129.               '&view_unsafe_images='. (bool) $view_unsafe_images;
  130.  
  131.     $print_text _("View Printable Version");
  132.  
  133.     $result '';
  134.     /* Output the link. */
  135.     if ($javascript_on{
  136.         $result '<script language="javascript" type="text/javascript">' "\n" .
  137.                   '<!--' "\n" .
  138.                   "  function printFormat() {\n" .
  139.                   '    window.open("../src/printer_friendly_main.php' .
  140.                   $params '","Print","width=800,height=600");' "\n".
  141.                   "  }\n" .
  142.                   "// -->\n" .
  143.                   "</script>\n" .
  144.                   "<a href=\"javascript:printFormat();\">$print_text</a>\n";
  145.     else {
  146.         $result '<a target="_blank" href="../src/printer_friendly_bottom.php' .
  147.                   "$params\">$print_text</a>\n";
  148.     }
  149.     return $result;
  150. }
  151.  
  152. function ServerMDNSupport($read{
  153.     /* escaping $ doesn't work -> \x36 */
  154.     $ret preg_match('/(\x36MDNSent|\\\\\*)/i'$read);
  155.     return $ret;
  156. }
  157.  
  158. function SendMDN $mailbox$passed_id$sender$message$imapConnection{
  159.     global $username$attachment_dir$color,
  160.            $version$attachments$squirrelmail_language$default_charset,
  161.            $languages$useSendmail$domain$sent_folder,
  162.            $popuser$data_dir$username;
  163.  
  164.     sqgetGlobalVar('SERVER_NAME'$SERVER_NAMESQ_SERVER);
  165.  
  166.     $header $message->rfc822_header;
  167.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  168.  
  169.     $rfc822_header new Rfc822Header();
  170.     $content_type  new ContentType('multipart/report');
  171.     $content_type->properties['report-type']='disposition-notification';
  172.  
  173.     set_my_charset();
  174.     if ($default_charset{
  175.         $content_type->properties['charset']=$default_charset;
  176.     }
  177.     $rfc822_header->content_type $content_type;
  178.     $rfc822_header->to[$header->dnt;
  179.     $rfc822_header->subject _("Read:"' ' encodeHeader($header->subject);
  180.  
  181.     // FIX ME, use identity.php from SM 1.5. Change this also in compose.php
  182.  
  183.     $reply_to '';
  184.     if (isset($identity&& $identity != 'default'{
  185.         $from_mail getPref($data_dir$username,
  186.                              'email_address' $identity);
  187.         $full_name getPref($data_dir$username,
  188.                              'full_name' $identity);
  189.         $from_addr '"'.$full_name.'" <'.$from_mail.'>';
  190.         $reply_to  getPref($data_dir$username,
  191.                              'reply_to' $identity);
  192.     else {
  193.         $from_mail getPref($data_dir$username'email_address');
  194.         $full_name getPref($data_dir$username'full_name');
  195.         $from_addr '"'.$full_name.'" <'.$from_mail.'>';
  196.         $reply_to  getPref($data_dir$username,'reply_to');
  197.     }
  198.  
  199.     // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
  200.     // This merely comes from compose.php and only happens when there is no
  201.     // email_addr specified in user's identity (which is the startup config)
  202.     if (ereg("^([^@%/]+)[@%/](.+)$"$username$usernamedata)) {
  203.        $popuser $usernamedata[1];
  204.        $domain  $usernamedata[2];
  205.        unset($usernamedata);
  206.     else {
  207.        $popuser $username;
  208.     }
  209.  
  210.     if (!$from_mail{
  211.        $from_mail "$popuser@$domain";
  212.        $from_addr $from_mail;
  213.     }
  214.  
  215.     $rfc822_header->from $rfc822_header->parseAddress($from_addr,true);
  216.     if ($reply_to{
  217.        $rfc822_header->reply_to $rfc822_header->parseAddress($reply_to,true);
  218.     }
  219.  
  220.     // part 1 (RFC2298)
  221.     $senton getLongDateString$header->date );
  222.     $to_array $header->to;
  223.     $to '';
  224.     foreach ($to_array as $line{
  225.         $to .= ' '.$line->getAddress();
  226.     }
  227.     $now getLongDateStringtime() );
  228.     set_my_charset();
  229.     $body _("Your message""\r\n\r\n" .
  230.             "\t" _("To"': ' decodeHeader($to,false,false,true"\r\n" .
  231.             "\t" _("Subject"': ' decodeHeader($header->subject,false,false,true"\r\n" .
  232.             "\t" _("Sent"': ' $senton "\r\n" .
  233.             "\r\n" .
  234.             sprintf_("Was displayed on %s")$now );
  235.  
  236.     $special_encoding '';
  237.     if (isset($languages[$squirrelmail_language]['XTRA_CODE']&&
  238.         function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  239.         $body $languages[$squirrelmail_language]['XTRA_CODE']('encode'$body);
  240.         if (strtolower($default_charset== 'iso-2022-jp'{
  241.             if (mb_detect_encoding($body== 'ASCII'{
  242.                 $special_encoding '8bit';
  243.             else {
  244.                 $body mb_convert_encoding($body'JIS');
  245.                 $special_encoding '7bit';
  246.             }
  247.         }
  248.     elseif (sq_is8bit($body)) {
  249.         // detect 8bit symbols added by translations
  250.         $special_encoding '8bit';
  251.     }
  252.     $part1 new Message();
  253.     $part1->setBody($body);
  254.     $mime_header new MessageHeader;
  255.     $mime_header->type0 'text';
  256.     $mime_header->type1 'plain';
  257.     if ($special_encoding{
  258.         $mime_header->encoding $special_encoding;
  259.     else {
  260.         $mime_header->encoding 'us-ascii';
  261.     }
  262.     if ($default_charset{
  263.         $mime_header->parameters['charset'$default_charset;
  264.     }
  265.     $part1->mime_header $mime_header;
  266.  
  267.     // part2  (RFC2298)
  268.     $original_recipient  $to;
  269.     $original_message_id $header->message_id;
  270.  
  271.     $report "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
  272.     if ($original_recipient != ''{
  273.         $report .= "Original-Recipient : $original_recipient\r\n";
  274.     }
  275.     $final_recipient $sender;
  276.     $report .= "Final-Recipientrfc822$final_recipient\r\n.
  277.               "Original-Message-ID : $original_message_id\r\n.
  278.               "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
  279.  
  280.     $part2 new Message();
  281.     $part2->setBody($report);
  282.     $mime_header new MessageHeader;
  283.     $mime_header->type0 'message';
  284.     $mime_header->type1 'disposition-notification';
  285.     $mime_header->encoding 'us-ascii';
  286.     $part2->mime_header $mime_header;
  287.  
  288.     $composeMessage new Message();
  289.     $composeMessage->rfc822_header $rfc822_header;
  290.     $composeMessage->addEntity($part1);
  291.     $composeMessage->addEntity($part2);
  292.  
  293.  
  294.     if ($useSendmail{
  295.         require_once(SM_PATH 'class/deliver/Deliver_SendMail.class.php');
  296.         global $sendmail_path$sendmail_args;
  297.         // Check for outdated configuration
  298.         if (!isset($sendmail_args)) {
  299.             if ($sendmail_path=='/var/qmail/bin/qmail-inject'{
  300.                 $sendmail_args '';
  301.             else {
  302.                 $sendmail_args '-i -t';
  303.             }
  304.         }
  305.         $deliver new Deliver_SendMail(array('sendmail_args'=>$sendmail_args));
  306.         $stream $deliver->initStream($composeMessage,$sendmail_path);
  307.     else {
  308.         require_once(SM_PATH 'class/deliver/Deliver_SMTP.class.php');
  309.         $deliver new Deliver_SMTP();
  310.         if ($smtp_auth_mech == 'none'{
  311.             $user '';
  312.             $pass '';
  313.         else {
  314.             global $key$onetimepad;
  315.             $user $username;
  316.             $pass OneTimePadDecrypt($key$onetimepad);
  317.         }
  318.         $authPop (isset($pop_before_smtp&& $pop_before_smtptrue false;
  319.         $stream $deliver->initStream($composeMessage,$domain,0,
  320.                                        $smtpServerAddress$smtpPort$user$pass$authPop);
  321.     }
  322.     $success false;
  323.     if ($stream{
  324.         $length  $deliver->mail($composeMessage$stream);
  325.         $success $deliver->finalizeStream($stream);
  326.     }
  327.     if (!$success{
  328.         $msg  $deliver->dlv_msg '<br />' .
  329.                 _("Server replied:"' ' $deliver->dlv_ret_nr ' '.
  330.                 $deliver->dlv_server_msg;
  331.         require_once(SM_PATH 'functions/display_messages.php');
  332.         plain_error_message($msg$color);
  333.     else {
  334.         unset ($deliver);
  335.         if (sqimap_mailbox_exists ($imapConnection$sent_folder)) {
  336.             sqimap_append ($imapConnection$sent_folder$length);
  337.             require_once(SM_PATH 'class/deliver/Deliver_IMAP.class.php');
  338.             $imap_deliver new Deliver_IMAP();
  339.             $imap_deliver->mail($composeMessage$imapConnection);
  340.             sqimap_append_done ($imapConnection);
  341.             unset ($imap_deliver);
  342.         }
  343.     }
  344.     return $success;
  345. }
  346.  
  347. function ToggleMDNflag ($set ,$imapConnection$mailbox$passed_id$uid_support{
  348.     $sg   =  $set?'+':'-';
  349.     $cmd  'STORE ' $passed_id ' ' $sg 'FLAGS ($MDNSent)';
  350.     $read sqimap_run_command ($imapConnection$cmdtrue$response,
  351.                                 $readmessage$uid_support);
  352. }
  353.  
  354. function formatRecipientString($recipients$item {
  355.     global $show_more_cc$show_more$show_more_bcc,
  356.            $PHP_SELF;
  357.  
  358.     $string '';
  359.     if ((is_array($recipients)) && (isset($recipients[0]))) {
  360.         $show false;
  361.  
  362.         if ($item == 'to'{
  363.             if ($show_more{
  364.                 $show true;
  365.                 $url set_url_var($PHP_SELF'show_more',0);
  366.             else {
  367.                 $url set_url_var($PHP_SELF'show_more',1);
  368.             }
  369.         else if ($item == 'cc'{
  370.             if ($show_more_cc{
  371.                 $show true;
  372.                 $url set_url_var($PHP_SELF'show_more_cc',0);
  373.             else {
  374.                 $url set_url_var($PHP_SELF'show_more_cc',1);
  375.             }
  376.         else if ($item == 'bcc'{
  377.             if ($show_more_bcc{
  378.                 $show true;
  379.                 $url set_url_var($PHP_SELF'show_more_bcc',0);
  380.             else {
  381.                 $url set_url_var($PHP_SELF'show_more_bcc',1);
  382.             }
  383.         }
  384.  
  385.         $cnt count($recipients);
  386.         foreach($recipients as $r{
  387.             $add decodeHeader($r->getAddress(true));
  388.             if ($string{
  389.                 $string .= '<br />' $add;
  390.             else {
  391.                 $string $add;
  392.                 if ($cnt 1{
  393.                     $string .= '&nbsp;(<a href="'.$url;
  394.                     if ($show{
  395.                        $string .= '">'._("less").'</a>)';
  396.                     else {
  397.                        $string .= '">'._("more").'</a>)';
  398.                        break;
  399.                     }
  400.                 }
  401.             }
  402.         }
  403.     }
  404.     return $string;
  405. }
  406.  
  407. function formatEnvheader($mailbox$passed_id$passed_ent_id$message,
  408.                          $color$FirstTimeSee{
  409.     global $msn_user_support$default_use_mdn$default_use_priority,
  410.            $show_xmailer_default$mdn_user_support$PHP_SELF$javascript_on,
  411.            $squirrelmail_language;
  412.  
  413.     $header $message->rfc822_header;
  414.     $env array();
  415.     $env[_("Subject")decodeHeader($header->subject);
  416.     $from_name $header->getAddr_s('from');
  417.     if (!$from_name{
  418.         $from_name $header->getAddr_s('sender');
  419.         if (!$from_name{
  420.             $from_name _("Unknown sender");
  421.         }
  422.     }
  423.     $env[_("From")decodeHeader($from_name);
  424.     $env[_("Date")getLongDateString($header->date);
  425.     $env[_("To")formatRecipientString($header->to"to");
  426.     $env[_("Cc")formatRecipientString($header->cc"cc");
  427.     $env[_("Bcc")formatRecipientString($header->bcc"bcc");
  428.     if ($default_use_priority{
  429.         $env[_("Priority")htmlspecialchars(getPriorityStr($header->priority));
  430.     }
  431.     if ($show_xmailer_default{
  432.         $env[_("Mailer")decodeHeader($header->xmailer);
  433.     }
  434.     if ($default_use_mdn{
  435.         if ($mdn_user_support{
  436.             if ($header->dnt{
  437.                 if ($message->is_mdnsent{
  438.                     $env[_("Read receipt")_("sent");
  439.                 else {
  440.                     $env[_("Read receipt")_("requested");
  441.                     if (!(handleAsSent($mailbox||
  442.                           $message->is_deleted ||
  443.                           $passed_ent_id)) {
  444.                         $mdn_url $PHP_SELF;
  445.                         $mdn_url set_url_var($PHP_SELF'mailbox'urlencode($mailbox));
  446.                         $mdn_url set_url_var($PHP_SELF'passed_id'$passed_id);
  447.                         $mdn_url set_url_var($PHP_SELF'passed_ent_id'$passed_ent_id);
  448.                         $mdn_url set_url_var($PHP_SELF'sendreceipt'1);
  449.                         if ($FirstTimeSee && $javascript_on{
  450.                             $script  '<script language="JavaScript" type="text/javascript">' "\n";
  451.                             $script .= '<!--'"\n";
  452.                             $script .= 'if(window.confirm("' .
  453.                                        _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?".
  454.                                        '")) {  '."\n" .
  455.                                        '    sendMDN()'.
  456.                                        '}' "\n";
  457.                             $script .= '// -->'"\n";
  458.                             $script .= '</script>'"\n";
  459.                             echo $script;
  460.                         }
  461.                         $env[_("Read receipt").= '&nbsp;<a href="' $mdn_url '">[' .
  462.                                                    _("Send read receipt now"']</a>';
  463.                     }
  464.                 }
  465.             }
  466.         }
  467.     }
  468.  
  469.     $s  '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
  470.     $s .= ' align="center" bgcolor="'.$color[0].'">';
  471.     foreach ($env as $key => $val{
  472.         if ($val{
  473.             $s .= '<tr>';
  474.             $s .= html_tag('td''<b>' $key ':&nbsp;&nbsp;</b>''right''''valign="top" width="20%"'"\n";
  475.             $s .= html_tag('td'$val'left''''valign="top" width="80%"'"\n";
  476.             $s .= '</tr>';
  477.         }
  478.     }
  479.     echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
  480.          ' cellspacing="0" border="0" align="center">'."\n";
  481.     echo '<tr><td height="5" colspan="2" bgcolor="'.
  482.           $color[4].'"></td></tr><tr><td align="center">'."\n";
  483.     echo $s;
  484.     do_hook('read_body_header');
  485.     formatToolbar($mailbox$passed_id$passed_ent_id$message$color);
  486.     echo '</table>';
  487.     echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
  488.     echo '</table>';
  489. }
  490.  
  491. function formatMenubar($mailbox$passed_id$passed_ent_id$message$mbx_response{
  492.     global $base_uri$draft_folder$where$what$color$sort,
  493.            $startMessage$PHP_SELF$save_as_draft,
  494.            $enable_forward_as_attachment;
  495.  
  496.     $topbar_delimiter '&nbsp;|&nbsp;';
  497.     $urlMailbox urlencode($mailbox);
  498.     $s '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
  499.          ' border="0" bgcolor="'.$color[9].'"><tr>' .
  500.          html_tag'td''''left''''width="33%"' '<small>';
  501.  
  502.     $msgs_url $base_uri 'src/';
  503.     if (isset($where&& isset($what)) {
  504.         $msgs_url .= 'search.php?where=' urlencode($where.
  505.                      '&amp;what=' urlencode($what'&amp;mailbox=' $urlMailbox;
  506.         $msgs_str  _("Search Results");
  507.     else {
  508.         $msgs_url .= 'right_main.php?sort=' $sort '&amp;startMessage=' .
  509.                      $startMessage '&amp;mailbox=' $urlMailbox;
  510.         $msgs_str  _("Message List");
  511.     }
  512.     $s .= '<a href="' $msgs_url '">' $msgs_str '</a>';
  513.  
  514.     $delete_url $base_uri 'src/delete_message.php?mailbox=' $urlMailbox .
  515.                   '&amp;message=' $passed_id '&amp;';
  516.     if (!(isset($passed_ent_id&& $passed_ent_id)) {
  517.         if ($where && $what{
  518.             $delete_url .= 'where=' urlencode($where'&amp;what=' urlencode($what);
  519.         else {
  520.             $delete_url .= 'sort=' $sort '&amp;startMessage=' $startMessage;
  521.         }
  522.         $s .= $topbar_delimiter;
  523.         $s .= '<a href="' $delete_url '">' _("Delete"'</a>';
  524.     }
  525.  
  526.     $comp_uri 'src/compose.php' .
  527.                 '?passed_id=' $passed_id .
  528.                 '&amp;mailbox=' $urlMailbox .
  529.                 '&amp;startMessage=' $startMessage .
  530.                 (isset($passed_ent_id)?'&amp;passed_ent_id='.urlencode($passed_ent_id):'');
  531.  
  532.     if (($mailbox == $draft_folder&& ($save_as_draft)) {
  533.         $comp_alt_uri $comp_uri '&amp;smaction=draft';
  534.         $comp_alt_string _("Resume Draft");
  535.     else if (handleAsSent($mailbox)) {
  536.         $comp_alt_uri $comp_uri '&amp;smaction=edit_as_new';
  537.         $comp_alt_string _("Edit Message as New");
  538.     }
  539.     if (isset($comp_alt_uri)) {
  540.         $s .= $topbar_delimiter;
  541.         $s .= makeComposeLink($comp_alt_uri$comp_alt_string);
  542.     }
  543.  
  544.     $s .= '</small></td><td align="center" width="33%"><small>';
  545.  
  546.     if (!(isset($where&& isset($what)) && !$passed_ent_id{
  547.         $prev findPreviousMessage($mbx_response['EXISTS']$passed_id);
  548.         $next findNextMessage($passed_id);
  549.         if ($prev != -1{
  550.             $uri $base_uri 'src/read_body.php?passed_id='.$prev.
  551.                    '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  552.                    '&amp;startMessage='.$startMessage.'&amp;show_more=0';
  553.             $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
  554.         else {
  555.             $s .= _("Previous");
  556.         }
  557.         $s .= $topbar_delimiter;
  558.         if ($next != -1{
  559.             $uri $base_uri 'src/read_body.php?passed_id='.$next.
  560.                    '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  561.                    '&amp;startMessage='.$startMessage.'&amp;show_more=0';
  562.             $s .= '<a href="'.$uri.'">'._("Next").'</a>';
  563.         else {
  564.             $s .= _("Next");
  565.         }
  566.     else if (isset($passed_ent_id&& $passed_ent_id{
  567.         /* code for navigating through attached message/rfc822 messages */
  568.         $url set_url_var($PHP_SELF'passed_ent_id',0);
  569.         $s .= '<a href="'.$url.'">'._("View Message").'</a>';
  570.         $entities     array();
  571.         $entity_count array();
  572.         $c 0;
  573.  
  574.         foreach($message->parent->entities as $ent{
  575.             if ($ent->type0 == 'message' && $ent->type1 == 'rfc822'{
  576.                 $c++;
  577.                 $entity_count[$c$ent->entity_id;
  578.                 $entities[$ent->entity_id$c;
  579.             }
  580.         }
  581.  
  582.         $prev_link _("Previous");
  583.         if (!empty($entities[$passed_ent_id]&& ($entities[$passed_ent_id1)) {
  584.             $prev_ent_id $entity_count[$entities[$passed_ent_id1];
  585.             $prev_link   '<a href="'
  586.                          . set_url_var($PHP_SELF'passed_ent_id'$prev_ent_id)
  587.                          . '">' $prev_link '</a>';
  588.         }
  589.  
  590.         $next_link _("Next");
  591.         if (!empty($entities[$passed_ent_id]&& ($entities[$passed_ent_id$c)) {
  592.             $next_ent_id $entity_count[$entities[$passed_ent_id1];
  593.             $next_link   '<a href="'
  594.                          . set_url_var($PHP_SELF'passed_ent_id'$next_ent_id)
  595.                          . '">' $next_link '</a>';
  596.         }
  597.         $s .= $topbar_delimiter $prev_link;
  598.         $par_ent_id $message->parent->entity_id;
  599.         if ($par_ent_id{
  600.             $par_ent_id substr($par_ent_id,0,-2);
  601.             $s .= $topbar_delimiter;
  602.             $url set_url_var($PHP_SELF'passed_ent_id',$par_ent_id);
  603.             $s .= '<a href="'.$url.'">'._("Up").'</a>';
  604.         }
  605.         $s .= $topbar_delimiter $next_link;
  606.     }
  607.  
  608.     $s .= '</small></td>' "\n" .
  609.           html_tag'td''''right''''width="33%" nowrap' '<small>';
  610.     $comp_action_uri $comp_uri '&amp;smaction=forward';
  611.     $s .= makeComposeLink($comp_action_uri_("Forward"));
  612.  
  613.     if ($enable_forward_as_attachment{
  614.         $comp_action_uri $comp_uri '&amp;smaction=forward_as_attachment';
  615.         $s .= $topbar_delimiter;
  616.         $s .= makeComposeLink($comp_action_uri_("Forward as Attachment"));
  617.     }
  618.  
  619.     $comp_action_uri $comp_uri '&amp;smaction=reply';
  620.     $s .= $topbar_delimiter;
  621.     $s .= makeComposeLink($comp_action_uri_("Reply"));
  622.  
  623.     $comp_action_uri $comp_uri '&amp;smaction=reply_all';
  624.     $s .= $topbar_delimiter;
  625.     $s .= makeComposeLink($comp_action_uri_("Reply All"));
  626.     $s .= '</small></td></tr></table>';
  627.     $ret concat_hook_function('read_body_menu_top'$s);
  628.     if($ret != ''{
  629.         $s $ret;
  630.     }
  631.     echo $s;
  632.     do_hook('read_body_menu_bottom');
  633. }
  634.  
  635. function formatToolbar($mailbox$passed_id$passed_ent_id$message$color{
  636.     global $base_uri$where$what$download_and_unsafe_link;
  637.  
  638.     $urlMailbox urlencode($mailbox);
  639.     $urlPassed_id urlencode($passed_id);
  640.     $urlPassed_ent_id urlencode($passed_ent_id);
  641.  
  642.     $query_string 'mailbox=' $urlMailbox '&amp;passed_id=' $urlPassed_id '&amp;passed_ent_id=' $urlPassed_ent_id;
  643.  
  644.     if (!empty($where)) {
  645.         $query_string .= '&amp;where=' urlencode($where);
  646.     }
  647.  
  648.     if (!empty($what)) {
  649.         $query_string .= '&amp;what=' urlencode($what);
  650.     }
  651.  
  652.     $url $base_uri.'src/view_header.php?'.$query_string;
  653.  
  654.     $s  "<tr>\n" .
  655.           html_tag'td''''right''''valign="middle" width="20%"' '<b>' _("Options"":&nbsp;&nbsp;</b></td>\n" .
  656.           html_tag'td''''left''''valign="middle" width="80%"' '<small>' .
  657.           '<a href="'.$url.'">'._("View Full Header").'</a>';
  658.  
  659.     /* Output the printer friendly link if we are in subtle mode. */
  660.     $s .= '&nbsp;|&nbsp;' .
  661.           printer_friendly_link($mailbox$passed_id$passed_ent_id$color);
  662.     echo $s;
  663.  
  664.     /* Output the download and/or unsafe images link/-s, if any. */
  665.     if ($download_and_unsafe_link{
  666.         echo $download_and_unsafe_link;
  667.     }
  668.  
  669.     do_hook("read_body_header_right");
  670.     $s "</small></td>\n" .
  671.          "</tr>\n";
  672.     echo $s;
  673.  
  674. }
  675.  
  676. /***************************/
  677. /*   Main of read_body.php */
  678. /***************************/
  679.  
  680. /* get the globals we may need */
  681.  
  682. sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  683. sqgetGlobalVar('username',  $username,      SQ_SESSION);
  684. sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  685. sqgetGlobalVar('delimiter'$delimiter,     SQ_SESSION);
  686. sqgetGlobalVar('base_uri',  $base_uri,      SQ_SESSION);
  687.  
  688. sqgetGlobalVar('msgs',      $msgs,          SQ_SESSION);
  689. sqgetGlobalVar('msort',     $msort,         SQ_SESSION);
  690. sqgetGlobalVar('lastTargetMailbox'$lastTargetMailboxSQ_SESSION);
  691. sqgetGlobalVar('server_sort_array'$server_sort_arraySQ_SESSION);
  692. if (!sqgetGlobalVar('messages'$messagesSQ_SESSION) ) {
  693.     $messages array();
  694. }
  695.  
  696. /** GET VARS */
  697. sqgetGlobalVar('sendreceipt',   $sendreceipt,   SQ_GET);
  698. sqgetGlobalVar('where',         $where,         SQ_GET);
  699. sqgetGlobalVar('what',          $what,          SQ_GET);
  700. if sqgetGlobalVar('show_more'$temp,  SQ_GET) ) {
  701.     $show_more = (int) $temp;
  702. }
  703. if sqgetGlobalVar('show_more_cc'$temp,  SQ_GET) ) {
  704.     $show_more_cc = (int) $temp;
  705. }
  706. if sqgetGlobalVar('show_more_bcc'$temp,  SQ_GET) ) {
  707.     $show_more_bcc = (int) $temp;
  708. }
  709. if sqgetGlobalVar('view_hdr'$temp,  SQ_GET) ) {
  710.     $view_hdr = (int) $temp;
  711. }
  712.  
  713. /** POST VARS */
  714. sqgetGlobalVar('move_id',       $move_id,       SQ_POST);
  715.  
  716. /** GET/POST VARS */
  717. sqgetGlobalVar('passed_ent_id'$passed_ent_id);
  718. sqgetGlobalVar('mailbox',       $mailbox);
  719.  
  720. if sqgetGlobalVar('passed_id'$temp) ) {
  721.     $passed_id = (int) $temp;
  722. }
  723. if sqgetGlobalVar('sort'$temp) ) {
  724.     $sort = (int) $temp;
  725. }
  726. if sqgetGlobalVar('startMessage'$temp) ) {
  727.     $startMessage = (int) $temp;
  728. }
  729.  
  730. /* end of get globals */
  731. global $uid_support$sqimap_capabilities;
  732.  
  733. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0);
  734. $mbx_response   sqimap_mailbox_select($imapConnection$mailboxfalsefalsetrue);
  735.  
  736.  
  737. /**
  738.  * $message contains all information about the message
  739.  * including header and body
  740.  */
  741.  
  742. $uidvalidity $mbx_response['UIDVALIDITY'];
  743.  
  744. if (!isset($messages[$uidvalidity])) {
  745.    $messages[$uidvalidityarray();
  746. }
  747. if (!isset($messages[$uidvalidity][$passed_id]|| !$uid_support{
  748.    $message sqimap_get_message($imapConnection$passed_id$mailbox);
  749.    $FirstTimeSee !$message->is_seen;
  750.    $message->is_seen true;
  751.    $messages[$uidvalidity][$passed_id$message;
  752. else {
  753. //   $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
  754.       $message $messages[$uidvalidity][$passed_id];
  755.    $FirstTimeSee !$message->is_seen;
  756. }
  757.  
  758. if (isset($passed_ent_id&& $passed_ent_id{
  759.     $message $message->getEntity($passed_ent_id);
  760.     if ($message->type0 != 'message'  && $message->type1 != 'rfc822'{
  761.         $message $message->parent;
  762.     }
  763.     $read sqimap_run_command ($imapConnection"FETCH $passed_id BODY[$passed_ent_id.HEADER]"true$response$msg$uid_support);
  764.     $rfc822_header new Rfc822Header();
  765.     $rfc822_header->parseHeader($read);
  766.     $message->rfc822_header $rfc822_header;
  767. else {
  768.     $passed_ent_id 0;
  769. }
  770. $header $message->header;
  771.  
  772. do_hook('html_top');
  773.  
  774. /****************************************/
  775. /* Block for handling incoming url vars */
  776. /****************************************/
  777.  
  778. if (isset($sendreceipt)) {
  779.    if !$message->is_mdnsent {
  780.       if (isset($identity) ) {
  781.          $final_recipient getPref($data_dir$username'email_address0''' );
  782.       else {
  783.          $final_recipient getPref($data_dir$username'email_address''' );
  784.       }
  785.  
  786.       $final_recipient trim($final_recipient);
  787.       if ($final_recipient == '' {
  788.          $final_recipient getPref($data_dir$username'email_address''' );
  789.       }
  790.       $supportMDN ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
  791.       if SendMDN$mailbox$passed_id$final_recipient$message$imapConnection && $supportMDN {
  792.          ToggleMDNflagtrue$imapConnection$mailbox$passed_id$uid_support);
  793.          $message->is_mdnsent true;
  794.          $messages[$uidvalidity][$passed_id]=$message;
  795.       }
  796.    }
  797. }
  798. /***********************************************/
  799. /* End of block for handling incoming url vars */
  800. /***********************************************/
  801.  
  802. $msgs[$passed_id]['FLAG_SEEN'true;
  803.  
  804. $messagebody '';
  805. do_hook('read_body_top');
  806. if ($show_html_default == 1{
  807.     $ent_ar $message->findDisplayEntity(array());
  808. else {
  809.     $ent_ar $message->findDisplayEntity(array()array('text/plain'));
  810. }
  811. $cnt count($ent_ar);
  812. for ($i 0$i $cnt$i++{
  813.    $messagebody .= formatBody($imapConnection$message$color$wrap_at$ent_ar[$i]$passed_id$mailbox);
  814.    if ($i != $cnt-1{
  815.        $messagebody .= '<hr noshade size=1>';
  816.    }
  817. }
  818.  
  819. displayPageHeader($color$mailbox);
  820. formatMenuBar($mailbox$passed_id$passed_ent_id$message$mbx_response);
  821. formatEnvheader($mailbox$passed_id$passed_ent_id$message$color$FirstTimeSee);
  822. echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
  823. echo '  <tr><td>';
  824. echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
  825. echo '      <tr><td>';
  826. echo '        <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
  827. echo '          <tr bgcolor="'.$color[4].'"><td>';
  828. // echo '            <table cellpadding="1" cellspacing="5" align="left" border="0">';
  829. echo html_tag'table' ,'' 'left''''cellpadding="1" cellspacing="5" border="0"' );
  830. echo '              <tr>' html_tag'td''<br />'$messagebody."\n"'left')
  831.                         . '</tr>';
  832. echo '            </table>';
  833. echo '          </td></tr>';
  834. echo '        </table></td></tr>';
  835. echo '    </table>';
  836. echo '  </td></tr>';
  837.  
  838. echo '<tr><td height="5" colspan="2" bgcolor="'.
  839.           $color[4].'"></td></tr>'."\n";
  840.  
  841. $attachmentsdisplay formatAttachments($message,$ent_ar,$mailbox$passed_id);
  842. if ($attachmentsdisplay{
  843.    echo '  <tr><td>';
  844.    echo '    <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
  845.    echo '     <tr><td>';
  846.    echo '       <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
  847.    echo '        <tr>' html_tag'td''''left'$color[9);
  848.    echo '           <b>' _("Attachments"':</b>';
  849.    echo '        </td></tr>';
  850.    echo '        <tr><td>';
  851.    echo '          <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
  852.    echo              $attachmentsdisplay;
  853.    echo '          </td></tr></table>';
  854.    echo '       </td></tr></table>';
  855.    echo '    </td></tr></table>';
  856.    echo '  </td></tr>';
  857.    echo '<tr><td height="5" colspan="2" bgcolor="'.
  858.           $color[4].'"></td></tr>';
  859. }
  860. echo '</table>';
  861.  
  862. /* show attached images inline -- if pref'fed so */
  863. if (($attachment_common_show_images&&
  864.     is_array($attachment_common_show_images_list)) {
  865.     foreach ($attachment_common_show_images_list as $img{
  866.         $imgurl SM_PATH 'src/download.php' .
  867.                 '?' .
  868.                 'passed_id='     urlencode($img['passed_id'].
  869.                 '&amp;mailbox='       urlencode($mailbox.
  870.                 '&amp;ent_id=' urlencode($img['ent_id'].
  871.                 '&amp;absolute_dl=true';
  872.  
  873.         echo html_tag'table'"\n" .
  874.                     html_tag'tr'"\n" .
  875.                         html_tag'td''<img src="' $imgurl '" />' ."\n"'left'
  876.                         )
  877.                     ,
  878.         'center''''cellspacing="0" border="0" cellpadding="2"');
  879.     }
  880. }
  881.  
  882. do_hook('read_body_bottom');
  883. do_hook('html_bottom');
  884. sqimap_logout($imapConnection);
  885. /* sessions are written at the end of the script. it's better to register
  886.    them at the end so we avoid double session_register calls */
  887. sqsession_register($messages,'messages');
  888.  
  889. ?>
  890. </body></html>

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