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

$oAttachment->getContent() retorna false #526

Open
YaszCarol opened this issue Oct 24, 2024 · 1 comment
Open

$oAttachment->getContent() retorna false #526

YaszCarol opened this issue Oct 24, 2024 · 1 comment

Comments

@YaszCarol
Copy link

Após a conexao e pegar as mensagens, o codigo é
foreach ($aMessage as $oMessage) {

                        if ($oMessage->hasAttachments()) {
                            $aAttachment = $oMessage->getAttachments();
                            $aAttachment->each(function ($oAttachment) {

                                dd($oAttachment->getContent());
 dessa forma me retornando false quando existe o arquivo no e-mail, o objeto Webklex\IMAP\Attachment é criado certinho e existe o atributo dessa forma:
 +attachments: Webklex\IMAP\Support\AttachmentCollection {#12668
  #total: null
  #items: array:1 [
    0 => Webklex\IMAP\Attachment {[#7072](https://github.com/Webklex/php-imap/issues/new?assignees=&labels=&projects=&template=general-help-request.md#sf-dump-1888554629-ref27072)}
  ]
}
alguém consegue me dizer o porque nao consigo obter o conteudo desse arquivo com $oAttachment->getContent() ?
@YaszCarol
Copy link
Author

YaszCarol commented Oct 30, 2024

Após alguns dias de investigação, identifiquei a origem do problema: a função decodeString estava utilizando a função nativa imap_base64, que, por algum motivo, não conseguia decodificar corretamente o conteúdo em Base64. Acredito que o erro tenha ocorrido devido a quebras de linha no texto codificado.

Para corrigir, adicionei o seguinte código no case IMAP::MESSAGE_ENC_BASE64:

$content = \imap_base64($string);
if (!$content) {
$content = base64_decode($string);
}
return $content;
Essa alteração resolveu o problema, e agora a decodificação funciona corretamente!

{9E68DC62-E0BA-4318-B0A4-599804D74781}

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

No branches or pull requests

1 participant