Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/MessagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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], '"');
}

Expand Down