Webklex / laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
https://www.php-imap.com
MIT License
623 stars 179 forks source link

Reading a blank body (text / html) but only from this sender #203

Closed kasperfd closed 4 years ago

kasperfd commented 5 years ago

Hi,

I really enjoy this plugin and I've used it for 1½ year without problems until now - so I'm thinking there must be a rare bug because it has been working for so long in version 1.2 and now 1.4.

The problem short: Many (50+) people are writing emails to us everyday without problems but for a specific person then we only get the subject + attachments fetched and both the text & html content is blank / empty.

So I hope you have some ideas of why this is happening - please tell thanks :)

Laravel: 5.4 Laravel Imap: 1.4 (latest) - the problem were also in 1.2 because I tried that version too without luck

Reproducing the problem: I tried but I cannot - so my conclusion is that the problem must exist in the email headers. Because when forwarding the e-mail to myself and back again to the IMAP inbox then the body could be fetched correctly.... I'm so lost here :)

imap config:

            'host' => 'outlook.office365.com',
            'port' => 993,
            'protocol' => 'imap',
            'encryption' => 'ssl',
            'validate_cert' => true,
...
    'options' => [
        'delimiter' => '/',
        'fetch' => FT_PEEK,
        'fetch_body' => true,
        'fetch_attachment' => true,
        'fetch_flags' => true,
        'message_key' => 'id',
        'fetch_order' => 'asc',
        'open' => [
            'DISABLE_AUTHENTICATOR' => ['GSSAPI','PLAIN'],
        ]
    ]

Email headers where the body is blank / empty and only the subject + attachments is fetched successfully. Can you spot any wierd header causing something going wrong ? I can log in to the mailbox on office 365 and see the email (I renamed recipient and sender email):

Received: from AM6PR03MB3816.eurprd03.prod.outlook.com (2603:10a6:206:14::46)
 by AM6PR03MB3815.eurprd03.prod.outlook.com with HTTPS via
 AM5P190CA0033.EURP190.PROD.OUTLOOK.COM; Tue, 26 Mar 2019 16:59:33 +0000
Received: from DB8PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:10:be::26)
 by AM6PR03MB3816.eurprd03.prod.outlook.com (2603:10a6:20b:24::15) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Tue, 26 Mar
 2019 16:59:32 +0000
Received: from VI1EUR04FT035.eop-eur04.prod.protection.outlook.com
 (2a01:111:f400:7e0e::203) by DB8PR03CA0013.outlook.office365.com
 (2603:10a6:10:be::26) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1730.18 via Frontend
 Transport; Tue, 26 Mar 2019 16:59:31 +0000
Authentication-Results: spf=none (sender IP is 78.46.72.43)
 smtp.mailfrom=kellertravel.ie; campingvision.com; dkim=none (message not
 signed) header.d=none;campingvision.com; dmarc=none action=none
 header.from=kellertravel.ie;compauth=pass reason=116
Received-SPF: None (protection.outlook.com: kellertravel.ie does not designate
 permitted sender hosts)
Received: from mr30.theemaillaundry.net (78.46.72.43) by
 VI1EUR04FT035.mail.protection.outlook.com (10.152.28.160) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id
 15.20.1750.11 via Frontend Transport; Tue, 26 Mar 2019 16:59:31 +0000
Received: from localhost (localhost [127.0.0.1])
    by mr30.theemaillaundry.net (Postfix) with ESMTP id 50DCD241869
    for <our@domainhere.com>; Tue, 26 Mar 2019 16:59:31 +0000 (GMT)
X-Amavis-Modified: Mail body modified (using disclaimer) -
    mr30.theemaillaundry.net
