从imap_fetchbody解析样式

Specifically I'd like to preserve newline information. Here's my code:

$body = imap_fetchbody($stream, $emailId, 1.2); 
if (!strlen($body) > 0) { 
    $body = imap_fetchbody($stream, $emailId, 1.1); 
}
if (!strlen($body) > 0) {
    $body = imap_fetchbody($stream, $emailId, 1);
}

$structure = imap_fetchstructure($stream, $emailId);
if ($structure->encoding == 3) {
    $body = base64_decode($body);
} else if ($structure->encoding == 4) {
    $body = imap_qprint($body);
} else if ($structure->encoding == 0) {
    $body = $this->decode7Bit($body);
}

private function decode7Bit($text)
{
    // If there are no spaces on the first line, assume that the body is
    // actually base64-encoded, and decode it.
    $lines = explode("
", $text);
     $first_line_words = explode(' ', $lines[0]);
    if ($first_line_words[0] == $lines[0]) {
        $text = base64_decode($text);
    }

    // Manually convert common encoded characters into their UTF-8 equivalents.
    $characters = array(
        '=20' => ' ', // space.
        '=E2=80=99' => "'", // single quote.
        '=0A' => "
", // line break.
        '=A0' => ' ', // non-breaking space.
        '=C2=A0' => ' ', // non-breaking space.
        "=
" => '', // joined line.
        '=E2=80=A6' => '…', // ellipsis.
        '=E2=80=A2' => '•', // bullet.
    );

    // Loop through the encoded characters and replace any that are found.
    foreach ($characters as $key => $value) {
        $text = str_replace($key, $value, $text);
    }

    return $text;
}

I'm also storing the body text into a database. When I look at the body in the DB via phpMyAdmin it has styling! Not as visible tags but the text is actually broken up into paragraphs. However, whenever I dump the body text or echo it into the html it drops in with no styling at all. It's all one giant run on line. What am I doing wrong here?