swiftmailer/swiftmailer — pull request #518 by Nyholm (2014-08-27 15:44:25+00:00)
Title: [MemorySpool] Bugfix, message might change when in the memory spool

This is a bugfix for the memory spool. The behavior of the memory spool is not consistent with the file spool. This PR solves that issue.

The `Swift_Transport_SpoolTransport::send` does 3 things.

1. It may rewrite a `Message` on the `beforeSendPerformed` event.
2. Add the message to the spool
3. It may revert the rewrite on the `sendPerformed` event.

Since the `Message` object is not sent (or stored to a file like in `FileSpool`), the queued `Message` (in 2) will be the same object as the `Message` (in 3) that is being reverted from the rewrite. The result will be that the rewrite has no effect.

My solution is to serialize the message once it put on the queue. And then deserialize it when we flush the queue. This will make sure that the message will have the same properties when you send it as when you queue it.

(Cloning the message will not work. When you clone an object all the referenced objects will not be cloned.)

### In Symfony

I found this bug when I had the following configuration in my Symfony application:

``` js
default:
transport: whatever
host: example.com
username: %mailer_user%
password: %mailer_password%
delivery_address: dev@example.com
spool:
type: memory
```

The emails would not be sent to `dev@example.com`. It would work if I did not use a spool or if I used the file spool.