ddeboer / imap

Object-oriented, fully tested PHP IMAP library
MIT License
889 stars 253 forks source link

Notice undefined property in Attachment::getEmbeddedMessage() #453

Open keksa opened 4 years ago

keksa commented 4 years ago

I don't know how to reproduce this, we just received a crash report.

On this line: https://github.com/ddeboer/imap/blob/208a29fd4bb2c3240a10ebfb51cc84f5a16dad51/src/Message/Attachment.php#L61

We've got a notice:

Notice: Undefined property: stdClass::$parts

I think it might be because the getStructure() method only calls AbstractPart::lazyLoadStructure() and not AbstractPart::lazyParseStructure(), but I don't see into the code enough to know for sure.

Slamdunk commented 4 years ago

Mmm, no, for structure to be present lazyLoadStructure is enough.

The original raw message is needed to me for debugging the issue

keksa commented 4 years ago

Hello @Slamdunk, I'm sorry to say, but I don't have the original message and I have no way of getting it.

Is it really needed though? IMO just checking if there is a parts property in structure should be enough. In case there is no part from which to construct new structure I would just throw a NotEmbeddedMessageException. Since you require the structure being there, it makes the most sense to me.

Additionally this could be checked in the Attachment::isEmbeddedMessage().

ezade commented 4 years ago

@keksa @Slamdunk The problem arose because of a TypeError

In /ddeboer/imap/src/Message/Attachment.php on line 61

shouldn't the following line

return new EmbeddedMessage($this->resource, $this->getNumber(), $this->getPartNumber(), $this->getStructure()->parts[0]);

be replaced by return new EmbeddedMessage($this->resource, $this->getNumber(), $this->getPartNumber(), $this->getStructure());

?

Slamdunk commented 4 years ago

->parts[0] is needed for regular embedded messages, try to remove it and run the test suite.

A guard assertion would be good, but still we need a real example to better handle the case.

antoniofusco commented 3 years ago

Hello I have the same issue:

Notice:  Undefined property: stdClass::$parts in /vendor/ddeboer/imap/src/Message/Attachment.php on line 51
Notice:  Trying to access array offset on value of type null in /vendor/ddeboer/imap/src/Message/Attachment.php on line 51
Fatal error:  Uncaught TypeError: Argument 4 passed to Ddeboer\Imap\Message\AbstractPart::__construct() must be an instance of stdClass, null given, called in /vendor/ddeboer/imap/src/Message/Attachment.php on line 51 and defined in /vendor/ddeboer/imap/src/Message/AbstractPart.php:74
Stack trace:
#0 /vendor/ddeboer/imap/src/Message/Attachment.php(51): Ddeboer\Imap\Message\AbstractPart->__construct()

attachment-object.txt

Thanks

Slamdunk commented 3 years ago

@antoniofusco Can you paste here, with sensitive data obfuscated, the original mail that generated the error please?

antoniofusco commented 3 years ago

what do you mean by original email. Do you need the .eml file?

Slamdunk commented 3 years ago

Exactly, I need it to replicate the behavior in the test suite

antoniofusco commented 3 years ago

mmm, I cannot share the .eml I am sorry

antoniofusco commented 3 years ago

is the object not helpful?

Slamdunk commented 3 years ago

As I said, just strip any sensitive data:

  1. Each IP/DNS or domain can be set to 1.1.1.1/example.com
  2. Each name can be John Doe
  3. Each attachment content can be replaced by foo
  4. Each text can be replaced by foo too

The object doesn't help

antoniofusco commented 3 years ago

is there a way to get the .eml file from the library?

Slamdunk commented 3 years ago

$message->getRawMessage()

antoniofusco commented 3 years ago

Thanks,

Here the content of the .eml file downloaded from the webmail

Received: from example.com (1.1.1.1/example.com) by example.com (5.8.715.01)
        id 6062BA7B0030817F for email; Wed, 7 Apr 2021 15:42:35 +0200
Received: from [192.168.1.3] ([151.26.56.189])
    by smtp-33.iol.local with ESMTPA
    id U8S3lIwEKR8VAU8S3lLcgl; Wed, 07 Apr 2021 15:42:35 +0200
x-libjamoibt: 1601
DKIM-Signature: DKIM-Signature
X-CNFS-Analysis: v=2.4 cv=OapdsjfY c=1 sm=1 tr=0 ts=606db6cb cx=a_exe
 a=zgQP26mVt5qJHDBbPw+dTw==:117 a=zgQP26mVt5qJHDBbPw+dTw==:17
 a=cs4TwIhsDtR7jx_pK5cA:9 a=QEXdDO2ut3YA:10 a=O3BSzL-NfjQ7-Z9sUR0A:9
 a=Eh59t4TRhDAA:10 a=m-Z_27IZkzAA:10 a=Kdbpdt8TAAAA:8 a=QQMVkDJmAAAA:8
 a=jdjLEVCnzNLDzOMku8gA:9 a=yF+Lej8VMLx8D+W9JUKAdI9maSY=:19 a=UERqH62pugEA:10
 a=f3Gq4qMEfRcEZIHzMf47:22 a=aSwMGaGY8aNtKDSVnBfA:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22
 a=bWyr8ysk75zN3GCy5bjg:22
Date: Wed, 07 Apr 2021 15:42:34 +0200
From: email
Message-ID: Message-ID
Subject: Subject
To: c2luaXN0cmlkYWxsYm9nZ0BsZWdhbG1haWwuaXQ=
 <DEST>
