Happy New Year
[squirrelmail.git] / plugins / message_details / message_details_bottom.php
index b6d897c2f9c451f605ffccb1d2d9a8ad1827b39f..3b7640fa0c36a330f8366fdf47dc26b0a68b0746 100644 (file)
@@ -6,13 +6,14 @@
  * Plugin to view the RFC822 raw message output and the bodystructure of a message
  *
  * @author Marc Groot Koerkamp
- * @copyright © 2002 Marc Groot Koerkamp, The Netherlands
- * @copyright © 2002-2006 The SquirrelMail Project Team
+ * @copyright 2002 Marc Groot Koerkamp, The Netherlands
+ * @copyright 2002-2020 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage message_details
  */
+//FIXME: this file uses HTML extensively and eventually needs to be "templatized" (don't echo HTML directly)
 
 /**
  * Include the SquirrelMail initialization file.
@@ -32,13 +33,16 @@ global $msgd_8bit_in_hex;
 $msgd_8bit_in_hex=false;
 
 if (!empty($md_action)) {
-    sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
+    sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
+    if (!sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET))
+        $passed_ent_id = 0;
     sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
     /* 
-     * add third function argument, if you want to see 
+     * change $unformatted to TRUE if you want to see 
      * message source without formating
      */
-    echo get_message_details($mailbox, $passed_id);
+    $unformatted = FALSE;
+    echo get_message_details($mailbox, $passed_id, $passed_ent_id, $unformatted);
 }
 
 
@@ -100,22 +104,25 @@ function CalcEntity($entString, $direction) {
  * Returns actual message details
  * @param string $mailbox
  * @param string $passed_id
+ * @param string $passed_ent_id
  * @param boolean $stripHTML If TRUE, only plain text is returned,
  *                           default is FALSE, wherein output contains
  *                           pretty-HTMLification of message body
  * @return string The formatted message details
  * @access public
  */
-function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
-    global $imapServerAddress, $imapPort, $color,$msgd_8bit_in_hex;
+function get_message_details($mailbox, $passed_id, $passed_ent_id=0, $stripHTML=FALSE) {
+    global $imapServerAddress, $imapPort, $imap_stream_options,
+           $color,$msgd_8bit_in_hex, $username;
 
     $returnValue = '';
 
-    sqgetGlobalVar('username', $username, SQ_SESSION);
-
-    $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
+    $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
     $read = sqimap_mailbox_select($imapConnection, $mailbox);
-    $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
+    if (!empty($passed_ent_id))
+        $body = sqimap_run_command($imapConnection, "FETCH $passed_id BODY[$passed_ent_id]",true, $response, $readmessage, TRUE);
+    else
+        $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
     $message_body = '';
     $header = false;
     $mimepart = false;
@@ -124,7 +131,7 @@ function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
     $messageheaderstart=false;
     $boundaries = array();
     $entities = array();
-    session_unregister("entities");
+    sqsession_unregister("entities");
     $pre = '<b>';
     $end = '</b>';
     $entStr = '';
@@ -232,9 +239,9 @@ function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
                     $entStr = CalcEntity("$entStr",0);
                     $content_indx++;
                     $content[$content_indx]=array();
-                    $content[$content_indx]['ent'] = '<a href="#'."$entStr \">$entStr".'</a>';
+                    $content[$content_indx]['ent'] = '<a href="#' . $entStr . '">' . $entStr . '</a>';
                     $pre .= '</div><div class="entheader" id="'.
-                        $entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
+                        $entStr.'H"><a name="'."$entStr".'"></a><b><font color="'.$color[2].'">';
                     $end .= '</font></b>';
                     $header = true;
                     $mimepart = false;
@@ -254,7 +261,7 @@ function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
                             $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
                         }
                     } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
-                        $name = htmlspecialchars($reg[2]);
+                        $name = sm_encode_html_special_chars($reg[2]);
                         $content[$content_indx]['name'] = decodeHeader($name);
                         $nameset = true;
                         if (isset($entities["$entStr"])) {
@@ -279,7 +286,7 @@ function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
         if ($stripHTML) {
             $message_body .= $line . "\r\n";
         } else {
-            $line = htmlspecialchars($line);
+            $line = sm_encode_html_special_chars($line);
             if ($msgd_8bit_in_hex) $line = msgd_convert_to_hex($line);
             $message_body .= "$pre"."$line"."$end"."\r\n";
         }
@@ -289,7 +296,6 @@ function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
 $xtra = <<<ECHO
 
 <style type="text/css">
-
 <!--
 .ent_body {
   display:inline;
@@ -303,8 +309,7 @@ $xtra = <<<ECHO
   display:inline;
   width:99%;
 }
-//-->
-
+-->
 </style>
 
 ECHO;
@@ -368,4 +373,3 @@ ECHO;
     }
     return $returnValue;
 }
-?>
\ No newline at end of file