Are there any specific PHP functions or libraries recommended for decoding emails, especially those with complex content?

When decoding emails, especially those with complex content like HTML or attachments, it's recommended to use the PHP built-in function `imap_fetchbody` for retrieving the body of the email and decoding it. Additionally, the `mb_convert_encoding` function can be used to handle character encoding issues that may arise when decoding emails.

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

// Fetch the email body
$emails = imap_search($mailbox, 'ALL');
$email_number = $emails[0]; // Assuming the first email in the inbox
$body = imap_fetchbody($mailbox, $email_number, 1.2); // Fetch the body of the email

// Decode the email body
$body = mb_convert_encoding($body, 'UTF-8', 'UTF-8');

// Close the connection to the IMAP server
imap_close($mailbox);