X-Virus-Scanned: amavisd-new at theemaillaundry.net
Received: from mr30.theemaillaundry.net ([127.0.0.1])
    by localhost (mr30.theemaillaundry.net [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id DZotoCQz3rCQ for <our@domainhere.com>;
    Tue, 26 Mar 2019 16:59:24 +0000 (GMT)
Received: from kellertravel.ie (unknown [83.71.235.137])
    by mr30.theemaillaundry.net (Postfix) with ESMTP id 9DF262416F1
    for <our@domainhere.com>; Tue, 26 Mar 2019 16:59:24 +0000 (GMT)
Received: from KELLER-DOM-MTA by kellertravel.ie
    with Novell_GroupWise; Tue, 26 Mar 2019 16:59:24 +0000
MIME-Version: 1.0
Date: Tue, 26 Mar 2019 16:59:19 +0000
References: <a40b0d0be277468267bcdf3874ebd408@backend.twentybook.com>
In-Reply-To: <a40b0d0be277468267bcdf3874ebd408@backend.twentybook.com>
Message-ID: <5C9A5A67.2988.003A.0@kellertravel.ie>
X-Mailer: Groupwise 7.0.3
From: Sender name here <sender@domainhere.com>
Subject: Re: [Booking ref: AL851209]
To: Camping Vision <our@domainhere.com>
Content-Type: multipart/alternative; boundary="____IZPBWUYHBUJDCJJCVTXY____"
Return-Path: sender@domainhere.com
X-MS-Exchange-Organization-ExpirationStartTime: 26 Mar 2019 16:59:31.6834
 (UTC)
X-MS-Exchange-Organization-ExpirationStartTimeReason: OriginalSubmit
X-MS-Exchange-Organization-ExpirationInterval: 2:00:00:00.0000000
X-MS-Exchange-Organization-ExpirationIntervalReason: OriginalSubmit
X-MS-Exchange-Organization-Network-Message-Id:
 0963b9be-507e-4da1-65d9-08d6b20c6a92
X-EOPAttributedMessage: 0
X-EOPTenantAttributedMessage: d06c4993-a045-45c6-a1d9-c808440ef213:0
X-MS-Exchange-Organization-MessageDirectionality: Incoming
X-Forefront-Antispam-Report:
 CIP:78.46.72.43;IPV:NLI;CTRY:DE;EFV:NLI;SFV:NSPM;SFS:(2980300002)(428003)(199004)(189003)(50226002)(8676002)(733005)(16586007)(6666004)(71190400001)(229853002)(356004)(36756003)(486006)(6916009)(33656002)(246002)(81446001)(24386001)(72206003)(1096003)(105586002)(106466001)(6246003)(19627405001)(16003)(57326003)(6306002)(54556002)(26005)(7596002)(7636002)(46656002)(336012)(476003)(86362001)(33964004)(14444005)(5660300002)(84326002)(76176011)(446003)(11346002)(74482002)(105004)(2616005)(126002)(426003)(21314003);DIR:INB;SFP:;SCL:1;SRVR:AM6PR03MB3816;H:mr30.theemaillaundry.net;FPR:;SPF:None;LANG:en;PTR:mr30.theemaillaundry.net;A:1;MX:1;
X-MS-Exchange-Organization-AuthSource:
 VI1EUR04FT035.eop-eur04.prod.protection.outlook.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: 0963b9be-507e-4da1-65d9-08d6b20c6a92
X-Microsoft-Antispam:
 BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(5600127)(711020)(4605104)(49563074)(1401299)(1421009)(71702078);SRVR:AM6PR03MB3816;
X-MS-TrafficTypeDiagnostic: AM6PR03MB3816:
X-MS-Exchange-Organization-SCL: 1
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2019 16:59:31.5653
 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 0963b9be-507e-4da1-65d9-08d6b20c6a92
X-MS-Exchange-CrossTenant-Id: d06c4993-a045-45c6-a1d9-c808440ef213
X-MS-Exchange-CrossTenant-FromEntityHeader: Internet
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB3816
X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.6377032
X-MS-Exchange-Processed-By-BccFoldering: 15.20.1730.017
X-Microsoft-Antispam-Mailbox-Delivery:
    ucf:0;jmr:0;ex:0;auth:0;dest:I;ENG:(20160514016)(750119)(520011016)(944506303)(944626516);
X-Microsoft-Antispam-Message-Info:
    2jFc8nZP5d13KuSakCSM7nU+u7kKpXmcY6R3Jlk23M3RC40W8xnhdN6CleyHxIk5uBREAVPvyKa7cF+tpHU668L9wLKAQ2epQgQmAsygrYpV4OMx1jfrnAFmUjdsUOfJnh7UYtM4Cc9/V5YdJJLmLWfXSPb5tziOPH2FjSsXYmXFckDVKdLcMqEalFaUAQ7LoGroOYL7m8xsLrqhevdU/WmvIgoJaqwVcrX5k5gq9Y689PbR4kqRM60w1K4WL8okd0ur24DjwZTIDIKdXdJXp6mtWDYtbBjmhEj+CNfDtvO80uyRZp52s/oQizxeg/97juHKw76XbCPpMWAcl6jQft4VEezWM9WrIgFN8Let9a81c7lYklu6Y++J5CdXQT31/WIaDYebUEync+BhKR4KiHIukJWnZ8UhgAGpG2wY955EwqSNCdvzQkXNGXNIrE4OwRIktcOvNAruBEIwNVorDLuTXmNd6Nd3BihrWvgPSlxWtxnaLNmjAliJXU0C1ZAfbARH0oDorpEAlATemRVIrM8rNUzNPoOUuqdD2J5TmtdaMaioKGkyzyk7Reg6+knEsreuKE7fkQZtldVg96relRIco8ouSRzA3WKxTwidvI5zH5KhO4q7PrO0gg5Op9AUBzMn2bt4YF+MUj7TL9Coo2CsRekXRV/1/C9TGX8pdjj7GOpwqfCIgRZmEjwa772PqVjL2klEiR8WGPZZ+7GWR2xqlao6ocFL66sjnCRMXlcUowlt2Z7xWjpAFTPAnI3huUvgcTE3OGIc/ApvQbc5HHWjieSZewly0ALtu+8BV5HK9d4RVXSaR+5/IXX1YZvSOP1LbDFb0YETHwkAYmzpkZ2AnFBzmU5w6Ya+92pTwFc=
Webklex commented 5 years ago

Hi @kasperfd, thanks for your well formatted issue.

The described bug seems to be realy odd. I assume just like you did that it's probably a client related issue.

However your mail headers look fine to me. The only thing that caught my attention was the Groupwise flag.

From https://books.google.de/books?id=D3Om_zmjW7oC&pg=PT94&lpg=PT94&dq=Groupwise+empty+mail+body

[..] Forward as Attachment leaves the new message's body blank and places the forwarded message as an attachment.

Please check the mail attachment of these specific "empty" mails. If your body is indeed an attachment please provide some additional information:

var_dump([
    'mime_type' => $attachment->getMimeType(),
    'type' => $attachment->getType(),
    'name' => $attachment->getName(),
    'disposition' => $attachment->getDisposition(),
    'content_type' => $attachment->getContentType(),
]);

Btw the client you used to "resend" the mail might detect the attachment as some sort of body-part and use them as mail body automatically(?).

At this point this is just a vague guess. Please keep me updated on how things worked out :)

Best regards

kasperfd commented 5 years ago

Thanks for your quick response - this is very helpful.

The "Groupwise" pointed me in some direction to google on. Your assumption about the body treated as attachment might be correct - see following two temp file attachments: email_with_two_temp_attachments

Office 365 can preview the email body correctly when viewing it so somehow it should be possible hm :)

