What are the potential drawbacks of using imap_fetchbody() to display the body of an HTML email in PHP?

Using imap_fetchbody() to display the body of an HTML email in PHP may not always return the desired content, as it can sometimes include extra characters or not properly decode the email body. To ensure accurate display of the HTML content, it is recommended to use a more robust method like imap_fetchstructure() to parse the email structure and then decode the body accordingly.

// Connect to the IMAP server
$mailbox = imap_open('{imap.example.com:993/imap/ssl}INBOX', 'username', 'password');

// Get the email structure
$emailStructure = imap_fetchstructure($mailbox, $emailNumber);

// Check if email is multipart
if ($emailStructure->type == 1) {
    // Iterate through each part
    foreach ($emailStructure->parts as $partNumber => $part) {
        // Get the body of the HTML part
        if ($part->subtype == 'HTML') {
            $emailBody = imap_fetchbody($mailbox, $emailNumber, $partNumber + 1);
            // Decode the body if necessary
            $emailBody = imap_qprint($emailBody);
            // Display the HTML content
            echo $emailBody;
        }
    }
}

// Close the connection
imap_close($mailbox);