You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Using laravel-imap, I receive emails from mail and pass them to handlers in laravel queues. When passed to the queue, the object is serialized to JSON in the Illuminate\Queue\Queue::create Payload() method. As a result, I get an error:
Illuminate\Queue\InvalidPayloadException Unable to JSON encode payload. Error code: 5.
--
() at vendor/laravel/framework/src/Illuminate/Queue/Queue.php:108
Illuminate\Queue\Queue->createPayload() at vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:92
Illuminate\Queue\DatabaseQueue->push() at vendor/laravel/framework/src/Illuminate/Queue/Queue.php:57
Illuminate\Queue\Queue->pushOn() at vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:591
Illuminate\Events\Dispatcher->queueHandler() at vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:515
Illuminate\Events\Dispatcher->Illuminate\Events\{closure}() at vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:441
Illuminate\Events\Dispatcher->Illuminate\Events\{closure}() at vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:249
Illuminate\Events\Dispatcher->dispatch() at vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:433
event() at vendor/laravel/framework/src/Illuminate/Foundation/Events/Dispatchable.php:14
App\Events\EmailReceived::dispatch() at eval()'d code:2
eval() at vendor/psy/psysh/src/ExecutionLoopClosure.php:53
Psy\{closure}() at vendor/psy/psysh/src/ExecutionClosure.php:89
Psy\ExecutionClosure->execute() at vendor/psy/psysh/src/Shell.php:395
Psy\Shell->doInteractiveRun() at vendor/psy/psysh/src/Shell.php:366
Psy\Shell->doRun() at vendor/symfony/console/Application.php:168
Symfony\Component\Console\Application->run() at vendor/psy/psysh/src/Shell.php:341
Psy\Shell->run() at vendor/laravel/tinker/src/Console/TinkerCommand.php:85
Laravel\Tinker\Console\TinkerCommand->handle() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at vendor/laravel/framework/src/Illuminate/Container/Util.php:41
Illuminate\Container\Util::unwrapIfClosure() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
Illuminate\Container\BoundMethod::callBoundMethod() at vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:35
Illuminate\Container\BoundMethod::call() at vendor/laravel/framework/src/Illuminate/Container/Container.php:662
Illuminate\Container\Container->call() at vendor/laravel/framework/src/Illuminate/Console/Command.php:208
Illuminate\Console\Command->execute() at vendor/symfony/console/Command/Command.php:312
Symfony\Component\Console\Command\Command->run() at vendor/laravel/framework/src/Illuminate/Console/Command.php:177
Illuminate\Console\Command->run() at vendor/symfony/console/Application.php:1040
Symfony\Component\Console\Application->doRunCommand() at vendor/symfony/console/Application.php:314
Symfony\Component\Console\Application->doRun() at vendor/symfony/console/Application.php:168
Symfony\Component\Console\Application->run() at vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:200
Illuminate\Foundation\Console\Kernel->handle() at artisan:35
Describe the solution you'd like
For the solution, I added the methods __serialize() and __unserialize to the event object. After studying the source code of the \Webklex\PHPIMAP\Message class, I decided to do it by analogy with the save() and fromString() methods. It turned out the following:
<?phpnamespaceApp\Events;
useIlluminate\Broadcasting\InteractsWithSockets;
useIlluminate\Foundation\Events\Dispatchable;
useIlluminate\Queue\SerializesModels;
useWebklex\PHPIMAP\ClientManager;
useWebklex\PHPIMAP\Message;
class EmailReceived
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
/** * Create a new event instance. */publicfunction__construct(
publicMessage$message
) {
//
}
publicfunction__serialize()
{
return [
'message' => $this->message->getHeader()->raw . "\r\n\r\n" . $this->message->getRawBody(),
];
}
publicfunction__unserialize(array$values)
{
// Load config for \Webklex\PHPIMAP\Message classnewClientManager();
$this->message = Message::fromString($values['message']);
}
}
I think the same solution can be applied for the \Webklex\PHPIMAP\Message class
Describe alternatives you've considered
Initially, I tried to solve the problem by serializing the \Webklex\PHPIMAP\Message object, but I wanted the event to accept an instance of the class, not a string.
In addition, serialize() and unserialize() incorrectly expand Attribute and adjacent objects. I found this fix in the issue to webklex\phpimap: #179.
Additional context
Without initializing new Client Manager();, the method \Webklex\PHPIMAP\Message::fromString() does not work. Therefore, I had to initialize it in the __unserialize() method. Perhaps there is a better solution?
This is what I get if I don't initialize new \Webklex\PHPIMAP\ClientManager():
Cannot assign null to property Webklex\PHPIMAP\Message::$config of type array {"exception":"[object] (TypeError(code: 0): Cannot assign null to property Webklex\\PHPIMAP\\Message::$config of type array at /run/media/mrfriz/Windows/xampp/htdocs/carzaem.local/vendor/webklex/php-imap/src/Message.php:368)\n[previous exception] [object] (TypeError(code: 0): Cannot assign null to property Webklex\\PHPIMAP\\Message::$config of type array at /run/media/mrfriz/Windows/xampp/htdocs/carzaem.local/vendor/webklex/php-imap/src/Message.php:368)"}
The text was updated successfully, but these errors were encountered:
Hi @vmrfriz ,
many thanks for your suggestion. I like the idea, but I'm afraid of another big "thing" - how to handle the active client connection? Or have you tested it and it already restores itself somehow?
Is your feature request related to a problem? Please describe.
Using laravel-imap, I receive emails from mail and pass them to handlers in laravel queues. When passed to the queue, the object is serialized to JSON in the
Illuminate\Queue\Queue::create Payload()
method. As a result, I get an error:Describe the solution you'd like
For the solution, I added the methods
__serialize()
and__unserialize
to the event object. After studying the source code of the\Webklex\PHPIMAP\Message
class, I decided to do it by analogy with thesave()
andfromString()
methods. It turned out the following:I think the same solution can be applied for the
\Webklex\PHPIMAP\Message
classDescribe alternatives you've considered
Initially, I tried to solve the problem by serializing the \Webklex\PHPIMAP\Message object, but I wanted the event to accept an instance of the class, not a string.
In addition,
serialize()
andunserialize()
incorrectly expand Attribute and adjacent objects. I found this fix in the issue to webklex\phpimap: #179.Additional context
Without initializing
new Client Manager();
, the method\Webklex\PHPIMAP\Message::fromString()
does not work. Therefore, I had to initialize it in the__unserialize()
method. Perhaps there is a better solution?This is what I get if I don't initialize
new \Webklex\PHPIMAP\ClientManager()
:The text was updated successfully, but these errors were encountered: