From 4588f43defbad726d307820e8126cf8cabc886ca Mon Sep 17 00:00:00 2001 From: tokul Date: Sun, 23 Apr 2006 13:16:18 +0000 Subject: [PATCH] removed debug function message body is placed in

 instead of  in order to display tabs in headers. rtrim function
 is used instead of trim in order to strip writespace only from the end of
 line.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11075 7612ce4b-ef26-0410-bec9-ea0150e637f0
---
 .../message_details_bottom.php                | 482 ++++++++----------
 1 file changed, 222 insertions(+), 260 deletions(-)

diff --git a/plugins/message_details/message_details_bottom.php b/plugins/message_details/message_details_bottom.php
index f66817db..b6d897c2 100644
--- a/plugins/message_details/message_details_bottom.php
+++ b/plugins/message_details/message_details_bottom.php
@@ -31,10 +31,13 @@ sqgetGlobalVar('get_message_details', $md_action, SQ_GET);
 global $msgd_8bit_in_hex;
 $msgd_8bit_in_hex=false;
 
-if (!empty($md_action))
-{
+if (!empty($md_action)) {
     sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
     sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
+    /* 
+     * add third function argument, if you want to see 
+     * message source without formating
+     */
     echo get_message_details($mailbox, $passed_id);
 }
 
@@ -93,22 +96,6 @@ function CalcEntity($entString, $direction) {
 }
 
 
-
-/**
- * Returns time in microseconds between selected and current timestamp
- *
- * @param array $start see details about array format at http://www.php.net/gettimeofday
- * @return integer time in microseconds
- * @access private
- */
-function returnTime($start) {
- $stop = gettimeofday();
- $timepassed =  1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
- return $timepassed;
-}
-
-
-
 /**
  * Returns actual message details
  * @param string $mailbox
@@ -120,195 +107,184 @@ function returnTime($start) {
  * @access public
  */
 function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
-
-global $imapServerAddress, $imapPort, $color,$msgd_8bit_in_hex;
-
-$returnValue = '';
-
-sqgetGlobalVar('username', $username, SQ_SESSION);
-
-$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
-$read = sqimap_mailbox_select($imapConnection, $mailbox);
-$start = gettimeofday();
-$body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
-$message_body = '';
-$header = false;
-$mimepart = false;
-$bnd_end = false;
-$messageheader = true;
-$messageheaderstart=false;
-$boundaries = array();
-$entities = array();
-session_unregister("entities");
-$pre = '';
-$end = '';
-$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".''."\n \n".'
'."\n \n"; - } - $mimepart = -$header; - $bnd_end = false; - if ($messageheaderstart) { - $messageheaderstart=false; + global $imapServerAddress, $imapPort, $color,$msgd_8bit_in_hex; + + $returnValue = ''; + + sqgetGlobalVar('username', $username, SQ_SESSION); + + $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); + $read = sqimap_mailbox_select($imapConnection, $mailbox); + $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE); + $message_body = ''; + $header = false; + $mimepart = false; + $bnd_end = false; + $messageheader = true; + $messageheaderstart=false; + $boundaries = array(); + $entities = array(); + session_unregister("entities"); + $pre = ''; + $end = ''; + $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 = rtrim($body[$i]); + if ($line == '') { + $pre = ''; + $end = ''; + if ($bnd_end) { + $header = true; + $mimepart = false; + } else if ($messageheader) { + if ($header) { + $header=false; + $end = '
'; + } + $mimepart = -$header; + $bnd_end = false; + if ($messageheaderstart) { + $messageheaderstart=false; + } + } else if ($messageheaderstart) { + $messageheader= false; + } else { + if ($header) { + $pre = ''; + $end = '
'; + } + $header = false; + $mimepart=true; } - } else if ($messageheaderstart) { - $messageheader= false; + $contentset = false; + $nameset = false; } else { - if ($header) { - $pre = ''; - $end = "\n \n".'
'."\n \n".'
'."\n \n"; + if (!$header && $messageheader) { + $messageheaderstart=true; + if ($pre != '') { + $pre = ''; + $end = ''; + } } - $header = false; - $mimepart=true; - } - $contentset = false; - $nameset = false; - } else { - if (!$header && $messageheader) { - $messageheaderstart=true; - if ($pre != '') { - $pre = ''; - $end = ''; + if (!$messageheader && !$header ) { + $mimepart=true; + } else { + $mimepart=false; } + $pre = ''; + $end = ''; } - if (!$messageheader && !$header ) { - $mimepart=true; - } else { + 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; - } - $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 .= ''; - $end .= ''; - $header = true; - $mimepart = false; - $bnd_end = true; - $encoding = ''; + if ($entStr=='') { + $entStr='0'; } else { - $header = true; - $bnd_end = false; - $entStr = CalcEntity("$entStr",0); - $content_indx++; - $content[$content_indx]=array(); - $content[$content_indx]['ent'] = '$entStr".''; - $pre .= "\n \n".'
'."\n \n".'
'; - $end .= ''."\n"; - $header = true; - $mimepart = false; - $encoding = ''; + $entStr = CalcEntity("$entStr",1); } - } 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 = ''; + } + + 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 .= ''; + $end .= ''; + $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'] = '$entStr".''; + $pre .= '
'; + $end .= ''; + $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 .= ''; - $end .= ''; - //$mimepart=false; + $pre .= ''; + $end .= ''; + //$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; - } + + if ($stripHTML) { + $message_body .= $line . "\r\n"; + } else { + $line = htmlspecialchars($line); + if ($msgd_8bit_in_hex) $line = msgd_convert_to_hex($line); + $message_body .= "$pre"."$line"."$end"."\r\n"; } } -*/ - if ($stripHTML) { - $message_body .= $line . "\r\n"; - } else { - $line = htmlspecialchars($line); - if ($msgd_8bit_in_hex) $line = msgd_convert_to_hex($line); - $message_body .= "$pre"."$line"."$end".'
'."\r\n"; - } -} - + //$returnValue .= returnTime($start).'
'; $xtra = <<\n"; - $returnValue .= ''."\n"; - $returnValue .= ''."\n"; - $returnValue .= '
'."\n"; -} - - -//session_register("entities"); -//$keys = array_keys($entities); -//$start = gettimeofday(); -//foreach ($keys as $key) { -// if (isset($entities[$key])) { -// if ($entities[$key]['encoding'] == 'base64') { -// if (!$stripHTML) { -// $returnValue .= 'img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&name='.$entities[$key]['name'].'">
'; -// } -// } -// } -//} -//session_unregister("entities"); - -if (count($content) > 0 && !$stripHTML) { - $returnValue .= '