I didn't managed to print out any attachments in the code though - just empty unfurtunately. I even looked at the $message object again without luck seeing anything helpful.

Do you have other suggestions ? :) I've asked the client to sent a clean test email to me and then I can show you a full var_dump / print of the $message object (perhaps you can see something making sense)

kasperfd commented 5 years ago

@Webklex : Ok I got a little further.

Maybe you can spot something I could change in the "Message.php" so it might work ? :)

I just did following in Message.php and got some readable body text out even though these two lines are empty:

$body = $message->getTextBody();
$body = $message->getHTMLBody($this->replaceImageWithLinks);

So somewhere following should give us a clue and improve this to be working (hopefully):

private function fetchStructure($structure, $partNumber = null) {
        \Log::info('--------- fetchStructure---------');
        \Log::info('partNumber: ' . $partNumber);
        \Log::info(print_r($structure, true));
        $encoding = $this->getEncoding($structure);
        $test = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options | IMAP::FT_UID);
        $test = $this->decodeString($test, $structure->encoding);
        if ($encoding != 'us-ascii') {
            $test = $this->convertEncoding($test, $encoding);
        }
        \Log::info(print_r($test, true));

And the result:

[2019-04-04 11:57:20] local.INFO: --------- fetchStructure---------  
[2019-04-04 11:57:20] local.INFO: partNumber: 1  
[2019-04-04 11:57:20] local.INFO: stdClass Object
(
    [type] => 0
    [encoding] => 3
    [ifsubtype] => 1
    [subtype] => PLAIN
    [ifdescription] => 0
    [ifid] => 0
    [lines] => 4
    [bytes] => 376
    [ifdisposition] => 1
    [disposition] => inline
    [ifdparameters] => 1
    [dparameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => modification-date
                    [value] => Thu, 3 Apr 2019 15:50:39  +0100
                )

        )

    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => charset
                    [value] => utf-8
                )

        )

)
[2019-04-04 11:57:20] local.INFO: Hi Kasper
This is a test email......

