diff --git a/src/MessagePart.php b/src/MessagePart.php index ce7b7ce..49493d4 100644 --- a/src/MessagePart.php +++ b/src/MessagePart.php @@ -99,11 +99,17 @@ public function getContentType(): string public function getContent(): string { + $content = $this->content; + if (strtolower($this->getHeader('Content-Transfer-Encoding', '')) === 'base64') { - return Utils::normaliseLineEndings(base64_decode($this->content)); + $content = base64_decode($content); + } + + if ($this->isAttachment()) { + return $content; } - return Utils::normaliseLineEndings($this->content); + return Utils::normaliseLineEndings($content); } public function isHtml(): bool @@ -123,16 +129,16 @@ public function isImage(): bool public function isAttachment(): bool { - return str_starts_with($this->getHeader('Content-Disposition', ''), 'attachment'); + return str_starts_with(strtolower($this->getHeader('Content-Disposition', '')), 'attachment'); } public function getFilename(): string { - if (preg_match('/filename=([^;]+)/', $this->getHeader('Content-Disposition'), $matches)) { + if (preg_match('/filename=([^;]+)/i', $this->getHeader('Content-Disposition'), $matches)) { return trim($matches[1], '"'); } - if (preg_match('/name=([^;]+)/', $this->getContentType(), $matches)) { + if (preg_match('/name=([^;]+)/i', $this->getContentType(), $matches)) { return trim($matches[1], '"'); }