diff options
Diffstat (limited to 'lib/private/Mail/Attachment.php')
-rw-r--r-- | lib/private/Mail/Attachment.php | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/private/Mail/Attachment.php b/lib/private/Mail/Attachment.php index 12f71df86d9..5bfe0dd0522 100644 --- a/lib/private/Mail/Attachment.php +++ b/lib/private/Mail/Attachment.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OC\Mail; use OCP\Mail\IAttachment; +use Symfony\Component\Mime\Email; /** * Class Attachment @@ -35,11 +36,21 @@ use OCP\Mail\IAttachment; * @since 13.0.0 */ class Attachment implements IAttachment { - /** @var \Swift_Mime_Attachment */ - protected $swiftAttachment; + private ?string $body; + private ?string $name; + private ?string $contentType; + private ?string $path; - public function __construct(\Swift_Mime_Attachment $attachment) { - $this->swiftAttachment = $attachment; + public function __construct( + ?string $body, + ?string $name, + ?string $contentType, + ?string $path = null + ) { + $this->body = $body; + $this->name = $name; + $this->contentType = $contentType; + $this->path = $path; } /** @@ -48,7 +59,7 @@ class Attachment implements IAttachment { * @since 13.0.0 */ public function setFilename(string $filename): IAttachment { - $this->swiftAttachment->setFilename($filename); + $this->name = $filename; return $this; } @@ -58,7 +69,7 @@ class Attachment implements IAttachment { * @since 13.0.0 */ public function setContentType(string $contentType): IAttachment { - $this->swiftAttachment->setContentType($contentType); + $this->contentType = $contentType; return $this; } @@ -68,14 +79,15 @@ class Attachment implements IAttachment { * @since 13.0.0 */ public function setBody(string $body): IAttachment { - $this->swiftAttachment->setBody($body); + $this->body = $body; return $this; } - /** - * @return \Swift_Mime_Attachment - */ - public function getSwiftAttachment(): \Swift_Mime_Attachment { - return $this->swiftAttachment; + public function attach(Email $symfonyEmail): void { + if ($this->path !== null) { + $symfonyEmail->attachFromPath($this->path, $this->name, $this->contentType); + } else { + $symfonyEmail->attach($this->body, $this->name, $this->contentType); + } } } |