Skip to content

Commit 6c2f9e8

Browse files
committed
Allow skipping mail sending if a listener to MessageSending returned false
1 parent 7282e2c commit 6c2f9e8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Illuminate/Mail/Mailer.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ protected function createMessage()
428428
*/
429429
protected function sendSwiftMessage($message)
430430
{
431-
if ($this->events) {
432-
$this->events->dispatch(new Events\MessageSending($message));
431+
if (! $this->shouldSendMessage($message)) {
432+
return;
433433
}
434434

435435
try {
@@ -439,6 +439,23 @@ protected function sendSwiftMessage($message)
439439
}
440440
}
441441

442+
/**
443+
* Determines if the message can be sent.
444+
*
445+
* @param \Swift_Message $message
446+
* @return bool
447+
*/
448+
protected function shouldSendMessage($message)
449+
{
450+
if (! $this->events) {
451+
return true;
452+
}
453+
454+
return $this->events->until(
455+
new Events\MessageSending($message)
456+
) !== false;
457+
}
458+
442459
/**
443460
* Force the transport to re-connect.
444461
*

0 commit comments

Comments
 (0)