generated from Nodarx/template
feat: initial version
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
62
lib/Client/Mime/Part/SinglePart.php
Normal file
62
lib/Client/Mime/Part/SinglePart.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Gricob\IMAP\Mime\Part;
|
||||
|
||||
final readonly class SinglePart extends Part
|
||||
{
|
||||
private string $encoding;
|
||||
|
||||
public function __construct(
|
||||
string $type,
|
||||
string $subtype,
|
||||
array $attributes,
|
||||
private Body $body,
|
||||
private string $charset,
|
||||
string $encoding,
|
||||
private ?Disposition $disposition,
|
||||
) {
|
||||
|
||||
$this->encoding = strtolower($encoding);
|
||||
parent::__construct($type, $subtype, $attributes);
|
||||
}
|
||||
|
||||
public function body(): string
|
||||
{
|
||||
return (string) $this->body;
|
||||
}
|
||||
|
||||
public function decodedBody(): string
|
||||
{
|
||||
return match ($this->encoding) {
|
||||
'quoted-printable' => quoted_printable_decode($this->body()),
|
||||
'base64' => base64_decode($this->body()),
|
||||
default => $this->body(),
|
||||
};
|
||||
}
|
||||
|
||||
public function charset(): string
|
||||
{
|
||||
return $this->charset;
|
||||
}
|
||||
|
||||
public function encoding(): string
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
public function disposition(): ?Disposition
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
public function findPartByMimeType(string $mimeType): ?SinglePart
|
||||
{
|
||||
if ($this->mimeType() === strtolower($mimeType)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user