Skip to content

Commit

Permalink
Handle MixedPart messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonb-sf committed Apr 11, 2022
1 parent 2bf0efe commit 7e323de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MailTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use jdavidbakr\MailTracker\Model\SentEmailUrlClicked;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
use Symfony\Component\Mime\Part\Multipart\MixedPart;
use Symfony\Component\Mime\Part\TextPart;

class MailTracker
Expand Down Expand Up @@ -187,7 +188,10 @@ protected function createTrackers($message)

$original_content = $message->getBody();
$original_html = '';
if(get_class($original_content) == AlternativePart::class) {
if(
($original_content instanceof(AlternativePart::class)) ||
($original_content instanceof(MixedPart::class))
) {
$messageBody = $message->getBody() ?: [];
$newParts = [];
foreach($messageBody->getParts() as $part) {
Expand Down
27 changes: 27 additions & 0 deletions tests/MailTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,33 @@ public function testSendMessageWithMultiPart()
]);
}

public function testSendMessageWithMixedPart()
{
$faker = Factory::create();
$email = $faker->email;
$name = $faker->firstName . ' ' .$faker->lastName;
View::addLocation(__DIR__);
$str = Mockery::mock(Str::class);
app()->instance(Str::class, $str);
$str->shouldReceive('random')
->once()
->andReturn('random-hash');
$mailable = new TestMailable();
$mailable->subject('this is the message subject.');
$mailable->attach(__DIR__.'/email/test.blade.php');

try {
Mail::to($email)->send($mailable);
} catch (Exception $e) {
// dd($e);
}

$this->assertDatabaseHas('sent_emails', [
'hash' => 'random-hash',
'recipient_email' => $email,
]);
}

/**
* @test
*/
Expand Down

0 comments on commit 7e323de

Please sign in to comment.