Added Message details plugin to CVS
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 Sep 2002 13:44:57 +0000 (13:44 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 Sep 2002 13:44:57 +0000 (13:44 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3566 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/message_details/message_details_bottom.php [new file with mode: 0644]
plugins/message_details/message_details_main.php [new file with mode: 0644]
plugins/message_details/message_details_top.php [new file with mode: 0644]
plugins/message_details/setup.php [new file with mode: 0644]

diff --git a/plugins/message_details/message_details_bottom.php b/plugins/message_details/message_details_bottom.php
new file mode 100644 (file)
index 0000000..f70ea3f
--- /dev/null
@@ -0,0 +1,316 @@
+<?php
+
+/** Message Source  
+*
+* Plugin to view the RFC822 raw message output and the bodystructure of a message
+*
+* Copyright (c) 2002 Marc Groot Koerkamp, The Netherlands
+* Licensed under the GNU GPL. For full terms see the file COPYING.
+* 
+* $Id$
+**/
+
+
+//require_once('./message_viewentity.php');
+chdir('..');
+require_once('../functions/imap.php');
+require_once('../functions/mime.php');
+require_once('../config/config.php');
+require_once('../src/validate.php');
+require_once('../src/load_prefs.php');
+
+global $color, $uid_support;
+
+function CalcEntity($entString, $direction) {
+    $result = $entString;
+    if ($direction == -1) {
+         $pos = strrpos($entString,'.');
+         $result = substr($entString,0,$pos);
+    }
+
+    switch ($direction) {
+       case 0:
+          $pos = strrpos($entString,'.');
+          if ($pos === false) {
+            $entString++;
+            $result= $entString;
+          } 
+         else {
+             $level = substr($entString,0,$pos);
+            $sublevel = substr($entString,$pos+1);
+            $sublevel++;
+            $result = "$level".'.'."$sublevel";
+         }
+         break;
+       case 1:
+          $result = "$entString".".0";
+         break;
+       default:
+          break;
+    }
+    return ($result);
+}
+
+function returnTime($start) {
+ $stop = gettimeofday();
+ $timepassed =  1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
+ return $timepassed;
+}
+
+function GetMimeProperties($header) {
+}
+
+$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+$read = sqimap_mailbox_select($imapConnection, $mailbox);
+$start = gettimeofday();
+$body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, $uid_support);
+$message_body = '';
+$header = false;
+$mimepart = false;
+$bnd_end = false;
+$messageheader = true;
+$messageheaderstart=false;
+$boundaries = array();
+$entities = array();
+session_unregister("entities");
+$pre = '<b>';
+$end = '</b>';
+$entStr = '';
+$bla ='';
+$content = array ();
+$content_indx = -1;
+$contentset = false;
+
+$count=count($body);
+$body[$count-1] = substr($body[$count-1], -1);
+for ($i=1; $i < $count; $i++) {
+    $line = trim($body[$i]);
+    if ($line == '') {
+       $pre = '';
+       $end = '';
+        if ($bnd_end) {
+           $header = true;
+           $mimepart = false;
+       } else if ($messageheader) {
+           if ($header) {
+               $header=false;
+               $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" ID="'.$entStr.'B">'."\n \n"; 
+           }
+           $mimepart = -$header;
+           $bnd_end = false;
+           if ($messageheaderstart) {
+               $messageheaderstart=false;
+           }
+       } else if ($messageheaderstart) {
+           $messageheader= false;
+       } else {
+           if ($header) {
+               $pre = '';
+               $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" ID="'.$entStr.'B">'."\n \n"; 
+           }
+           $header = false;
+           $mimepart=true;
+       }  
+       $contentset = false;
+       $nameset = false;
+    } else {
+        if (!$header && $messageheader) {
+           $messageheaderstart=true;
+           if ($pre != '<b>') {
+               $pre = '<i><font color ='."$color[1]>";
+               $end = '</i></font>';
+           }
+       }     
+       if (!$messageheader && !$header ) {
+           $mimepart=true;
+       }  else {
+           $mimepart=false;
+       }
+       $pre = '';
+       $end = '';
+    }
+    if (  ( $header || $messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) )  {
+       $bnd = $reg[1];
+       $bndreg = $bnd;    
+       $bndreg = str_replace("\\","\\\\",$bndreg);     
+       $bndreg = str_replace("?","\\?",$bndreg);
+       $bndreg = str_replace("+","\\+",$bndreg);               
+       $bndreg = str_replace(".","\\.",$bndreg);                       
+       $bndreg = str_replace("/","\\/",$bndreg);
+       $bndreg = str_replace("-","\\-",$bndreg);
+       $bndreg = str_replace("(","\\(",$bndreg);
+       $bndreg = str_replace(")","\\)",$bndreg);
+
+       $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg);
+       $messageheader = false;
+       $messageheaderstart=false;
+       $mimepart=false;
+       if ($entStr=='') {
+           $entStr='0';
+       } else {
+           $entStr = CalcEntity("$entStr",1);
+       }
+    }
+    
+    if (($line != '' && $line{0} == '-' || $header)  && isset($boundaries[0])) {
+        $cnt=count($boundaries)-1;
+       $bnd = $boundaries[$cnt]['bnd'];
+       $bndreg = $boundaries[$cnt]['bndreg'];
+      
+       $regstr = '/^--'."($bndreg)".".*".'/';
+       if (preg_match($regstr,$line,$reg) ) {
+           $bndlen = strlen($reg[1]);
+           $bndend = false;        
+            if (strlen($line) > ($bndlen + 3)) {
+               if ($line{$bndlen+2} == '-' && $line{$bndlen+3} == '-') 
+                   $bndend = true;
+           }
+           if ($bndend) {
+               $entStr = CalcEntity("$entStr",-1);
+               array_pop($boundaries);
+               $pre .= '<b><font color ='."$color[2]>";
+               $end .= '</font></b>';
+               $header = true;
+               $mimepart = false;
+               $bnd_end = true;
+               $encoding = '';
+           } else {
+               $header = true;
+               $bnd_end = false;
+               $entStr = CalcEntity("$entStr",0);
+               $content_indx++;
+               $content[$content_indx]=array();                
+               $content[$content_indx]['ent'] = '<A HREF="#'."$entStr \">$entStr".'</a>';
+               $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" ID="'.$entStr.'H"><a name="'."$entStr".'"><b><font color ='."$color[2]>";
+               $end .= '</font></b>'."\n";
+               $header = true;
+               $mimepart = false;
+               $encoding = '';
+           }
+       }  else {
+           if ($header) {
+               if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
+                   if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') {
+                       $messageheader = true;
+                   }
+                   $content[$content_indx]['type'] = "$reg[2]/$reg[3]";
+                   $contentset = true;
+                   if ($reg[2] == 'image') {
+                       $entities["$entStr"] = array();
+                       $entities["$entStr"]['entity'] = $entStr;
+                       $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
+                   }   
+               } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
+                   $name = htmlspecialchars($reg[2]);
+                   $content[$content_indx]['name'] = decodeHeader($name);
+                   $nameset = true;
+                   if (isset($entities["$entStr"])) {
+                       $entities["$entStr"]['name'] = urlEncode($reg[2]);
+                   }
+               } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
+                   $encoding = $reg[2];
+                   if (isset($entities["$entStr"])) {
+                       $entities["$entStr"]['encoding']=$reg[2];
+                   }
+                   $content[$content_indx]['encoding'] = $encoding;
+                   $mimeentity = '';
+               }
+
+               $pre .= '<b><font color ='."$color[7]>";
+               $end .= '</font></b>';
+               //$mimepart=false;
+           }             
+       }
+    }  
+/*
+    if ($mimepart) {
+       if (isset($entities["$entStr"])) {
+           if (isset($encoding) && $encoding == 'base64') {
+               if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = '';
+               $entities["$entStr"]['content'] .= $line;
+           }
+        }
+    }  
+*/
+    $line = htmlspecialchars($line);
+    $message_body .= "$pre"."$line"."$end".'<BR>'."\r\n";
+}
+//echo returnTime($start).'<BR>';
+$xtra = <<<ECHO
+
+<STYLE>
+
+<!--
+.ent_body {
+  display:inline;
+}
+
+.header {
+  display:inline;
+}
+
+.entheader {
+  display:inline;
+  margin-bottom:1em;
+  padding-bottom:1em;
+  border-style: solid none solid none;
+  border-width:0.1em;
+  width:99%;
+}
+//-->
+
+</STYLE>
+
+ECHO;
+
+displayHtmlHeader( _("Message Details"), $xtra, FALSE );
+/* body */
+echo '<body><code>'."\n";
+echo '<font face = "monospace">'."\n";
+echo '<BR>'."\n";
+//session_register("entities");
+//$keys = array_keys($entities);
+//$start = gettimeofday();
+//foreach ($keys as $key) {
+//    if (isset($entities[$key])) {
+//    if ($entities[$key]['encoding'] == 'base64') {
+//     echo '<img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&amp;name='.$entities[$key]['name'].'"><br>';
+//    }
+//    }
+//}
+//session_unregister("entities");
+
+if (count($content) > 0) {
+    echo '<h2> Bodystructure </h2>'."\n\n";
+    echo '<table border=1 width="98%"><thead>'.
+         '<tr bgcolor="'."$color[7]".'">'.
+           '<td><b><font color="'."$color[5]".'">Entity</font></b></td>'.
+           '<td><b><font color="'."$color[5]".'">Content-Type</font></b></td>'.
+           '<td><b><font color="'."$color[5]".'">Name</font></b></td>'.
+           '<td><b><font color="'."$color[5]".'">Encoding</font></b></td>'.
+
+         '</tr>'.
+         '</thead><tbody>';
+    for ($i = 0; $i < count($content);$i++) {
+       echo '<tr><td>';
+       echo $content[$i]['ent'].'</td><td>';
+       if (isset($content[$i]['type'])) {
+           echo $content[$i]['type'];
+       } else echo 'TEXT/PLAIN';
+       echo '</td><td>';
+       if (isset($content[$i]['name'])) {
+           echo $content[$i]['name'];
+       } else echo '&nbsp';
+       echo '</td><td>';
+       if (isset($content[$i]['encoding'])) {
+           echo $content[$i]['encoding'];
+       } else echo '&nbsp';
+       echo '</td></tr>'."\n";
+    }
+    echo '</tbody></table><br>'."\n";
+}
+echo '<h2> RFC822 Message body </h2>'."\n\n";
+echo '<div><div class="header">'."\n\n";
+echo $message_body;
+echo '</div></div></font></code></body></html>';
+?>
diff --git a/plugins/message_details/message_details_main.php b/plugins/message_details/message_details_main.php
new file mode 100644 (file)
index 0000000..1e262ef
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/** Message Source  
+*
+* Plugin to view the RFC822 raw message output and the bodystructure of a message
+*
+* Copyright (c) 2002 Marc Groot Koerkamp, The Netherlands
+* Licensed under the GNU GPL. For full terms see the file COPYING.
+* 
+* $Id$
+**/
+
+chdir ('..');
+require_once('../src/validate.php');
+require_once('../functions/page_header.php');
+require_once('../functions/strings.php');
+
+displayHtmlHeader( _("Message details"), '', FALSE );
+
+echo "<frameset rows=\"60, *\" noresize border=\"0\">\n";
+echo '<frame src="message_details_top.php?mailbox=' . urlencode($mailbox) .'&passed_id=' . "$passed_id". '" name="top_frame" scrolling="off">';
+echo '<frame src="message_details_bottom.php?mailbox=' . urlencode($mailbox) .'&passed_id=' . "$passed_id" . '" name="bottom_frame">';
+echo  '</frameset>'."\n"."</html>\n";
+?>
\ No newline at end of file
diff --git a/plugins/message_details/message_details_top.php b/plugins/message_details/message_details_top.php
new file mode 100644 (file)
index 0000000..8e97c09
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/** Message Source  
+*
+* Plugin to view the RFC822 raw message output and the bodystructure of a message
+*
+* Copyright (c) 2002 Marc Groot Koerkamp, The Netherlands
+* Licensed under the GNU GPL. For full terms see the file COPYING.
+* 
+* $Id$
+**/
+
+    chdir('..');
+    require_once ('../src/validate.php');
+    require_once ('../functions/strings.php');
+    require_once ('../config/config.php');
+
+
+displayHtmlHeader( _("Message details"),
+             "<script language=\"javascript\">\n".
+             "<!--\n".
+             "function printPopup() {\n".
+                "parent.frames[1].focus();\n".
+                "parent.frames[1].print();\n".
+             "}\n".
+             "-->\n".
+             "</script>\n", FALSE );
+
+
+echo "<body text=\"$color[8]\" bgcolor=\"$color[3]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
+     '<center><b>'.
+     '<FORM name=rfc822 action="message_details_download.php?savemessage=1&passed_id='."$passed_id".'" METHOD=POST>' .     
+     '<input type="button" value="' . _("Print") . '" onClick="printPopup()">&nbsp&nbsp '.
+     '<input type="button" value="' . _("Close Window") . '" onClick="window.parent.close()">&nbsp&nbsp'.
+     '<input type="submit" value="' . _("Save Message") . '"> '.
+     '<input type="hidden" name="mailbox" value="'. "$mailbox" . '"> ' .
+     '</form>'.
+     '</b>'.
+     '</body>'.
+     "</html>\n";
+?>
\ No newline at end of file
diff --git a/plugins/message_details/setup.php b/plugins/message_details/setup.php
new file mode 100644 (file)
index 0000000..085c541
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/** Message Source  
+*
+* Plugin to view the RFC822 raw message output and the bodystructure of a message
+*
+* Copyright (c) 2002 Marc Groot Koerkamp, The Netherlands
+* Licensed under the GNU GPL. For full terms see the file COPYING.
+* 
+* $Id$
+**/
+
+
+function squirrelmail_plugin_init_message_details()
+{
+  global $squirrelmail_plugin_hooks;
+
+  do_hook("read_body_header_right");
+  $squirrelmail_plugin_hooks['read_body_header_right']['message_details'] = "show_message_details";
+}
+
+function show_message_details() {
+    global $passed_id, $mailbox, $ent_num, $color,
+           $pf_subtle_link,
+           $javascript_on;
+
+    if (strlen(trim($mailbox)) < 1) {
+        $mailbox = 'INBOX';
+    }
+
+    $params = '?passed_ent_id=' . $ent_num .
+              '&mailbox=' . urlencode($mailbox) .
+              '&passed_id=' . $passed_id;
+
+    $print_text = _("View Message details");
+
+
+    $result = '';
+    /* Output the link. */
+    if ($javascript_on) {
+        $result = '<script language="javascript">' . "\n" .
+                '<!--' . "\n" .
+                "  function MessageSource() {\n" .
+                '    window.open("../plugins/message_details/message_details_main.php' .
+                        $params . '","Print","width=800,height=600");' . "\n".
+                "  }\n" .
+                "// -->\n" .
+                "</script>\n" .
+                "&nbsp;|&nbsp;<A HREF=\"javascript:MessageSource();\">$print_text</A>\n";
+    } 
+    echo $result;
+}
\ No newline at end of file