generated from Nodarx/template
129 lines
3.7 KiB
PHP
129 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXM\ProviderImap\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(); }
|
|
}
|