Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem with attachments #548

Open
blackxel opened this issue Feb 12, 2025 · 0 comments
Open

Problem with attachments #548

blackxel opened this issue Feb 12, 2025 · 0 comments

Comments

@blackxel
Copy link

Describe the bug
This email should have attachments.

Code to Reproduce

$eml = <<<EML
Delivered-To: mail@mail.com
Received: by 2002:a05:6400:62b5:b0:27c:7b7b:895b with SMTP id kv53csp168015ecb;
        Tue, 4 Feb 2025 04:13:47 -0800 (PST)
Return-Path: <inbox@cloud.bxexpress.cl>
DKIM-Signature: v=1; a=rsa-sha256; c=simple;
    d=cloud.bxexpress.cl; s=default; r=y; l=19018; t=1738671297;
    x=1739276097; i=inbox@cloud.bxexpress.cl; q=dns/txt; h=InvoixSignature:
    Message-ID:MIME-Version:From:To:Date:Subject:Content-Type; z=Rec
    eived:=20from=20169.254.3.185=20[(34.200.193.86)]=20by=20cloud.g
    dexpress.cl=20with=20ESMTPSA=20id=20md5001028814655.msg=3B=20=0D
    =0A=09Tue,=2004=20Feb=202025=2009=3A14=3A56=20-0300|InvoixSignat
    ure:=20Rr1k5jv/K5uM6tNO7D2nrHEn+/bhDFYKOlemyHBwocUmUSGKSt2ZtCOjI
    ChG/MZEBt6MPkzAVCiU4JUzpLyAsKDWyj/fV+nXdxzy9gYelPcaHxUF0LeZe7ZLh
    PkEICEG|Message-ID:=20<XML_DTE_76946917-6_33_92838_0_20250204121
    340@cloud.bxexpress.cl>|MIME-Version:=201.0|From:=20"BXExpress"=
    20<inbox@cloud.bxexpress.cl>|To:=20mail@mail.com|Date:=204=20
    Feb=202025=2012=3A13=3A43=20+0000|Subject:=20=3D?utf-8?B?RmFjdHV
    yYSBFbGVjdHLDs25pY2EgOTI4MzggZGVsIDAzLzAy?=3D=0D=0A=20=3D?utf-8?
    B?LzIwMjUgZW1pdGlkYSBwb3IgRUxFQ1RSSUNJREFEIENBTExFSkFTIFNQ?=3D=0
    D=0A=20=3D?utf-8?B?QSBwYXJhIDc2NDY2MjQ1LTg=3D?=3D|Content-Type:=
    20multipart/mixed=3B=0D=0A=20boundary=3D--boundary_54_7771d5fe-3
    6a2-4520-b9c5-f65735f817b5; bh=5xfWXdA485Hl/XUGTYNfYDP77e7bOJ+h4
    zzSFd0sgGY=; b=CDb8NkFSwht6q8wQyPxpWR0dYZiJij+NMdNsvIAVFxsBL4+0k
    bR6MSdMX6JDyiJHMFyqKqUW6B9kSbUsXjDbRRXO3XSJvpSGDi00I40DqBcR+vwRk
    EMqmkT4eUeyl1Qt2liz4lF6/8jE/EuWDyOc3gGowEuYlFS/OxF91IVX1OGOBC0bb
    WEUro0nz3p1An1SY7B+2/v5z/c1NzfZNaCgVRXDQZoqQTkJkYFpfQ4kbJLrumRkq
    BEJ9MIwLKai2JZ8YLi+GlAlc3j7GwQUJVsKDZMvGPM1RRO+E0kdOvhdgdSPCc8u5
    k+hXw1FR0GXGeDDaFRiMYXRz84AA/VOdH2ulg==
Received: from 169.254.3.185 [(34.200.193.86)] by cloud.bxexpress.cl with ESMTPSA id md5001028814655.msg;
    Tue, 04 Feb 2025 09:14:56 -0300
Message-ID: <XML_DTE_76946917-6_33_92838_0_20250204121340@cloud.bxexpress.cl>
MIME-Version: 1.0
From: "BXExpress" <inbox@cloud.bxexpress.cl>
To: mail@mail.com
Date: 4 Feb 2025 12:13:43 +0000
Subject: =?utf-8?B?RmFjdHVyYSBFbGVjdHLDs25pY2EgOTI4MzggZGVsIDAzLzAy?=
    =?utf-8?B?LzIwMjUgZW1pdGlkYSBwb3IgRUxFQ1RSSUNJREFEIENBTExFSkFTIFNQ?=
    =?utf-8?B?QSBwYXJhIDc2NDY2MjQ1LTg=?=
Content-Type: multipart/mixed;
    boundary=--boundary_54_7771d5fe-36a2-4520-b9c5-f65735f817b5


----boundary_54_7771d5fe-36a2-4520-b9c5-f65735f817b5
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64

PGRpdiBkaXI9Imx0ciI+PGRpdiBjbGFzcz0iZ21haWxfZGVmYXVsdCIgc3R5bGU9ImZv
bnQtZmFtaWx5OnRhaG9tYSxzYW5zLXNlcmlmIj5UZXN0PC9kaXY+PC9kaXY+
----boundary_54_7771d5fe-36a2-4520-b9c5-f65735f817b5
Content-Type: application/octet-stream;
    name=ed9f1e16-4ba3-47f3-b219-4641a83017ac.xml
Content-Transfer-Encoding: base64
Content-Disposition: attachment

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHRlc3Q+MTwvdGVz
dD4=
----boundary_54_7771d5fe-36a2-4520-b9c5-f65735f817b5--
EML;
$message =  Webklex\PHPIMAP\Message::fromString($eml);
var_dump($message->hasAttachments());//false :-/

I "Fixed" modifying the find function in src/Header.php

/**
 * Perform a regex match all on the raw header and return the first result
 * @param $pattern
 *
 * @return mixed|null
 */
public function find($pattern): mixed {
    if (preg_match_all($pattern, $this->raw, $matches)) {
        if (isset($matches[1])) {
            if (count($matches[1]) > 0) {
                //return $matches[1][0];
                $maxLength = 0;
                $item = '';
                foreach ($matches[1] as $match) {
                    if (strlen($match) > $maxLength) {
                        $maxLength = strlen($match);
                        $item = $match;
                    }
                }
                return $item;
            }
        }
    }
    return null;
}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant