Source for file message_details_bottom.php

Documentation is available at message_details_bottom.php

  1. <?php
  2. /**
  3.  * Message Details plugin - bottom frame with message structure and rfc822 body
  4.  *
  5.  * Plugin to view the RFC822 raw message output and the bodystructure of a message
  6.  *
  7.  * Licensed under the GNU GPL. For full terms see the file COPYING.
  8.  *
  9.  * @author Marc Groot Koerkamp
  10.  * @copyright 2002 Marc Groot Koerkamp, The Netherlands
  11.  * @copyright 2004-2020 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: message_details_bottom.php 14840 2020-01-07 07:42:38Z pdontthink $
  14.  * @package plugins
  15.  * @subpackage message_details
  16.  */
  17.  
  18. /** @ignore */
  19. define('SM_PATH','../../');
  20.  
  21. /* SquirrelMail required files. */
  22. require_once(SM_PATH 'include/validate.php');
  23. require_once(SM_PATH 'functions/imap.php');
  24. require_once(SM_PATH 'functions/mime.php');
  25.  
  26. global $color$uid_support;
  27.  
  28. sqgetGlobalVar('passed_id'$passed_idSQ_GET);
  29. if (!sqGetGlobalVar('passed_ent_id'$passed_ent_idSQ_FORM))
  30.     $passed_ent_id 0;
  31. sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  32.  
  33. sqgetGlobalVar('username'$usernameSQ_SESSION);
  34. sqgetGlobalVar('key'$keySQ_COOKIE);
  35. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  36. global $imap_stream_options// in case not defined in config
  37.  
  38. /**
  39.  * Calculates id of MIME entity
  40.  * @param string $entString 
  41.  * @param integer $direction 
  42.  * @return string 
  43.  * @access private
  44.  */
  45. function CalcEntity($entString$direction{
  46.     $result $entString;
  47.     if ($direction == -1{
  48.         $pos strrpos($entString,'.');
  49.         $result substr($entString,0,$pos);
  50.     }
  51.  
  52.     switch ($direction{
  53.        case 0:
  54.           $pos strrpos($entString,'.');
  55.           if ($pos === false{
  56.          $entString++;
  57.          $result$entString;
  58.           
  59.       else {
  60.              $level substr($entString,0,$pos);
  61.          $sublevel substr($entString,$pos+1);
  62.          $sublevel++;
  63.          $result "$level".'.'."$sublevel";
  64.       }
  65.       break;
  66.        case 1:
  67.           $result "$entString".".0";
  68.       break;
  69.        default:
  70.           break;
  71.     }
  72.     return ($result);
  73. }
  74.  
  75. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  76. $read sqimap_mailbox_select($imapConnection$mailbox);
  77. if (!empty($passed_ent_id))
  78.     $body sqimap_run_command($imapConnection"FETCH $passed_id BODY[$passed_ent_id]",true$response$readmessage$uid_support);
  79. else
  80.     $body sqimap_run_command($imapConnection"FETCH $passed_id RFC822",true$response$readmessage$uid_support);
  81. $message_body '';
  82. $header false;
  83. $mimepart false;
  84. $bnd_end false;
  85. $messageheader true;
  86. $messageheaderstart=false;
  87. $boundaries array();
  88. $entities array();
  89. $pre '<b>';
  90. $end '</b>';
  91. $entStr '';
  92. $bla ='';
  93. $content array ();
  94. $content_indx = -1;
  95. $contentset false;
  96.  
  97. $count=count($body);
  98. $body[$count-1substr($body[$count-1]-1);
  99. for ($i=1$i $count$i++{
  100.     $line trim($body[$i]);
  101.     if ($line == ''{
  102.     $pre '';
  103.     $end '';
  104.         if ($bnd_end{
  105.         $header true;
  106.         $mimepart false;
  107.     else if ($messageheader{
  108.         if ($header{
  109.         $header=false;
  110.         $end "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n"
  111.         }
  112.         $mimepart = -$header;
  113.         $bnd_end false;
  114.         if ($messageheaderstart{
  115.         $messageheaderstart=false;
  116.         }
  117.     else if ($messageheaderstart{
  118.         $messageheaderfalse;
  119.     else {
  120.         if ($header{
  121.             $pre '';
  122.         $end "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n"
  123.         }
  124.         $header false;
  125.         $mimepart=true;
  126.     }  
  127.     $contentset false;
  128.     $nameset false;
  129.     else {
  130.         if (!$header && $messageheader{
  131.         $messageheaderstart=true;
  132.         if ($pre != '<b>'{
  133.         $pre '<i><font color ='."$color[1]>";
  134.         $end '</font></i>';
  135.         }
  136.     }     
  137.     if (!$messageheader && !$header {
  138.         $mimepart=true;
  139.     }  else {
  140.         $mimepart=false;
  141.     }
  142.     $pre '';
  143.     $end '';
  144.     }
  145.     if (  ( $header || $messageheader&& (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) )  {
  146.         $bnd $reg[1];
  147.         $bndreg $bnd;    
  148.         $bndreg str_replace("\\","\\\\",$bndreg);    
  149.         $bndreg str_replace("?","\\?",$bndreg);
  150.         $bndreg str_replace("+","\\+",$bndreg);        
  151.         $bndreg str_replace(".","\\.",$bndreg);            
  152.         $bndreg str_replace("/","\\/",$bndreg);
  153.         $bndreg str_replace("-","\\-",$bndreg);
  154.         $bndreg str_replace("(","\\(",$bndreg);
  155.         $bndreg str_replace(")","\\)",$bndreg);
  156.  
  157.         $boundaries[array'bnd' => $bnd'bndreg' => $bndreg);
  158.         $messageheader false;
  159.         $messageheaderstart=false;
  160.         $mimepart=false;
  161.         if ($entStr==''{
  162.             $entStr='0';
  163.         else {
  164.             $entStr CalcEntity("$entStr",1);
  165.         }
  166.     }
  167.     
  168.     if (($line != '' && $line{0== '-' || $header)  && isset($boundaries[0])) {
  169.         $cnt=count($boundaries)-1;
  170.     $bnd $boundaries[$cnt]['bnd'];
  171.     $bndreg $boundaries[$cnt]['bndreg'];
  172.       
  173.     $regstr '/^--'."($bndreg)".".*".'/';
  174.     if (preg_match($regstr,$line,$reg) ) {
  175.         $bndlen strlen($reg[1]);
  176.         $bndend false;        
  177.             if (strlen($line($bndlen 3)) {
  178.         if ($line{$bndlen+2== '-' && $line{$bndlen+3== '-'
  179.             $bndend true;
  180.         }
  181.         if ($bndend{
  182.             $entStr CalcEntity("$entStr",-1);
  183.             array_pop($boundaries);
  184.             $pre .= '<b><font color ='."$color[2]>";
  185.             $end .= '</font></b>';
  186.             $header true;
  187.             $mimepart false;
  188.             $bnd_end true;
  189.             $encoding '';
  190.         else {
  191.             $header true;
  192.             $bnd_end false;
  193.             $entStr CalcEntity("$entStr",0);
  194.             $content_indx++;
  195.             $content[$content_indx]=array();        
  196.             $content[$content_indx]['ent''<a href="#' $entStr '">' $entStr '</a>';
  197.             $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" id="'.
  198.                 $entStr.'H"><a name="'."$entStr".'"></a><b><font color ='."$color[2]>";
  199.             $end .= '</font></b>'."\n";
  200.             $header true;
  201.             $mimepart false;
  202.             $encoding '';
  203.         }
  204.     }  else {
  205.         if ($header{
  206.         if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
  207.             if (strtolower($reg[2]== 'message' && strtolower($reg[3]== 'rfc822'{
  208.             $messageheader true;
  209.             }
  210.             $content[$content_indx]['type'"$reg[2]/$reg[3]";
  211.             $contentset true;
  212.             if ($reg[2== 'image'{
  213.             $entities["$entStr"array();
  214.             $entities["$entStr"]['entity'$entStr;
  215.             $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
  216.             }    
  217.            else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
  218.             $name sm_encode_html_special_chars($reg[2]);
  219.             $content[$content_indx]['name'decodeHeader($name);
  220.             $nameset true;
  221.             if (isset($entities["$entStr"])) {
  222.             $entities["$entStr"]['name'urlEncode($reg[2]);
  223.             }
  224.            else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
  225.             $encoding $reg[2];
  226.             if (isset($entities["$entStr"])) {
  227.             $entities["$entStr"]['encoding']=$reg[2];
  228.             }
  229.             $content[$content_indx]['encoding'$encoding;
  230.             $mimeentity '';
  231.         }
  232.  
  233.         $pre .= '<b><font color ='."$color[7]>";
  234.         $end .= '</font></b>';
  235.         //$mimepart=false;
  236.         }           
  237.     }
  238.     }  
  239. /*
  240.     if ($mimepart) {
  241.         if (isset($entities["$entStr"])) {
  242.         if (isset($encoding) && $encoding == 'base64') {
  243.             if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = '';
  244.         $entities["$entStr"]['content'] .= $line;
  245.         }
  246.         }
  247.     }     
  248. */
  249.     $line sm_encode_html_special_chars($line);
  250.     $message_body .= "$pre"."$line"."$end".'<br />'."\r\n";
  251. }
  252.  
  253. $xtra = <<<ECHO
  254.  
  255. <style>
  256.  
  257. <!--
  258. .ent_body {
  259.   display:inline;
  260. }
  261.  
  262. .header {
  263.   display:inline;
  264. }
  265.  
  266. .entheader {
  267.   display:inline;
  268.   width:99%;
  269. }
  270. //-->
  271.  
  272. </style>
  273.  
  274. ECHO;
  275.  
  276. displayHtmlHeader_("Message Details")$xtraFALSE );
  277. /* body */
  278. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
  279. echo '<code>'."\n";
  280. echo '<font face = "monospace">'."\n";
  281. echo '<br />'."\n";
  282.  
  283. if (count($content0{
  284.     echo '<h2>' _("Bodystructure""</h2>\n\n";
  285.     echo '<table border=1 width="98%"><thead>'.
  286.       '<tr bgcolor="'."$color[7]".'">'.
  287.         '<td><b><font color="'."$color[5]".'">' _("Entity"'</font></b></td>'.
  288.         '<td><b><font color="'."$color[5]".'">' _("Content-Type"'</font></b></td>'.
  289.         '<td><b><font color="'."$color[5]".'">' _("Name"'</font></b></td>'.
  290.         '<td><b><font color="'."$color[5]".'">' _("Encoding"'</font></b></td>'.
  291.  
  292.       '</tr>'.
  293.       '</thead><tbody>';
  294.     for ($i 0$i count($content);$i++{
  295.     echo '<tr><td>';
  296.     echo $content[$i]['ent'].'</td><td>';
  297.     if (isset($content[$i]['type'])) {
  298.         echo $content[$i]['type'];
  299.     else echo 'TEXT/PLAIN';
  300.     echo '</td><td>';
  301.     if (isset($content[$i]['name'])) {
  302.         echo $content[$i]['name'];
  303.     else echo '&nbsp;';
  304.     echo '</td><td>';
  305.     if (isset($content[$i]['encoding'])) {
  306.         echo $content[$i]['encoding'];
  307.     else echo '&nbsp;';
  308.     echo '</td></tr>'."\n";
  309.     }
  310.     echo '</tbody></table><br>'."\n";
  311. }
  312. echo '<h2>' _("RFC822 Message body""</h2>\n\n";
  313. echo '<div><div class="header">'."\n\n";
  314. echo $message_body;
  315. echo '</div></div></font></code></body></html>';
  316. ?>

Documentation generated on Mon, 13 Jan 2020 04:24:57 +0100 by phpDocumentor 1.4.3