'._("Bodystructure")."

\n\n"; - $returnValue .= ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''; - for ($i = 0; $i < count($content);$i++) { - $returnValue .= ''."\n"; + if (!$stripHTML) { + ob_start(); + displayHtmlHeader( _("Message Details"), $xtra, FALSE ); + $returnValue .= ob_get_contents(); + ob_end_clean(); } - $returnValue .= '
'._("Entity").''._("Content-Type").''._("Name").''._("Encoding").'
'; - $returnValue .= $content[$i]['ent'].''; - if (isset($content[$i]['type'])) { - $returnValue .= $content[$i]['type']; - } else $returnValue .= 'TEXT/PLAIN'; - $returnValue .= ''; - if (isset($content[$i]['name'])) { - $returnValue .= $content[$i]['name']; - } else $returnValue .= ' '; - $returnValue .= ''; - if (isset($content[$i]['encoding'])) { - $returnValue .= $content[$i]['encoding']; - } else $returnValue .= ' '; - $returnValue .= '

'."\n"; -} - -if (!$stripHTML) { - $returnValue .= '

'._("RFC822 Message body")."

\n\n"; - $returnValue .= '
'."\n\n"; -} -$returnValue .= $message_body; + /* body */ + if (!$stripHTML) { + $returnValue .= "\n"; + $returnValue .= ''."\n"; + $returnValue .= '
'."\n"; + } -if (!$stripHTML) - $returnValue .= '
'; + if (count($content) > 0 && !$stripHTML) { + $returnValue .= '

'._("Bodystructure")."

\n\n"; + $returnValue .= ''. + ''. + ''. + ''. + ''. + ''. + ''. + ''; + for ($i = 0; $i < count($content);$i++) { + $returnValue .= ''."\n"; + } + $returnValue .= '
'._("Entity").''._("Content-Type").''._("Name").''._("Encoding").'
'; + $returnValue .= $content[$i]['ent'].''; + if (isset($content[$i]['type'])) { + $returnValue .= $content[$i]['type']; + } else $returnValue .= 'TEXT/PLAIN'; + $returnValue .= ''; + if (isset($content[$i]['name'])) { + $returnValue .= $content[$i]['name']; + } else $returnValue .= ' '; + $returnValue .= ''; + if (isset($content[$i]['encoding'])) { + $returnValue .= $content[$i]['encoding']; + } else $returnValue .= ' '; + $returnValue .= '

'."\n"; + } -return $returnValue; + if (!$stripHTML) { + $returnValue .= '

'._("RFC822 Message body")."

\n\n"; + $returnValue .= '
'; + } else { + $returnValue .= '
';
+    }
 
+    $returnValue .= $message_body;
+    
+    if (!$stripHTML) {
+        $returnValue .= '
'; + } else { + $returnValue .= ''; + } + return $returnValue; } - ?> \ No newline at end of file -- 2.25.1