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:
128
lib/Providers/MessageAttachment.php
Normal file
128
lib/Providers/MessageAttachment.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderImapMail\Providers;
|
||||
|
||||
/**
|
||||
* Mail Attachment Object
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MessageAttachment implements \KTXF\Mail\Object\MessagePartInterface {
|
||||
|
||||
protected MessagePart $_meta;
|
||||
protected ?string $_contents = null;
|
||||
|
||||
public function __construct(?MessagePart $meta = null, ?string $contents = null) {
|
||||
if ($meta === null) {
|
||||
$meta = new MessagePart();
|
||||
$meta->setDisposition('attachment');
|
||||
$meta->setType('application/octet-stream');
|
||||
}
|
||||
$this->setParameters($meta);
|
||||
if ($contents !== null) {
|
||||
$this->setContents($contents);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attachment parameters
|
||||
*/
|
||||
public function setParameters(?MessagePart $meta): static {
|
||||
$this->_meta = $meta;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment parameters
|
||||
*/
|
||||
public function getParameters(): MessagePart {
|
||||
return $this->_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique identifier for this attachment (MIME part id)
|
||||
*/
|
||||
public function id(): string {
|
||||
return $this->_meta->getBlobId() ?? $this->_meta->getId() ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attachment file name
|
||||
*/
|
||||
public function setName(string $value): static {
|
||||
$this->_meta->setName($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment file name
|
||||
*/
|
||||
public function getName(): ?string {
|
||||
return $this->_meta->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attachment MIME type
|
||||
*/
|
||||
public function setType(string $value): static {
|
||||
$this->_meta->setType($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment MIME type
|
||||
*/
|
||||
public function getType(): ?string {
|
||||
return $this->_meta->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attachment contents (binary data)
|
||||
*/
|
||||
public function setContents(string $value): static {
|
||||
$this->_contents = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment contents
|
||||
*/
|
||||
public function getContents(): ?string {
|
||||
return $this->_contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the attachment is embedded (inline)
|
||||
*/
|
||||
public function setEmbedded(bool $value): static {
|
||||
$this->_meta->setDisposition($value ? 'inline' : 'attachment');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the attachment is embedded (inline)
|
||||
*/
|
||||
public function getEmbedded(): bool {
|
||||
return $this->_meta->getDisposition() === 'inline';
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
// MessagePartInterface pass-throughs
|
||||
// ──────────────────────────────────────────────────────────────
|
||||
|
||||
public function getBlobId(): ?string { return $this->_meta->getBlobId(); }
|
||||
public function getId(): ?string { return $this->_meta->getId(); }
|
||||
public function getDisposition(): ?string { return $this->_meta->getDisposition(); }
|
||||
public function getCharset(): ?string { return $this->_meta->getCharset(); }
|
||||
public function getLanguage(): ?string { return $this->_meta->getLanguage(); }
|
||||
public function getLocation(): ?string { return $this->_meta->getLocation(); }
|
||||
public function getParts(): array { return $this->_meta->getParts(); }
|
||||
public function jsonSerialize(): array { return $this->_meta->jsonSerialize(); }
|
||||
}
|
||||
Reference in New Issue
Block a user