barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.65k stars 459 forks source link

[BUG] textPlain and textHtml both empty (for some mails) #677

Closed blieb closed 1 year ago

blieb commented 1 year ago

Environment (please complete the following information):

Describe the bug For some emails we receive I see it has not text in the mail. Both textPlain and textHtml are empty string. What I understand that this only happens when a mail does not have a plain text version included. (Sadly some of the people/companies who mail us do this).

When I dump the full mail object I also don't see any of text that is in the mail.

When I check the $mail->headersRaw I only see this referring to the html attachment

    MIME-Version: 1.0\r\n
    Content-Type: multipart/related; \r\n
    \tboundary="----=_Part_3161_11814195.1658904584277"\r\n

when I check the source in mail client I see:

Content-Type: multipart/related; 
    boundary="----=_Part_3161_11814195.1658904584277"
Precedence: bulk
Auto-Submitted: auto-generated

------=_Part_3161_11814195.1658904584277
Content-Transfer-Encoding: 7bit
Content-Type: text/html; charset=UTF-8

<html><head></head><body><p><span style="font-family: verdana, geneva; font-size: 14pt;">Beste,</span></p>

I can sadly not attach the full headers of the mails because of privacy.

To Reproduce Receive a html only mail with php-imap

The used code:

$mailbox = new Mailbox(...);
$mail = mailbox->getMail($mailId);
var_dump($mail->htmlText);
blieb commented 1 year ago

I'm trying to find the issue. I see it also happens when mail has both html and plain body. Hereby a full header (I edited a little to hide personal information, sent with CakePHP mailer)

Return-Path: <support@ourdomain.nl>
Delivered-To: firstname.lastname@ourdomain.nl
Received: from mailsvr.ourdomain.nl
    by mailsvr.ourdomain.nl with LMTP
    id OE0wLBNV4mI+KQAAvrt3Ug
    (envelope-from <support@ourdomain.nl>)
    for <firstname.lastname@ourdomain.nl>; Thu, 28 Jul 2022 11:21:23 +0200
Return-path: <support@ourdomain.nl>
Envelope-to: firstname.lastname@ourdomain.nl
Delivery-date: Thu, 28 Jul 2022 11:21:23 +0200
Received: from 095-097-076-114.static.chello.nl ([95.97.76.114] helo=www.ourdomain.nl)
    by mailsvr.ourdomain.nl with esmtpa (Exim 4.92.3)
    (envelope-from <support@ourdomain.nl>)
    id 1oGzhr-0002mu-Lb
    for firstname.lastname@ourdomain.nl; Thu, 28 Jul 2022 11:21:23 +0200
From: Ourdomain Support <support@ourdomain.nl>
To:  <firstname.lastname@ourdomain.nl>
Date: Thu, 28 Jul 2022 11:21:23 +0200
Message-ID: <b6ca1d09e7de48278d0f775413af7842@www.ourdomain.nl>
Subject: just a random subject
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="3e3376315198d86c76738faf7751ccaf"
Content-Transfer-Encoding: 8bit

--3e3376315198d86c76738faf7751ccaf
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

firstname lastname - 28-07-2022 11:21

hoi daar 2

--3e3376315198d86c76738faf7751ccaf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html class="no-js" lang="" style="margin:0;padding:0;border:0;outline:0;">

    <head>
        <meta charset="utf-8">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>E-mail Template Inline</title>
        <style type="text/css">
        </style>
    </head>

    <body class="bg" style="margin:0;padding:0;border:0;outline:0;">
        <div class="body" style="padding:20px 20px;">

            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;font-family:Helvetica, Arial, sans-serif;color:#1d1d1d;line-height:1.2;">
                <tr>
                    <td rowspan="4" width="75" style="vertical-align: top;" ><img src="https://files.ourdomain.nl/images/mail-logo-256x256.png" width="64" height="64" /></td>
                </tr>
                <tr>
                    <td style="font-size:large;padding-top:15px"><strong>firstname lastname</strong></td>
                </tr>
                <tr>
                    <td style="color:#bbbbbb;">28-07-2022 11:21</td>
                </tr>
                <tr>
                    <td style="padding-top: 15px;line-height:1.6;">hoi daar 2</td>
                </tr>
            </table>
        </div>
    </body>

</html>

--3e3376315198d86c76738faf7751ccaf--
blieb commented 1 year ago

I really don't know why I started using htmlText instead of textHtml. $mail->textHtml does works. but not visible when you dump the mail object itself. Ignore the above thread :)