Regards

[2019-04-04 11:57:20] local.INFO: --------- fetchStructure---------  
[2019-04-04 11:57:20] local.INFO: partNumber: 2.1  
[2019-04-04 11:57:20] local.INFO: stdClass Object
(
    [type] => 0
    [encoding] => 3
    [ifsubtype] => 1
    [subtype] => HTML
    [ifdescription] => 0
    [ifid] => 0
    [lines] => 52
    [bytes] => 4044
    [ifdisposition] => 1
    [disposition] => inline
    [ifdparameters] => 1
    [dparameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => modification-date
                    [value] => Thu, 3 Apr 2019 15:50:39  +0100
                )

        )

    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => charset
                    [value] => utf-8
                )

        )

)

[2019-04-04 11:57:20] local.INFO: <html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="MSHTML 11.00.10570.1001"></head>
<body style="FONT: 10pt Segoe UI; MARGIN: 4px 4px 1px">
<div>Hi Kasper</div>
<div>This is a test email......</div>
<div>&nbsp;</div>
<div>Regards</div>
<div>&nbsp;</div>
</body></html>  

[2019-04-04 11:57:20] local.WARNING: The email body is empty for following subject: Test email  
emtudo commented 5 years ago

have the same problem

Both $message->getTextBody() and $message->getHTMLBody() come empty.

Webklex commented 5 years ago

Hi @kasperfd , please go ahead and give the current master version a try.

@emtudo thanks for your pull requests! :)

Best regards

kasperfd commented 5 years ago

Hi @Webklex ,

Great - just tried the latest version but still empty unfurtunately :/

Could you track something from the log above ?

Regards

emtudo commented 5 years ago

Hi @kasperfd, The @Webklex did not generate a new tag, did you directly try the branch master?

@Webklex Could you release a new version tag?

Webklex commented 5 years ago

Hi @emtudo , 1.4.1 is already released containing all latest commits :)

@kasperfd I'm having a hard time simulating this "feature" :/ The structure looks fine to me and should be fetched.

Could you check if Message::fetchStructure() L:696 gets reached and $body is actually filled? The same with L:717?

emtudo commented 5 years ago

@Webklex Had not noticed, thank you!

kasperfd commented 5 years ago

@Webklex Sorry - Easter holidays came in the way :)

I checked Message:fetchStructure for both lines - they are never called for this test email.