References: References
MIME-Version: 1.0
Content-Type: multipart/report; report-type=disposition-notification;
    boundary="------------mdn62E58E45C983D9C9435C616A"
X-CMAE-Envelope: MS4xfP4PzTeurRCDFgOemG9RGPEJJPPlKldJqZYCJyfg/TEWOvQ7bUHU2NyUP9uMX2S0ghbopu251p+MrkFsrM1OZfIvLGMye0Si7QoFsBiEoRQKKQNJhPRp
 X3hsAiv8lgyd9gzTejffAW2ME1Gl7RvslZBSmVzLd5eL+vWXZfLVRgsPeEjXzHJ4LQvDoRvhhPXbux8fqz2V3XMktiHfA9y7p/0=

--------------mdn62E58E45C983D9C9435C616A
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
BODY
--------------mdn62E58E45C983D9C9435C616A
Content-Type: message/disposition-notification; name="MDNPart2.txt"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Reporting-UA: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0
Final-Recipient: rfc822;Final-Recipient
Original-Message-ID: Original-Message-ID
Disposition: manual-action/MDN-sent-manually; displayed

--------------mdn62E58E45C983D9C9435C616A
Content-Type: text/rfc822-headers; name="MDNPart3.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Return-Path: <email>
Delivered-To: email
Received: from dcd-12 ([10.103.10.25])
    by dcbackend-36.iol.local with LMTP id cGv9EpenbWBDHQQA0mtumg
    for ; Wed, 07 Apr 2021 14:37:43 +0200
Received: from dcp-17.iol.local ([10.103.10.25])
    by dcd-12 with LMTP id YI3cEpenbWDx/wAAo7Ek4Q
    ; Wed, 07 Apr 2021 14:37:43 +0200
Received: from libero.it ([10.103.10.25])
    by dcp-17.iol.local with LMTP id SPM3D5enbWBxdQEAXmhDwA
    ; Wed, 07 Apr 2021 14:37:43 +0200
Received: from 
    by smtp-25.iol.local with ESMTP
    id U7RGlNslso08DU7RGlxdnA; Wed, 07 Apr 2021 14:37:43 +0200
X-IOL-DMARC: X-IOL-DMARC
X-IOL-DKIM: X-IOL-DKIM
X-IOL-SPF: X-IOL-SPF
X-IOL-SEC: _SPFOK_NODKIM_NODMARC
x-fbsn: x-fbsn
x-libjamoibt: 2601
Received-SPF: pass
X-CNFS-Analysis: v=2.4 cv=dNdjJMVb c=1 sm=1 tr=0 ts=606da797 cx=a_exe
 a=eF99n0+kJaWlA6UO8X8FlA==:117 a=AjAyd5mc6WtYKcZ44Lqm7g==:17
 a=3YhXtTcJ-WEA:10 a=QQMVkDJmAAAA:8 a=tPUxibC-1i7YqQCDP7MA:9 a=wPNLvfGTeEIA:10
 a=0-mT0QOSfRYcpCXoKs0A:9 a=5Nb44pWDtQb_V56I:21 a=_W_S_7VecoQA:10
 a=r77TgQKjGQsHNAKrUKIA:9 a=RT134Wp91VU43VZs3bgA:9 a=QEXdDO2ut3YA:10
 a=KobOExqYxX0A:10 a=JHi4H5UT99yyDx_wqjEA:9 a=jjlfnWhyjRlJA0mAGF8A:9
 a=IKIoO-ieCDEA:10 a=aW-bZQx6DCYA:10 a=Yy2xoct6d_2ZlxTvqP-Z:22
 a=2Y-vvK4RtTjk8tdDCeaJ:22 a=e1bHTynNcurks996NJsQ:22 a=5MxXyNQ-P-6J4PTiW665:22
 a=-UBWlq5PF8_PtPJzeHtb:22 a=wlUwIh43bdezdDEJ2Pn8:22 a=OuUWKbJwWYUocdwMygcA:9
 a=zJJgJrR4LD4A:10 a=A4eEXqY5kCutICW5W5kA:9 a=ZVk8-NSrHBgA:10
 a=aSwMGaGY8aNtKDSVnBfA:22 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22
Received: 
        id 5DCD02D60859E26A; Wed, 7 Apr 2021 14:37:31 +0200
Received: by Received
Received: 
        id 6062B6A500219499; Wed, 7 Apr 2021 14:37:26 +0200
Date: Wed, 7 Apr 2021 12:37:28 +0000
From: From
Sender: Sender
Reply-To: Reply-To
To: To
Message-ID: Message-ID
Subject: Subject
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-1; 
    boundary="----=_Part_210985685_910079062.1617799048429"
X-Priority: 1
Return-Receipt-To: Return-Receipt-To
Disposition-Notification-To: Disposition-Notification-To
X-Trasporto: posta-certificata
X-Riferimento-Message-ID:Message-ID
X-CMAE-Envelope: X-CMAE-Envelope
--------------mdn62E58E45C983D9C9435C616A--
antoniofusco commented 3 years ago

is this helpful?

Slamdunk commented 3 years ago

I need time to debug it, hope to have a look in the next month

antoniofusco commented 3 years ago

in the meantime, could you tell me how to escape it? I tried with a try catch but nothing Thanks

Slamdunk commented 3 years ago

I don't think you can escape it.

Any PR is welcome