+ 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 .= '</div><div class="entheader" id="'.
+ $entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
+ $end .= '</font></b>';
+ $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 ($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).'<br />';