Debian Codegraph @

classes/Mail/MailMessage.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2020-2024 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
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 }