| ' .
+ "$display_filename | " .
+ '' . show_readable_size($message->header->size) .
+ ' | ' .
+ "[ $type0/$type1 ] | " .
+ '';
+ if ($message->header->description)
+ $body .= '' . htmlspecialchars($message->header->description) . '';
+ $body .= ' | ';
+
+
+ $SkipSpaces = 1;
+ foreach ($Links as $Val) {
+ if ($SkipSpaces) {
+ $SkipSpaces = 0;
+ } else {
+ $body .= ' | ';
+ }
+ $body .= '' . $Val['text'] . '';
+ }
+
+ unset($Links);
+
+ $body .= " |
\n";
+ }
+ } else {
+ for ($i = 0; $i < count($message->entities); $i++) {
+ $body .= formatAttachments ($message->entities[$i], $ent_id, $mailbox, $id);
+ }
+ }
+ return( $body );
+ }
+}
+
+
+/** this function decodes the body depending on the encoding type. **/
+function decodeBody($body, $encoding) {
+ $body = str_replace("\r\n", "\n", $body);
+ $encoding = strtolower($encoding);
+
+ global $show_html_default;
+
+ if ($encoding == 'quoted-printable') {
+ $body = quoted_printable_decode($body);
+
+
+ while (ereg("=\n", $body))
+ $body = ereg_replace ("=\n", "", $body);
+
+ } else if ($encoding == 'base64') {
+ $body = base64_decode($body);
+ }
+
+ // All other encodings are returned raw.
+ return $body;
+}
+
+/*
+ * This functions decode strings that is encoded according to
+ * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text).
+ */
+function decodeHeader ($string, $utfencode=true) {
+
+if ( is_array( $string ) ) {
+ $string = implode("\n", $string );
+}
+
+if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=',
+ $string, $res)) {
+ if (ucfirst($res[2]) == 'B') {
+ $replace = base64_decode($res[3]);
+ } else {
+ $replace = str_replace('_', ' ', $res[3]);
+ // Convert lowercase Quoted Printable to uppercase for
+ // quoted_printable_decode to understand it.
+ while (ereg("(=(([0-9][abcdef])|([abcdef][0-9])|([abcdef][abcdef])))",
+ $replace, $res)) {
+ $replace = str_replace($res[1], strtoupper($res[1]), $replace);
+ }
+ $replace = quoted_printable_decode($replace);
+ }
+ /* Only encode into entities by default. Some places
+ don't need the encoding, like the compose form. */
+ if ($utfencode){
+ $replace = charset_decode ($res[1], $replace);
+ }
+
+ // Remove the name of the character set.
+ $string = eregi_replace ('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=',
+ $replace, $string);
+
+ // In case there should be more encoding in the string: recurse
+ $string = decodeHeader($string);
+}
+
+return ($string);
+}
+
+/*
+ * Encode a string according to RFC 1522 for use in headers if it
+ * contains 8-bit characters or anything that looks like it should
+ * be encoded.
+ */
+function encodeHeader ($string) {
+ global $default_charset;
+
+ // Encode only if the string contains 8-bit characters or =?
+ $j = strlen( $string );
+ $l = strstr($string, '=?'); // Must be encoded ?
+ $ret = '';
+ for( $i=0; $i < $j; ++$i) {
+ switch( $string{$i} ) {
+ case '=':
+ $ret .= '=3D';
+ break;
+ case '?':
+ $ret .= '=3F';
+ break;
+ case '_':
+ $ret .= '=5F';
+ break;
+ case ' ':
+ $ret .= '_';
+ break;
+ default:
+ $k = ord( $string{$i} );
+ if ( $k > 126 ) {
+ $ret .= sprintf("=%02X", $k);
+ $l = TRUE;
+ } else
+ $ret .= $string{$i};
+ }
+ }
+
+ if ( $l ) {
+ $string = "=?$default_charset?Q?$ret?=";
+ }
+
+ return( $string );
+}
+
+/*
+ Strips dangerous tags from html messages.
+*/
+function MagicHTML( $body, $id ) {
+
+ global $message, $HTTP_SERVER_VARS,
+ $attachment_common_show_images;
+
+ $attachment_common_show_images =
+ FALSE; // Don't display attached images in HTML mode
+ $j = strlen( $body ); // Legnth of the HTML
+ $ret = ''; // Returned string
+ $bgcolor = '#ffffff'; // Background style color (defaults to white)
+ $textcolor = '#000000'; // Foreground style color (defaults to black)
+ $leftmargin = ''; // Left margin style
+ $title = ''; // HTML title if any
+
+ $i = 0;
+ while ( $i < $j ) {
+ if ( $body{$i} == '<' ) {
+ $pos = $i + 1;
+ $tag = '';
+ while ($body{$pos} == ' ' || $body{$pos} == "\t" ||
+ $body{$pos} == "\n") {
+ $pos ++;
+ }
+ while (strlen($tag) < 4 && $body{$pos} != ' ' &&
+ $body{$pos} != "\t" && $body{$pos} != "\n") {
+ $tag .= $body{$pos};
+ $pos ++;
+ }
+ switch( strtoupper( $tag ) ) {
+ // Strips the entire tag and contents
+ case 'APPL':
+ case 'EMBB':
+ case 'FRAM':
+ case 'SCRI':
+ case 'OBJE':
+ $etg = '/' . $tag;
+ while ( $body{$i+1}.$body{$i+2}.$body{$i+3}.$body{$i+4}.$body{$i+5} <> $etg &&
+ $i < $j ) $i++;
+ while ( $i < $j && $body{++$i} <> '>' );
+ // $ret .= "";
+ break;
+ // Substitute Title
+ case 'TITL':
+ $i += 5;
+ while ( $body{$i} <> '>' && //
+ $i < $j )
+ $i++;
+ $i++;
+ $title = '';
+ while ( $body{$i} <> '<' && //
+ $i < $j ) {
+ $title .= $body{$i};
+ $i++;
+ }
+ $i += 7;
+ break;
+ // Destroy these tags
+ case 'HTML':
+ case 'HEAD':
+ case '/HTM':
+ case '/HEA':
+ case '!DOC':
+ case 'META':
+ //case 'DIV ':
+ //case '/DIV':
+ case '!-- ':
+ $i += 4;
+ while ( $body{$i} <> '>' &&
+ $i < $j )
+ $i++;
+ // $i++;
+ break;
+ case 'STYL':
+ $i += 5;
+ while ( $body{$i} <> '>' && //
+ $i < $j )
+ $i++;
+ $i++;
+ // We parse the style to look for interesting stuff
+ $styleblk = '';
+ while ( $body{$i} <> '>' &&
+ $i < $j ) {
+ // First we get the name of the style
+ $style = '';
+ while ( $body{$i} <> '>' &&
+ $body{$i} <> '<' &&
+ $body{$i} <> '{' &&
+ $i < $j ) {
+ if ( isnoSep( $body{$i} ) )
+ $style .= $body{$i};
+ $i++;
+ }
+ stripComments( $i, $j, $body );
+ $style = strtoupper( trim( $style ) );
+ if ( $style == 'BODY' ) {
+ // Next we look into the definitions of the body style
+ while ( $body{$i} <> '>' &&
+ $body{$i} <> '}' &&
+ $i < $j ) {
+ // We look for the background color if any.
+ if ( substr( $body, $i, 17 ) == 'BACKGROUND-COLOR:' ) {
+ $i += 17;
+ $bgcolor = getStyleData( $i, $j, $body );
+ } elseif ( substr( $body, $i, 12 ) == 'MARGIN-LEFT:' ) {
+ $i += 12;
+ $leftmargin = getStyleData( $i, $j, $body );
+ }
+ $i++;
+ }
+ } else {
+ // Other style are mantained
+ $styleblk .= "$style ";
+ while ( $body{$i} <> '>' &&
+ $body{$i} <> '<' &&
+ $body{$i} <> '}' &&
+ $i < $j ) {
+ $styleblk .= $body{$i};
+ $i++;
+ }
+ $styleblk .= $body{$i};
+ }
+ stripComments( $i, $j, $body );
+ if ( $body{$i} <> '>' )
+ $i++;
+ }
+ if ( $styleblk <> '' )
+ $ret .= "