8000 [9.x] Fix mails with tags and metadata are not queuable by joostdebruijn · Pull Request #41028 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Fix mails with tags and metadata are not queuable #41028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: mail could have multiple tags
  • Loading branch information
joostdebruijn committed Feb 15, 2022
commit e760553e300c975bc6b68919830a578f0fa0d3e3
20 changes: 11 additions & 9 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ class Mailable implements MailableContract, Renderable
protected $metadata = [];

/**
* The tag for the message.
* The tags for the message.
*
* @var string
* @var array
*/
protected $tag;
protected $tags = [];

/**
* The callback that should be invoked while building the view data.
Expand Down Expand Up @@ -204,7 +204,7 @@ public function send($mailer)
$this->buildFrom($message)
->buildRecipients($message)
->buildSubject($message)
->buildTag($message)
->buildTags($message)
->buildMetadata($message)
->runCallbacks($message)
->buildAttachments($message);
Expand Down Expand Up @@ -422,15 +422,17 @@ protected function buildSubject($message)
}

/**
* Set the tag for the message.
* Set the tags for the message.
*
* @param \Illuminate\Mail\Message $message
* @return $this
*/
protected function buildTag($message)
protected function buildTags($message)
{
if ($this->tag) {
$message->getHeaders()->add(new TagHeader($this->tag));
if ($this->tags) {
foreach ($this->tags as $tag) {
$message->getHeaders()->add(new TagHeader($tag));
}
}

return $this;
Expand Down Expand Up @@ -932,7 +934,7 @@ public function attachData($data, $name, array $options = [])
*/
public function tag($value)
{
$this->tag = $value;
array_push($this->tags, $value);
return $this;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ protected function buildMessage($mailMessage, $notifiable, $notification, $messa
$mailMessage->setPriority($message->priority);
}

if ($message->tag) {
$mailMessage->getHeaders()->add(new TagHeader($this->tag));
if ($message->tags) {
foreach ($message->tags as $tag) {
$mailMessage->getHeaders()->add(new TagHeader($tag));
}
}

if ($message->metadata) {
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class MailMessage extends SimpleMessage implements Renderable
public $metadata = [];

/**
* The tag for the message.
* The tags for the message.
*
* @var string
* @var array
*/
public $tag;
public $tags = [];

/**
* Set the view for the mail message.
Expand Down Expand Up @@ -275,7 +275,7 @@ public function attachData($data, $name, array $options = [])
*/
public function tag($value)
{
$this->tag = $value;
array_push($this->tags, $value);
return $this;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,13 @@ public function testMailableTagGetsSent()
$mailable->html('test content');

$mailable->tag('test');
$mailable->tag('foo');

$sentMessage = $mailer->send($mailable);

$this->assertSame('hello@laravel.com', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress());
$this->assertStringContainsString('X-Tag: test', $sentMessage->toString());
$this->assertStringContainsString('X-Tag: foo', $sentMessage->toString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Notifications/NotificationMailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testTagIsSetCorrectly()
$message = new MailMessage;
$message->tag('test');

$this->assertSame('test', $message->tag);
$this->assertContains('test', $message->tags);
}

public function testCallbackIsSetCorrectly()
Expand Down
0