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] Fetching/Parsing wrong body part number for rfc822 parts #692

Open IZSkiSurfer opened 1 year ago

IZSkiSurfer commented 1 year ago

Afaik there is a bug in handling mails with an rfc822 subtype having an inline TYPETEXT.

I have some messages from postman regarding undelivered mails. The FETCHSTRUCTURE looks like this:

BODYSTRUCTURE (
    (
        (
            "text" "plain" ("charset" "US-ASCII") NIL NIL "quoted-printable" 14497 281 NIL NIL NIL NIL
        )
        (
            "text" "html" ("charset" "US-ASCII") NIL NIL "quoted-printable" 42739 743 NIL NIL NIL NIL
        )
        "alternative" ("boundary" "Boundary_(ID_5JKmWG1wHeFO8WEu2RSKgQ)" "differences" "Content-Type") NIL NIL
    )
    ("message" "delivery-status" NIL NIL NIL "7BIT" 375 NIL NIL NIL NIL)
    ("message" "rfc822" NIL NIL NIL "7BIT" 0 (
            "Wed, 21 Dec 2022 19:55:55 +0000" "MVT AH2700"
            ((...)) NIL NIL
            (
                (...)
            )
            (
                (...)
            ) NIL "<7590f5ca85135.639b9811@...>" "<7750d0ce88bb7.63a2f44b@...>"
        )
        (
            "text" "plain" ("charset" "US-ASCII") NIL NIL "7BIT" 39 3 NIL ("inline" NIL) "en" NIL
        ) 0 NIL NIL NIL NIL
    ) "report" ("boundary" "Boundary_(ID_yAv9GTaQKkAHj3anuu9EGQ)" "report-type" "delivery-status") NIL "en"
) UID 396206

php-imap tries to fetch a BODY[3.0] which does not exist.

exquIT: [4208] C: A0018 UID FETCH 396206 (BODY.PEEK[3.0])
exquIT: [4208] S: A0018 BAD Command Argument Error. 11

Afaik it's somehow related to https://www.php.net/manual/de/function.imap-fetchstructure.php#12485 (search for "funny really"). My guess is it's a problem with the flattenParts method. It propably needs to be part number 3.1 or maybe simply 3!?

Any geeks who might help?

IZSkiSurfer commented 1 year ago

https://p2p.wrox.com/pro-php/8658-fyi-parsing-imap_fetchstructure.html Might give a hint.