X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Fmessage_details%2Fmessage_details_bottom.php;h=ce5e3c4e707b1342cf0c236b58b0291095d50577;hp=0852e5ca8c61ff3678081b0822141cfa716b12b0;hb=353d074afac6827c90f4bb03e846c5e453d3b5b1;hpb=47ccfad452e8d345542d09e59112cac317cffed8
diff --git a/plugins/message_details/message_details_bottom.php b/plugins/message_details/message_details_bottom.php
index 0852e5ca..ce5e3c4e 100644
--- a/plugins/message_details/message_details_bottom.php
+++ b/plugins/message_details/message_details_bottom.php
@@ -6,22 +6,22 @@
* 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-2018 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)
-/** @ignore */
-if (!defined('SM_PATH'))
- define('SM_PATH','../../');
-
-/* SquirrelMail required files. */
-require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/mime.php');
+/**
+ * Include the SquirrelMail initialization file.
+ */
+require('../../include/init.php');
+require(SM_PATH . 'functions/imap_general.php');
+require(SM_PATH . 'functions/imap_messages.php');
+require(SM_PATH . 'functions/mime.php');
sqgetGlobalVar('get_message_details', $md_action, SQ_GET);
@@ -32,11 +32,17 @@ sqgetGlobalVar('get_message_details', $md_action, SQ_GET);
global $msgd_8bit_in_hex;
$msgd_8bit_in_hex=false;
-if (!empty($md_action))
-{
- sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
+if (!empty($md_action)) {
+ 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);
- echo get_message_details($mailbox, $passed_id);
+ /*
+ * change $unformatted to TRUE if you want to see
+ * message source without formating
+ */
+ $unformatted = FALSE;
+ echo get_message_details($mailbox, $passed_id, $passed_ent_id, $unformatted);
}
@@ -94,228 +100,202 @@ 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
* @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;
-
-$returnValue = '';
-
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('key', $key, SQ_COOKIE);
-
-$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, 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;
+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 = '';
+
+ $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
+ $read = sqimap_mailbox_select($imapConnection, $mailbox);
+ 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;
+ $bnd_end = false;
+ $messageheader = true;
+ $messageheaderstart=false;
+ $boundaries = array();
+ $entities = array();
+ sqsession_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".'