Skip to content

Commit

Permalink
Merge pull request #227 from ddeboer/null_charset
Browse files Browse the repository at this point in the history
If charset is not specified defaults to "us-ascii"
Close #226
  • Loading branch information
Slamdunk authored Oct 5, 2017
2 parents b8719d2 + bec2e56 commit 4aa0a1d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Message/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ final public function getParameters(): Parameters
*/
final public function getCharset(): string
{
return $this->parameters->get('charset');
return $this->parameters->get('charset') ?: 'us-ascii';
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,23 @@ public function testSignedMessage()
$this->assertContains($expectedContains, \rtrim($attachment->getContent()), $attachment->getFilename());
}
}

public function testSimpleMessageWithoutCharset()
{
$this->mailbox->addMessage($this->getFixture('without_charset_plain_only'));

$message = $this->mailbox->getMessage(1);

$this->assertSame('Hi', \rtrim($message->getBodyText()));
}

public function testMultipartMessageWithoutCharset()
{
$this->mailbox->addMessage($this->getFixture('without_charset_simple_multipart'));

$message = $this->mailbox->getMessage(1);

$this->assertSame('MyPlain', \rtrim($message->getBodyText()));
$this->assertSame('MyHtml', \rtrim($message->getBodyHtml()));
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/without_charset_plain_only.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
From: [email protected]
To: [email protected]
Subject: Nuu
Date: Wed, 13 Sep 2017 13:05:45 +0200
Content-Type: text/plain; charset=
Content-Transfer-Encoding: quoted-printable

Hi
24 changes: 24 additions & 0 deletions tests/fixtures/without_charset_simple_multipart.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From: [email protected]
To: [email protected]
Date: Wed, 27 Sep 2017 12:48:51 +0200
Subject: test
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0081_01D32C91.033E7020"

This is a multipart message in MIME format.

------=_NextPart_000_0081_01D32C91.033E7020
Content-Type: text/plain;
charset=
Content-Transfer-Encoding: 7bit
MyPlain
------=_NextPart_000_0081_01D32C91.033E7020
Content-Type: text/html;
charset=""
Content-Transfer-Encoding: quoted-printable

MyHtml
------=_NextPart_000_0081_01D32C91.033E7020--

0 comments on commit 4aa0a1d

Please sign in to comment.