Skip to content

Commit

Permalink
Allow skipping mail sending if a listener to MessageSending returned …
Browse files Browse the repository at this point in the history
…false
  • Loading branch information
themsaid committed Mar 7, 2017
1 parent 7282e2c commit 6c2f9e8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ protected function createMessage()
*/
protected function sendSwiftMessage($message)
{
if ($this->events) {
$this->events->dispatch(new Events\MessageSending($message));
if (! $this->shouldSendMessage($message)) {
return;
}

try {
Expand All @@ -439,6 +439,23 @@ protected function sendSwiftMessage($message)
}
}

/**
* Determines if the message can be sent.
*
* @param \Swift_Message $message
* @return bool
*/
protected function shouldSendMessage($message)
{
if (! $this->events) {
return true;
}

return $this->events->until(
new Events\MessageSending($message)
) !== false;
}

/**
* Force the transport to re-connect.
*
Expand Down

0 comments on commit 6c2f9e8

Please sign in to comment.