diff --git a/src/Mail/ResentMessage.php b/src/Mail/ResentMessage.php index 1dfcd43..3da659c 100644 --- a/src/Mail/ResentMessage.php +++ b/src/Mail/ResentMessage.php @@ -66,11 +66,13 @@ public function build(): static $this->withSymfonyMessage($this->propagateContext()); - foreach ((array) $this->record->tags as $tag) { + // A resend of a resend already carries "resent"; one is enough, since + // resent_from_id records the depth. + foreach (array_unique([...(array) $this->record->tags, 'resent']) as $tag) { $this->tag($tag); } - return $this->tag('resent'); + return $this; } /** diff --git a/tests/ResendTest.php b/tests/ResendTest.php index ba345da..3ea306a 100644 --- a/tests/ResendTest.php +++ b/tests/ResendTest.php @@ -146,4 +146,18 @@ public function testTrackingResentFromIsRespected() $latest = EmailMessage::latest('id')->first(); $this->assertSame($original->id, $latest->resent_from_id); } + + public function testResendingAResendKeepsASingleResentTag() + { + Mail::send(new class extends \Illuminate\Mail\Mailable { + public function build(): static + { + return $this->to('r@example.com')->subject('Hi')->html('

Hi

')->tag('receipt')->tag('receipt'); + } + }); + Postmaster::resend(EmailMessage::first()); + Postmaster::resend(EmailMessage::latest('id')->first()); + + $this->assertSame(['receipt', 'resent'], EmailMessage::latest('id')->first()->tags); + } }