Skip to content

Commit

Permalink
test double text mime
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Jul 24, 2023
1 parent d5edf5c commit 5c6ee27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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 || $this->text->isEmpty()) && $contentType === 'text/plain' && $disposition === 'inline') {

Check failure on line 407 in src/MessageBodyCollection.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 tests

Negated boolean expression is always false.

Check failure on line 407 in src/MessageBodyCollection.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 tests

Negated boolean expression is always false.

Check failure on line 407 in src/MessageBodyCollection.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 tests

Negated boolean expression is always false.
$this->text = AlternativeText::fromEncodedText((string)new MimeBodyDecodedStream($part), $charset);
continue;
}
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 <me@example.com>
Cc: other <other@example.com>
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 5c6ee27

Please sign in to comment.