Skip to content

Commit

Permalink
test double text mime (#107)
Browse files Browse the repository at this point in the history
* test double text mime
  • Loading branch information
frederikbosch authored Jul 24, 2023
1 parent d5edf5c commit d3fe29f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MessageBodyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private function extractFromMimePart(MultiPartInterface $parts): void
continue;
}

if ($contentType === 'text/plain' && $disposition === 'inline') {
if ($this->text->isEmpty() && $contentType === 'text/plain' && $disposition === 'inline') {
$this->text = AlternativeText::fromEncodedText((string)new MimeBodyDecodedStream($part), $charset);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/PhpMailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function send(MessageInterface $message): void
$headers,
$parameters
);
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd
} else {
$callback = $this->replacedMailMethod;
$callback(
Expand Down
23 changes: 23 additions & 0 deletions test/Stub/MessageBodyCollection/double-text.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Subject: Hello World
To: me <[email protected]>
Cc: other <[email protected]>
MIME-Version: 1.0
Content-Type:
multipart/mixed; boundary=Apple-Mail-E26EA4FA-4B4F-4801-BEB2-43B254B76FDF
Content-Transfer-Encoding: 7bit

--Apple-Mail-E26EA4FA-4B4F-4801-BEB2-43B254B76FDF
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Hello World
--Apple-Mail-E26EA4FA-4B4F-4801-BEB2-43B254B76FDF
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
Another Text
--Apple-Mail-E26EA4FA-4B4F-4801-BEB2-43B254B76FDF--
22 changes: 22 additions & 0 deletions test/Unit/MessageBodyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,26 @@ public function it_should_extract_the_first_html_part(): void
$messageBodyCollection->getHtml()
);
}

/**
* @test
*/
public function it_should_extract_the_first_text_part(): void
{
$messageBodyCollection = MessageBodyCollection::extract(
GenericMessage::fromString(
\file_get_contents(__DIR__ . '/../Stub/MessageBodyCollection/double-text.eml')
)
);

$this->assertStringNotContainsString(
'Another Text',
$messageBodyCollection->getText()->getRaw()
);

$this->assertStringContainsString(
'Hello World',
$messageBodyCollection->getText()->getRaw()
);
}
}

0 comments on commit d3fe29f

Please sign in to comment.