Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Can't fetch some attachments #150

Closed
EthraZa opened this issue Aug 11, 2021 · 3 comments
Closed

Can't fetch some attachments #150

EthraZa opened this issue Aug 11, 2021 · 3 comments

Comments

@EthraZa
Copy link

EthraZa commented Aug 11, 2021

I'm unable to fetch attachment from some senders messages.

It's maybe related to #142

An eml sample with this problem:
CantGetAttachment.eml.txt

And here is the output of var_dump($message->getAttachments()):
CantGetAttachment.log.txt

As it can be seen on log at line 938, looks like it's getting the XML attachment and the body together:

       ["structure":protected]=>
        object(Webklex\PHPIMAP\Structure)#255 (5) {
          ["raw"]=>
          string(13973) "----AaZz
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline

Segue, em anexo, em caráter meramente comercial, o arquivo da nota fiscal eletrônica 2798556, de 11/08/2021 com chave de acesso 33210834274233009584550000027985561873768020.
Informamos que, independente deste envio, o arquivo da mesma ficará à disposição, para download, na aplicação Canal de Negócios do Portal BR, no endereço www.br.com.br.

----AaZz
Content-Type: application/xml; charset="UTF-8";
	name="NF-e_33210834274233009584550000027985561873768020.xml"
Content-Disposition: attachment;
	filename="NF-e_33210834274233009584550000027985561873768020.xml"
Content-Transfer-Encoding: base64

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PG5m
ZVByb2MgeG1sbnM9Imh0dHA6Ly93d3cucG9ydGFsZmlzY2FsLmluZi5ici9uZmUiIHZlcnNhbz0i
...

Versions:

$ php -v
PHP 8.0.9 (cli) (built: Jul 31 2021 08:10:26) ( NTS )

$ grep -A1 php-imap composer.lock 
            "name": "webklex/php-imap",
            "version": "2.5.1",

There's something I can do to get it working right?
Or, could you please point me to the file or method that could be tweked?
(This code is in production and will explode on me soon!)

Thank you.

EthraZa added a commit to EthraZa/php-imap that referenced this issue Aug 16, 2021
Resolves Webklex#150 where there is other header params in the same line of boundary
@EthraZa
Copy link
Author

EthraZa commented Aug 20, 2021

I have made a PR changing getBoundary function regex of 2.5.1 version (Header.php)
from
"/boundary\=(.*)/i"
to
"/boundary=(.*?(?=;)|(.*))/i"

but just found out that till version 2.4.3, is was (Structure.php)
"/boundary=\"?([^\"]*)[\";\s]/"
that seen to work as well.

Please, someone who understand RegEx better, take a look at this changes.

This is my poor's man test with parts from 2 e-mails headers:

<?php

#$p='/boundary\=(.*)/i'; # 2.5.1
##$p='/boundary=(.*?(?=;)|(.*))/i'; # PR #152 
$p="/boundary=\"?([^\"]*)[\";\s]/"; # 2.4.3

$s1='Organization: GHSix
Content-Type: multipart/mixed;
 boundary="=_34f19e771ef672441eab76cca3808103"

--=_34f19e771ef672441eab76cca3808103';

$s2='Message-ID: <OFC5EC803D.5298C025-ON0325872E.003DCA9D@br-petrobras.com.br>
Content-Type: multipart/mixed; boundary="--AaZz"; filename="untitled.txt"
Content-Disposition: nf-e_33210834274233009584550000027985561873768020.xml';


preg_match_all($p, $s1, $m1);
preg_match_all($p, $s2, $m2);

print_r([$m1, $m2]);

@EthraZa
Copy link
Author

EthraZa commented Oct 7, 2021

There is something wrong with my PR? I's almost 2 months pending already.

@Webklex
Copy link
Owner

Webklex commented Mar 8, 2022

Hi @EthraZa ,
I believe this issue is fixed. If I'm wrong please feel free to reopen this issue. Thanks again for your help and support!

Best regards,

@Webklex Webklex closed this as completed Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants