PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Imap2 / Functions.php

Functions.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Libraries/Imap2/Functions.php

200 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the PHP IMAP2 package.
5 *
6 * (c) Francesco Bianco <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace AcyMailing\Libraries\Imap2;
13
14 class Functions
15 {
16 public static function parseMailboxString($mailbox)
17 {
18 $mailboxParts = explode('}', $mailbox);
19 $mailboxParts[0] = substr($mailboxParts[0], 1);
20
21 $values = parse_url($mailboxParts[0]);
22
23 $values['mailbox'] = $mailboxParts[1] ?? '';
24 $values['path'] = explode('/', $values['path']);
25
26 return $values;
27 }
28
29 public static function getHostFromMailbox($mailbox)
30 {
31 $mailboxParts = is_array($mailbox) ? $mailbox : self::parseMailboxString($mailbox);
32
33 return @$mailboxParts['host'];
34 }
35
36 public static function getSslModeFromMailbox($mailbox)
37 {
38 $mailboxParts = is_array($mailbox) ? $mailbox : self::parseMailboxString($mailbox);
39
40 if (in_array('ssl', $mailboxParts['path'])) {
41 return 'ssl';
42 }
43
44 return false;
45 }
46
47 public static function expectedNumberOfMessages($sequence)
48 {
49 if (strpos($sequence, ',') > 0) {
50 return count(explode(',', $sequence));
51 } elseif (strpos($sequence, ':') > 0) {
52 $range = explode(':', $sequence);
53
54 return $range[1] - $range[0];
55 } else {
56 return 1;
57 }
58 }
59
60 public static function unique()
61 {
62 return md5(microtime().time().rand(1000, 9999));
63 }
64
65 /**
66 * Get name from full mailbox string.
67 *
68 * @param $mailbox
69 *
70 * @return mixed|string
71 */
72 public static function getMailboxName($mailbox)
73 {
74 $mailboxParts = explode('}', $mailbox, 2);
75
76 return empty($mailboxParts[1]) ? 'INBOX' : $mailboxParts[1];
77 }
78
79 /**
80 *
81 * @param $address
82 * @param $defaultHost
83 *
84 * @return string
85 */
86 public static function sanitizeAddress($address, $defaultHost = 'UNKNOWN')
87 {
88 $addressList = imap_rfc822_parse_adrlist($address, $defaultHost);
89
90 $sanitizedAddress = [];
91 foreach ($addressList as $addressEntry) {
92 $sanitizedAddress[] = imap_rfc822_write_address($addressEntry->mailbox, $addressEntry->host, $addressEntry->personal);
93 }
94
95 return implode(', ', $sanitizedAddress);
96 }
97
98 /**
99 *
100 */
101 public static function writeAddressFromEnvelope($addressList)
102 {
103 if (empty($addressList)) {
104 return null;
105 }
106
107 $sanitizedAddress = [];
108 foreach ($addressList as $addressEntry) {
109 $parsedAddressEntry = imap_rfc822_write_address($addressEntry[2], $addressEntry[3], $addressEntry[0]);
110 if (substr($parsedAddressEntry, -3) == '@""') {
111 $parsedAddressEntry = substr($parsedAddressEntry, 0, strlen($parsedAddressEntry) - 3).': ';
112 }
113 $sanitizedAddress[] = $parsedAddressEntry;
114 }
115
116 return implode(', ', $sanitizedAddress);
117 }
118
119 /**
120 *
121 */
122 public static function getListAttributesValue($attributes)
123 {
124 $attributesValue = 0;
125
126 foreach ($attributes as $attribute) {
127 switch ($attribute) {
128 case '\\NoInferiors':
129 $attributesValue |= LATT_NOINFERIORS;
130 break;
131 case '\\NoSelect':
132 $attributesValue |= LATT_NOSELECT;
133 break;
134 case '\\Marked':
135 $attributesValue |= LATT_MARKED;
136 break;
137 case '\\UnMarked':
138 $attributesValue |= LATT_UNMARKED;
139 break;
140 case '\\Referral':
141 $attributesValue |= LATT_REFERRAL;
142 break;
143 case '\\HasChildren':
144 $attributesValue |= LATT_HASCHILDREN;
145 break;
146 case '\\HasNoChildren':
147 $attributesValue |= LATT_HASNOCHILDREN;
148 break;
149 }
150 }
151
152 return $attributesValue;
153 }
154
155 public static function isValidImap1Connection($imap)
156 {
157 return is_resource($imap) && get_resource_type($imap) == 'imap';
158 }
159
160 public static function isValidImap2Connection($imap)
161 {
162 return Connection::isValid($imap);
163 }
164
165 public static function getAddressObjectList($addressList, $defaultHost = 'UNKNOWN')
166 {
167 $addressObjectList = [];
168 foreach ($addressList as $toAddress) {
169 $email = explode('@', $toAddress->getEmail());
170
171 $addressObject = (object)[
172 'mailbox' => $email[0],
173 'host' => $email[1] ?? $defaultHost,
174 ];
175
176 $personal = $toAddress->getName();
177 if ($personal) {
178 $addressObject->personal = $personal;
179 }
180
181 $addressObjectList[] = $addressObject;
182 }
183
184 return $addressObjectList;
185 }
186
187 public static function isBackportCall($backtrace, $depth)
188 {
189 return isset($backtrace[$depth + 1]['function'])
190 && preg_match('/^imap_/', $backtrace[$depth + 1]['function'])
191 && preg_match('/^imap2_/', $backtrace[$depth]['function'])
192 && substr($backtrace[$depth + 1]['function'], 4) == substr($backtrace[$depth]['function'], 5);
193 }
194
195 public static function isRetrofitResource($imap)
196 {
197 return is_resource($imap) && get_resource_type($imap) == 'imap';
198 }
199 }
200