beforeSendPerformed event is called twice with memory spool #139
Comments
@fabpot: Ping. Enabling it as mentioned in symfony/symfony-standard@4ab6de1, the issue still persists. |
Here's a listener which demonstrates the issue: <?php
class MyListener implements \Swift_Events_SendListener {
private $timesCalled = 0;
public function beforeSendPerformed(\Swift_Events_SendEvent $evt) {
++$this->timesCalled;
$message = $evt->getMessage();
$message->setBody($message->getBody() . $this->timesCalled);
}
} Because it's called twice, |
…olas Appriou) This PR was merged into the 5.3-dev branch. Discussion ---------- fix issue #443 #139 spool send event result Here is a PR for issues #443 and #139. We've added a new result status in SendEvents with code 0x11 (RESULT_PENDING | RESULT_SPOOLED). It seems logical to us because this status lies between those two status. The SpoolTransport now set RESULT_SPOOLED instead of RESULT_SUCCESS in order to be able to make the difference between a spooled mail and a sent mail. Unit tests fails, but it wasn't due to anything that we've added. The master branch unit tests was already broken when we cloned the project. Commits ------- 7b20f44 empty commit 33fa890 fix issue #443 #139 spool send event result
I'm also having this issue with file spool (using the current version 5.4.0). The event is triggered the 1st time when generating the mail and storing it in a file, then the 2nd time when it's actually being sent. I'm using this event to append some footer text to each mail, which is unfortunately done twice. @fabpot: It's a rather old issue. Do you even consider this to be a bug (which will be fixed some day) or do I need to make up a workaround? |
The status is |
I concur with @craue, in the beforeSendPerformed method the status is RESULT_PENDING in both instances so there is no way to differentiate. |
Anyone willing to submit a PR? |
I am also experiencing this issue - would an acceptable fix be changing the event target that is dispatched from |
Do anyone knows how to avoid this issue now? |
Look, maybe it helps https://github.com/appaydin/pd-mailer/blob/master/SwiftMailer/SendListener.php |
I came across this issue today, the easiest solution I found was to create an array with the key/or value of $message->getId() and checking against that before doing anything with the message. Not sure if it's fool proof, or if it would work in all use cases but maybe this will help someone. |
Using the memory spool added in d44b7fc,
beforeSendPerformed
of aSwift_Events_SendListener
is called twice.The text was updated successfully, but these errors were encountered: