Webklex / laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
https://www.php-imap.com
MIT License
637 stars 181 forks source link

replace email inline image url using mask #400

Closed nehemmiah closed 3 years ago

nehemmiah commented 3 years ago

hello, so i've been trying to understand how to use mask since i read the code and it has function to replace the image url inside the mail. i'm referencing to the getHTMLBodyWithEmbeddedBase64Images() i'm new to this so the first question is : what is mask? and then the main question, how to use it?

this is the code for my controller

$oClient = Client::account('default');
        $oClient->connect();

        $message_mask = \Webklex\PHPIMAP\Support\Masks\MessageMask::class;
        $oClient->setDefaultMessageMask($message_mask);

        /** @var \Webklex\IMAP\Folder $oFolder */
        $aFolder = $oClient->getFolders('INBOX');

        foreach($aFolder as $oFolder){

            /** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
            try {
                $aMessage = $oFolder->query()->getMessageByUid($id);
            } catch (\Throwable $th) {
                return 'error';
            }

        }

        $message_mask = $aMessage->mask();
        $mail = $aMessage;
        // $mailbody = $mail->getHtmlBody();

        return view("email.show", compact('mail'));

and this is on the blades view,

{!! $mail->getHtmlBody() !!}

i tried using

{!! $mail->getHTMLBodyWithEmbeddedBase64Images() !!}
or
{!! $mail->getCustomHTMLBody() !!}

but it just returned null

i hope i can get some help with this, thank you

Webklex commented 3 years ago

Hi @nehemmiah , please try to use $message_mask instead of $mail. In your case the masked instance is stored in $message_mask and not in $mail. If you want or have to use $mail, try using $mail->mask() instead.

Best regards,