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

Documentation generated on Mon, 13 Jan 2020 04:25:12 +0100 by phpDocumentor 1.4.3