From 7ff7ce6f191373eb1e65bda61f934e77ae2c9a07 Mon Sep 17 00:00:00 2001 From: paulwer Date: Wed, 28 Aug 2024 10:08:48 +0200 Subject: [PATCH] brevo fixes --- app/Jobs/Brevo/ProcessBrevoInboundWebhook.php | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php b/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php index 30f741c69ed6..b0ea10eaa47c 100644 --- a/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php +++ b/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php @@ -23,6 +23,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Http\UploadedFile; class ProcessBrevoInboundWebhook implements ShouldQueue { @@ -162,29 +163,44 @@ class ProcessBrevoInboundWebhook implements ShouldQueue // download file and save to tmp dir if (!empty($company_brevo_secret)) { - $data = null; try { $brevo = new InboundParsingApi(null, Configuration::getDefaultConfiguration()->setApiKey("api-key", $company_brevo_secret)); - $data = $brevo->getInboundEmailAttachment($attachment["DownloadToken"]); + $inboundMail->documents[] = new UploadedFile( + $brevo->getInboundEmailAttachment($attachment["DownloadToken"])->getPathname(), + $attachment["Name"], + $attachment["ContentType"], + 0, + true // Mark it as test, since the file isn't from real HTTP POST. + ); } catch (\Error $e) { if (config('services.brevo.secret')) { nlog("[ProcessBrevoInboundWebhook] Error while downloading with company credentials, we try to use default credentials now..."); $brevo = new InboundParsingApi(null, Configuration::getDefaultConfiguration()->setApiKey("api-key", config('services.brevo.secret'))); - $data = $brevo->getInboundEmailAttachment($attachment["DownloadToken"]); + $inboundMail->documents[] = new UploadedFile( + $brevo->getInboundEmailAttachment($attachment["DownloadToken"])->getPathname(), + $attachment["Name"], + $attachment["ContentType"], + 0, + true // Mark it as test, since the file isn't from real HTTP POST. + ); } else throw $e; } - $inboundMail->documents[] = TempFile::UploadedFileFromRaw($data, $attachment["Name"], $attachment["ContentType"]); } else { $brevo = new InboundParsingApi(null, Configuration::getDefaultConfiguration()->setApiKey("api-key", config('services.brevo.secret'))); - $inboundMail->documents[] = TempFile::UploadedFileFromRaw($brevo->getInboundEmailAttachment($attachment["DownloadToken"]), $attachment["Name"], $attachment["ContentType"]); - + $inboundMail->documents[] = new UploadedFile( + $brevo->getInboundEmailAttachment($attachment["DownloadToken"])->getPathname(), + $attachment["Name"], + $attachment["ContentType"], + 0, + true // Mark it as test, since the file isn't from real HTTP POST. + ); } }