Debian Codegraph @

classes/Mail/MailBox.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) 2025 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 abstract class MailBox
26 {
27 public const SEARCH_ALL = 1;
28 public const SEARCH_SEEN = 2;
29 public const SEARCH_UNSEEN = 3;
30 public const ORDER_ASCENT = 1;
31 public const ORDER_DESCENT = 2;
32
33 protected $host;
34 protected $mbox;
35 protected $name;
36 protected $uname;
37 protected $passw;
38 protected $authm;
39 protected $encrypt;
40 protected $nocert;
41 protected $a_excl;
42
43 private $expunge_f = false;
44
45 public function __construct(array $params)
46 {
47 $this->uname = $params['username'];
48 $this->passw = $params['password'];
49 $this->authm = $params['authentication'] ?? 'plain';
50 $this->name = $params['name'] ?? '';
51 if (strlen($this->name) === 0) {
52 $name = $this->uname;
53 $pos = strpos($name, '@');
54 if ($pos !== false && $pos !== 0) {
55 $name = substr($name, 0, $pos);
56 }
57 $this->name = $name;
58 }
59 $this->mbox = $params['mailbox'];
60 $this->host = $params['host'];
61 $this->encrypt = $params['encryption'] ?? '';
62 $this->nocert = $params['novalidate-cert'] ?? false;
63
64 $aexcl = $params['auth_exclude'] ?? null;
65 switch (gettype($aexcl)) {
66 case 'string':
67 $this->a_excl = [ $aexcl ];
68 break;
69 case 'array':
70 $this->a_excl = [];
71 for ($i = 0; $i < count($aexcl); ++$i) {
72 if (gettype($aexcl[$i]) == 'string') {
73 $this->a_excl[] = $aexcl[$i];
74 }
75 }
76 break;
77 default:
78 $this->a_excl = [];
79 break;
80 }
81 }
82
83 public function __destruct()
84 {
85 if ($this->expunge_f) {
86 $this->expunge();
87 }
88 $this->cleanup();
89 }
90
91 public function __clone(): void
92 {
93 $this->expunge_f = false;
94 }
95
96 public function setExpunge(): void
97 {
98 $this->expunge_f = true;
99 }
100
101 abstract public function expunge(): void;
102
103 abstract public function cleanup(): void;
104
105 public function name(): string
106 {
107 return $this->name;
108 }
109
110 public function authMethod(): string
111 {
112 return $this->authm;
113 }
114
115 public function host(): string
116 {
117 return $this->host;
118 }
119
120 public function folder(): string
121 {
122 return $this->mbox;
123 }
124
125 abstract public function childMailbox(string $folder);
126
127 abstract public function check(): array;
128
129 abstract public function messages(int $search_criteria, int $sort_criteria): array;
130
131 /**
132 * Checks whether the folder exists and creates it if it is not
133 *
134 * @param string $folder
135 *
136 * @return void
137 */
138 abstract public function ensureMailbox($folder): void;
139 }