| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace Liuch\DmarcSrg\Mail; |
| 24 |
|
| 25 |
use Liuch\DmarcSrg\Exception\SoftException; |
| 26 |
|
| 27 |
abstract class MailMessage |
| 28 |
{ |
| 29 |
protected $attachment = null; |
| 30 |
|
| 31 |
abstract public function __construct($data); |
| 32 |
|
| 33 |
abstract public function overview(): array; |
| 34 |
|
| 35 |
abstract public function markSeen(): void; |
| 36 |
|
| 37 |
public function validate() |
| 38 |
{ |
| 39 |
$acnt = $this->attachmentCount(); |
| 40 |
if ($acnt !== 1) { |
| 41 |
throw new SoftException("Attachment count is not valid ({$acnt})"); |
| 42 |
} |
| 43 |
|
| 44 |
$this->ensureAttachment(); |
| 45 |
|
| 46 |
$bytes = $this->attachment->size(); |
| 47 |
if ($bytes === -1) { |
| 48 |
throw new SoftException("Failed to get attached file size. Wrong message format?"); |
| 49 |
} |
| 50 |
if ($bytes < 50 || $bytes > 1 * 1024 * 1024) { |
| 51 |
throw new SoftException("Attachment file size is not valid ({$bytes} bytes)"); |
| 52 |
} |
| 53 |
|
| 54 |
$mime_type = $this->attachment->mimeType(); |
| 55 |
if (!in_array($mime_type, [ 'application/zip', 'application/gzip', 'application/x-gzip', 'text/xml' ])) { |
| 56 |
throw new SoftException("Attachment file type is not valid ({$mime_type})"); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
abstract public function attachment(); |
| 61 |
|
| 62 |
abstract public function move(string $folder): void; |
| 63 |
|
| 64 |
abstract public function delete(): void; |
| 65 |
|
| 66 |
abstract protected function attachmentCount(): int; |
| 67 |
|
| 68 |
abstract protected function ensureAttachment(): void; |
| 69 |
} |