They are not coming through this one: if ($structure->type == IMAP::MESSAGE_TYPE_TEXT && ($structure->ifdisposition == 0 || ($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber == null) ) ) {

It seems ifdisposition is 1 and partNumber is not null and therefore it fails.

Here's my log printing out the important stuff before the if statement above so you can see the whole thing (info: there's an inline signature image s don't get confused :) )

[2019-04-23 19:29:37] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:37] local.INFO: $partNumber:
[2019-04-23 19:29:37] local.INFO: $structure->type: 1
[2019-04-23 19:29:37] local.INFO: $structure->subtype: ALTERNATIVE
[2019-04-23 19:29:37] local.INFO: $structure->ifdisposition: 0
[2019-04-23 19:29:37] local.INFO: $structure->parts: is set
[2019-04-23 19:29:37] local.INFO: $content2:
[2019-04-23 19:29:37] local.INFO: (headers)

--UZMFBFSJZICTFZLSLAKP Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39 +0100"

--UZMFBFSJZICTFZLSLAKP Content-Type: multipart/related; boundary="KJOVFHYGTXPIHXKOXBNQ"

--KJOVFHYGTXPIHXKOXBNQ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39 +0100"

--KJOVFHYGTXPIHXKOXBNQ Content-ID: Content-Type: image/jpg Content-Transfer-Encoding: base64

--KJOVFHYGTXPIHXKOXBNQ--

--UZMFBFSJZICTFZLSLAKP--

[2019-04-23 19:29:37] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:37] local.INFO: $partNumber: 1
[2019-04-23 19:29:37] local.INFO: $structure->type: 0
[2019-04-23 19:29:37] local.INFO: $structure->subtype: PLAIN
[2019-04-23 19:29:37] local.INFO: $structure->ifdisposition: 1
[2019-04-23 19:29:37] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO: Hi Kasper This is a test email......

Regards

[2019-04-23 19:29:38] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:38] local.INFO: $partNumber: 2
[2019-04-23 19:29:38] local.INFO: $structure->type: 1
[2019-04-23 19:29:38] local.INFO: $structure->subtype: RELATED
[2019-04-23 19:29:38] local.INFO: $structure->ifdisposition: 0
[2019-04-23 19:29:38] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO: --KJOVFHYGTXPIHXKOXBNQ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 Content-Disposition: inline; modification-date="Thu, 3 Apr 2019 15:50:39 +0100"

--KJOVFHYGTXPIHXKOXBNQ Content-ID: Content-Type: image/jpg Content-Transfer-Encoding: base64

--KJOVFHYGTXPIHXKOXBNQ--

[2019-04-23 19:29:38] local.INFO: --------- fetchStructure---------
[2019-04-23 19:29:38] local.INFO: $partNumber: 2.1
[2019-04-23 19:29:38] local.INFO: $structure->type: 0
[2019-04-23 19:29:38] local.INFO: $structure->subtype: HTML
[2019-04-23 19:29:38] local.INFO: $structure->ifdisposition: 1
[2019-04-23 19:29:38] local.INFO: $structure->parts: is set
[2019-04-23 19:29:38] local.INFO: $content2:
[2019-04-23 19:29:38] local.INFO:

Hi Kasper
This is a test email......
 
Regards
 
 
 
(signature images inline here in html) [2019-04-23 19:29:38] local.INFO: --------- fetchStructure--------- [2019-04-23 19:29:38] local.INFO: $partNumber: 2.2 [2019-04-23 19:29:38] local.INFO: $structure->type: 5 [2019-04-23 19:29:38] local.INFO: $structure->subtype: JPG [2019-04-23 19:29:38] local.INFO: $structure->ifdisposition: 0 [2019-04-23 19:29:38] local.INFO: $structure->parts: is set [2019-04-23 19:29:38] local.INFO: $content2: [2019-04-23 19:29:38] local.INFO: (an image) [2019-04-23 19:29:38] local.WARNING: The email body is empty for following subject: Test email @Webklex Would it help if you could receive the real e-mail instead and debug ? Thanks for trying though :)
MarouaneZizah commented 5 years ago

I have the same issue, this is the output of $message->getStructure() for the mail with the type 1 it returns empty body

