Skip to content

Commit

Permalink
make sure content transfer encoding is a lower cased string
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed May 31, 2024
1 parent b033af7 commit 79f43af
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/Stream/MimeBodyDecodedStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@ private function calculateOptimalStream(PartInterface $part): StreamInterface
return $part->getBody();
}

$encoding = $part->getHeader('Content-Transfer-Encoding')->getValue();
switch ($encoding) {
case 'quoted-printable':
return QuotedPrintableDecodedStream::fromString((string)$part->getBody());
case 'base64':
return Base64DecodedStream::fromString((string)$part->getBody());
case '7bit':
case '8bit':
return $part->getBody();
default:
throw new \UnexpectedValueException(
'Cannot decode body of mime part, unknown transfer encoding ' . $encoding
);
}
$encoding = \strtolower((string)$part->getHeader('Content-Transfer-Encoding')->getValue());
return match ($encoding) {
'quoted-printable' => QuotedPrintableDecodedStream::fromString((string)$part->getBody()),
'base64' => Base64DecodedStream::fromString((string)$part->getBody()),
'7bit', '8bit' => $part->getBody(),
default => throw new \UnexpectedValueException(
'Cannot decode body of mime part, unknown transfer encoding ' . $encoding
),
};
}

/**
Expand Down

0 comments on commit 79f43af

Please sign in to comment.