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

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