{
  "type": 1,
  "encoding": 0,
  "ifsubtype": 1,
  "subtype": "ALTERNATIVE",
  "ifdescription": 0,
  "ifid": 0,
  "ifdisposition": 0,
  "ifdparameters": 0,
  "ifparameters": 1,
  "parameters": [
    {
      "attribute": "boundary",
      "value": "=_E61F1356043B1EE99CACC3E901FA04CB"
    }
  ],
  "parts": [
    {
      "type": 0,
      "encoding": 4,
      "ifsubtype": 1,
      "subtype": "PLAIN",
      "ifdescription": 1,
      "description": "plainpart",
      "ifid": 0,
      "lines": 202,
      "bytes": 3160,
      "ifdisposition": 1,
      "disposition": "inline",
      "ifdparameters": 0,
      "ifparameters": 1,
      "parameters": [
        {
          "attribute": "charset",
          "value": "UTF-8"
        }
      ]
    },
    {
      "type": 0,
      "encoding": 4,
      "ifsubtype": 1,
      "subtype": "HTML",
      "ifdescription": 1,
      "description": "htmlpart",
      "ifid": 0,
      "lines": 475,
      "bytes": 24725,
      "ifdisposition": 1,
      "disposition": "inline",
      "ifdparameters": 0,
      "ifparameters": 1,
      "parameters": [
        {
          "attribute": "charset",
          "value": "UTF-8"
        }
      ]
    }
  ]
}
kkriszx commented 5 years ago

I have the same problem. Some system or mailclient sending mails with type "multipart". The problem is in the fetchStructure() method as the others said.

my mail subtypes: PLAIN and HTML in the "parts" array, and "ifdisposition" value is "1" in both part. Your condition in the beginning of fetchStructure method not able to process my subtypes. The consequence is my content (html and plain) is empty.

I tried forward this message to other mail accont, but the outlook convert it to text typed message. So i cant send this mail for you :(

I dont know that mails meets the standard, but many customers send me such mails so its a real problem.

I hope it helps to solve this issue.

my fetched structure object:

object(stdClass)#875 (11) {
  ["type"]=>
  int(1)
  ["encoding"]=>
  int(0)
  ["ifsubtype"]=>
  int(1)
  ["subtype"]=>
  string(11) "ALTERNATIVE"
  ["ifdescription"]=>
  int(0)
  ["ifid"]=>
  int(0)
  ["ifdisposition"]=>
  int(0)
  ["ifdparameters"]=>
  int(0)
  ["ifparameters"]=>
  int(1)
  ["parameters"]=>
  array(1) {
    [0]=>
    object(stdClass)#869 (2) {
      ["attribute"]=>
      string(8) "boundary"
      ["value"]=>
      string(29) "----------=_1561117803-7184-0"
    }
  }
  ["parts"]=>
  array(2) {
    [0]=>
    object(stdClass)#867 (13) {
      ["type"]=>
      int(0)
      ["encoding"]=>
      int(4)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(5) "PLAIN"
      ["ifdescription"]=>
      int(0)
      ["ifid"]=>
      int(0)
      ["lines"]=>
      int(30)
      ["bytes"]=>
      int(1233)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(6) "inline"
      ["ifdparameters"]=>
      int(0)
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#866 (2) {
          ["attribute"]=>
          string(7) "charset"
          ["value"]=>
          string(5) "utf-8"
        }
      }
    }
    [1]=>
    object(stdClass)#865 (13) {
      ["type"]=>
      int(0)
      ["encoding"]=>
      int(4)
      ["ifsubtype"]=>
      int(1)
      ["subtype"]=>
      string(4) "HTML"
      ["ifdescription"]=>
      int(0)
      ["ifid"]=>
      int(0)
      ["lines"]=>
      int(24)
      ["bytes"]=>
      int(1804)
      ["ifdisposition"]=>
      int(1)
      ["disposition"]=>
      string(6) "inline"
      ["ifdparameters"]=>
      int(0)
      ["ifparameters"]=>
      int(1)
      ["parameters"]=>
      array(1) {
        [0]=>
        object(stdClass)#864 (2) {
          ["attribute"]=>
          string(7) "charset"
          ["value"]=>
          string(5) "utf-8"
        }
      }
    }
  }
}
kkriszx commented 5 years ago

