';
$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;
}
} else if ($messageheaderstart) {
$messageheader= false;
} else {
if ($header) {
$pre = '';
$end = "\n \n".'
'."\n \n".''."\n \n";
}
$header = false;
$mimepart=true;
}
$contentset = false;
$nameset = false;
} else {
if (!$header && $messageheader) {
$messageheaderstart=true;
if ($pre != '
') {
$pre = '';
}
}
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 .= '';
$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 .= "\n \n".' '."\n \n".'