. */ namespace Liuch\DmarcSrg\Mail; use Liuch\DmarcSrg\Exception\SoftException; abstract class MailMessage { protected $attachment = null; abstract public function __construct($data); abstract public function overview(): array; abstract public function markSeen(): void; public function validate() { $acnt = $this->attachmentCount(); if ($acnt !== 1) { throw new SoftException("Attachment count is not valid ({$acnt})"); } $this->ensureAttachment(); $bytes = $this->attachment->size(); if ($bytes === -1) { throw new SoftException("Failed to get attached file size. Wrong message format?"); } if ($bytes < 50 || $bytes > 1 * 1024 * 1024) { throw new SoftException("Attachment file size is not valid ({$bytes} bytes)"); } $mime_type = $this->attachment->mimeType(); if (!in_array($mime_type, [ 'application/zip', 'application/gzip', 'application/x-gzip', 'text/xml' ])) { throw new SoftException("Attachment file type is not valid ({$mime_type})"); } } abstract public function attachment(); abstract public function move(string $folder): void; abstract public function delete(): void; abstract protected function attachmentCount(): int; abstract protected function ensureAttachment(): void; }