@Webklex : what do you think about this fix (in Message.php line 665)? maybe this is right in other cases.

From:

($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber == null)

To:

($structure->ifdisposition == 1 && !isset($structure->parts) && $partNumber != null)
Qu1tR commented 5 years ago

@Webklex Hello, I see that you have made the changes as suggested before, in the condition of fetchStructure, however, AFTER the last release on 2nd of July (v1.4.2) I'm having the exact same issue with email bodies being blank. Everything goes back to normal, when I change the line in Message.php. So, while it may be a fix for that specific sender, it does affect not only that sender. Could you please look into this some more?

Webklex commented 5 years ago

Hi @AndriusStriupas , would you "donate" such a mail? :) I have no way to test it..

If so, please send it to imap_test[ a ]webklex.com.

Qu1tR commented 5 years ago

Hi @AndriusStriupas , would you "donate" such a mail? :) I have no way to test it..

If so, please send it to imap_test[ a ]webklex.com.

Hello, I've sent you the email as an attachment to the provided email. Have a read at my email body, there are some explanations. Hopefully it helps you.

jacm1993 commented 5 years ago

Hi friends, so what is the solution to this problem of bringing blank messages?

freescout-helpdesk commented 4 years ago

Same issue here with few examples: https://github.com/freescout-helpdesk/freescout/issues/320

Does anybody (@AndriusStriupas, @kkriszx, @kasperfd) have a recipe on how to reproduce the issue: 1) Open email client (which?) 2) Enter text (which?) 3) Send.

freescout-helpdesk commented 4 years ago

No need to check $structure->ifdisposition at all, it is not reliable.

Here is the solution:

1) Change condition in https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L662 to:

if ($structure->type == IMAP::MESSAGE_TYPE_TEXT &&
    (empty($structure->disposition) || strtolower($structure->disposition) != 'attachment')
) {

2) Condition on https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L721 can be removed:

} elseif ($structure->ifdisposition == 1 && strtolower($structure->disposition) == 'attachment') {
    if ($this->getFetchAttachmentOption() === true) {
        $this->fetchAttachment($structure, $partNumber);
    }
}
imc67 commented 4 years ago

Same issue here using Freescout @freescout-helpdesk, steps to reproduce:

  1. compose an email with Apple Mail iPhone client or Apple Mail MacOS client
  2. enter some text
  3. add an attachment
  4. after attachment use a signature or other text

Result:

  1. mail is received (in Freescout)
  2. text above the attachment in the original email is gone
  3. attachment is present
  4. text after attachment is visible

This is a rather serious issue as there are millions of Apple Mail users and as a receiver you don't know what you're missing.

freescout-helpdesk commented 4 years ago

@imc67 issues which you are experiencing in FreeScout please post here

imc67 commented 4 years ago

@freescout-helpdesk I'll do that immediately. The reason for putting it here was that you closed a similar ticket in your repository saying it was related to this ticket. Thanks for your response anyway :-)

SDCRoman commented 4 years ago

No need to check $structure->ifdisposition at all, it is not reliable.

Here is the solution:

  1. Change condition in https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L662 to:
if ($structure->type == IMAP::MESSAGE_TYPE_TEXT &&
  (empty($structure->disposition) || strtolower($structure->disposition) != 'attachment')
) {
  1. Condition on https://github.com/Webklex/laravel-imap/blob/master/src/IMAP/Message.php#L721 can be removed:
} elseif ($structure->ifdisposition == 1 && strtolower($structure->disposition) == 'attachment') {
  if ($this->getFetchAttachmentOption() === true) {
      $this->fetchAttachment($structure, $partNumber);
  }
}

I am currently on version 1.4.4. and this solved my issue. I had only to do step 1.