︙ | | | ︙ | |
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);
CREATE TABLE emails (
-- List of emails addresses
-- We are not storing actual email addresses here for privacy reasons
-- So that we can keep the record (for opt-out reasons) even when the
-- email address has been removed from the users table
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
verified INTEGER NOT NULL DEFAULT 0,
optout INTEGER NOT NULL DEFAULT 0,
invalid INTEGER NOT NULL DEFAULT 0,
fail_count INTEGER NOT NULL DEFAULT 0,
sent_count INTEGER NOT NULL DEFAULT 0,
fail_log TEXT NULL,
added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX emails_hash ON emails (hash);
CREATE TABLE emails_queue (
-- List of emails waiting to be sent
id INTEGER NOT NULL PRIMARY KEY,
sender TEXT NULL,
recipient TEXT NOT NULL,
recipient_hash TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL,
content_html TEXT NULL,
sending INTEGER NOT NULL DEFAULT 0, -- Will be changed to 1 when the queue run will start
sending_started TEXT NULL, -- Will be filled with the datetime when the email sending was started
context INTEGER NOT NULL
);
|
>
|
>
|
|
|
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS emails (
-- List of emails addresses
-- We are not storing actual email addresses here for privacy reasons
-- So that we can keep the record (for opt-out reasons) even when the
-- email address has been removed from the users table
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
verified INTEGER NOT NULL DEFAULT 0,
optout INTEGER NOT NULL DEFAULT 0,
invalid INTEGER NOT NULL DEFAULT 0,
fail_count INTEGER NOT NULL DEFAULT 0,
sent_count INTEGER NOT NULL DEFAULT 0,
fail_log TEXT NULL,
last_sent TEXT NULL,
added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS emails_hash ON emails (hash);
CREATE TABLE IF NOT EXISTS emails_queue (
-- List of emails waiting to be sent
id INTEGER NOT NULL PRIMARY KEY,
sender TEXT NULL,
recipient TEXT NOT NULL,
recipient_hash TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL,
content_html TEXT NULL,
sending INTEGER NOT NULL DEFAULT 0, -- Will be changed to 1 when the queue run will start
sending_started TEXT NULL, -- Will be filled with the datetime when the email sending was started
context INTEGER NOT NULL
);
|
︙ | | | ︙ | |
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);
CREATE TABLE emails (
-- List of emails addresses
-- We are not storing actual email addresses here for privacy reasons
-- So that we can keep the record (for opt-out reasons) even when the
-- email address has been removed from the users table
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
verified INTEGER NOT NULL DEFAULT 0,
optout INTEGER NOT NULL DEFAULT 0,
invalid INTEGER NOT NULL DEFAULT 0,
fail_count INTEGER NOT NULL DEFAULT 0,
sent_count INTEGER NOT NULL DEFAULT 0,
fail_log TEXT NULL,
added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX emails_hash ON emails (hash);
CREATE TABLE emails_queue (
-- List of emails waiting to be sent
id INTEGER NOT NULL PRIMARY KEY,
sender TEXT NULL,
recipient TEXT NOT NULL,
recipient_hash TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL,
content_html TEXT NULL,
sending INTEGER NOT NULL DEFAULT 0, -- Will be changed to 1 when the queue run will start
sending_started TEXT NULL, -- Will be filled with the datetime when the email sending was started
context INTEGER NOT NULL
);
|
>
|
>
|
|
|
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
CREATE TABLE IF NOT EXISTS compromised_passwords_cache_ranges
-- Cache des préfixes de mots de passe compromis
(
prefix TEXT NOT NULL PRIMARY KEY,
date INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS emails (
-- List of emails addresses
-- We are not storing actual email addresses here for privacy reasons
-- So that we can keep the record (for opt-out reasons) even when the
-- email address has been removed from the users table
id INTEGER NOT NULL PRIMARY KEY,
hash TEXT NOT NULL,
verified INTEGER NOT NULL DEFAULT 0,
optout INTEGER NOT NULL DEFAULT 0,
invalid INTEGER NOT NULL DEFAULT 0,
fail_count INTEGER NOT NULL DEFAULT 0,
sent_count INTEGER NOT NULL DEFAULT 0,
fail_log TEXT NULL,
last_sent TEXT NULL,
added TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS emails_hash ON emails (hash);
CREATE TABLE IF NOT EXISTS emails_queue (
-- List of emails waiting to be sent
id INTEGER NOT NULL PRIMARY KEY,
sender TEXT NULL,
recipient TEXT NOT NULL,
recipient_hash TEXT NOT NULL,
subject TEXT NOT NULL,
content TEXT NOT NULL,
content_html TEXT NULL,
sending INTEGER NOT NULL DEFAULT 0, -- Will be changed to 1 when the queue run will start
sending_started TEXT NULL, -- Will be filled with the datetime when the email sending was started
context INTEGER NOT NULL
);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<?php
declare(strict_types=1);
namespace Garradin\Entities\Users;
use Garradin\Entity;
use Garradin\UserException;
use Garradin\Users\Emails;
use const Garradin\{WWW_URL, SECRET_KEY};
class Email extends Entity
{
const TABLE = 'emails';
/**
* Antispam services that require to do a manual action to accept emails
*/
const BLACKLIST_MANUAL_VALIDATION_MX = '/mailinblack\.com|spamenmoins\.com/';
const COMMON_DOMAINS = ['laposte.net', 'gmail.com', 'hotmail.fr', 'hotmail.com', 'wanadoo.fr', 'free.fr', 'sfr.fr', 'yahoo.fr', 'orange.fr', 'live.fr', 'outlook.fr', 'yahoo.com', 'neuf.fr', 'outlook.com', 'icloud.com', 'riseup.net', 'vivaldi.net', 'aol.com', 'gmx.de', 'lilo.org', 'mailo.com', 'protonmail.com'];
protected int $id;
protected string $hash;
protected bool $verified;
protected bool $optout;
protected bool $invalid;
protected int $sent_count;
protected int $fail_count;
protected ?string $fail_log;
protected \DateTime $added;
/**
* Normalize email address and create a hash from this
*/
static public function getHash(string $email): string
{
$email = strtolower(trim($email));
|
>
>
|
|
|
|
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php
declare(strict_types=1);
namespace Garradin\Entities\Users;
use Garradin\Entity;
use Garradin\UserException;
use Garradin\Users\Emails;
use KD2\SMTP;
use const Garradin\{WWW_URL, SECRET_KEY};
class Email extends Entity
{
const TABLE = 'emails';
/**
* Antispam services that require to do a manual action to accept emails
*/
const BLACKLIST_MANUAL_VALIDATION_MX = '/mailinblack\.com|spamenmoins\.com/';
const COMMON_DOMAINS = ['laposte.net', 'gmail.com', 'hotmail.fr', 'hotmail.com', 'wanadoo.fr', 'free.fr', 'sfr.fr', 'yahoo.fr', 'orange.fr', 'live.fr', 'outlook.fr', 'yahoo.com', 'neuf.fr', 'outlook.com', 'icloud.com', 'riseup.net', 'vivaldi.net', 'aol.com', 'gmx.de', 'lilo.org', 'mailo.com', 'protonmail.com'];
protected int $id;
protected string $hash;
protected bool $verified = false;
protected bool $optout = false;
protected bool $invalid = false;
protected int $sent_count = 0;
protected int $fail_count = 0;
protected ?string $fail_log;
protected \DateTime $added;
protected ?\DateTime $last_sent;
/**
* Normalize email address and create a hash from this
*/
static public function getHash(string $email): string
{
$email = strtolower(trim($email));
|
︙ | | | ︙ | |
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
$this->set('verified', true);
$this->set('optout', false);
$this->set('invalid', false);
$this->set('fail_count', 0);
return true;
}
static public function validate(string $email): void
{
$user = strtok($email, '@');
$host = strtok('');
// Ce domaine n'existe pas (MX inexistant), erreur de saisie courante
if ($host == 'gmail.fr') {
throw new UserException('L\'adresse e-mail est invalide : est-ce que vous avez voulu écrire "gmail.com" ?');
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
$this->set('verified', true);
$this->set('optout', false);
$this->set('invalid', false);
$this->set('fail_count', 0);
return true;
}
public function validate(string $email): bool
{
if (!$this->canSend()) {
return false;
}
try {
self::validateAddress($email);
}
catch (UserException $e) {
$this->hasFailed(['type' => 'permanent', 'message' => $e->getMessage()]);
return false;
}
return true;
}
static public function validateAddress(string $email): void
{
$user = strtok($email, '@');
$host = strtok('');
// Ce domaine n'existe pas (MX inexistant), erreur de saisie courante
if ($host == 'gmail.fr') {
throw new UserException('L\'adresse e-mail est invalide : est-ce que vous avez voulu écrire "gmail.com" ?');
|
︙ | | | ︙ | |
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
throw new UserException('Adresse e-mail invalide : vérifiez que vous n\'avez pas fait une faute de frappe.');
}
getmxrr($host, $mx_list);
if (!count($mx_list)) {
throw new UserException('Adresse e-mail invalide : vérifiez que vous n\'avez pas fait une faute de frappe.');
}
$mx_list = array_filter($mx_list,
fn ($mx) => !preg_match(self::BLACKLIST_MANUAL_VALIDATION_MX, $mx)
);
if (!count($mx_list)) {
throw new UserException('Adresse e-mail invalide : impossible d\'envoyer des mails à un service (de type mailinblack ou spamenmoins) qui demande une validation manuelle de l\'expéditeur. Merci de choisir une autre adresse e-mail.');
}
}
public function canSend(): bool
{
if (!$this->verified) {
return false;
}
if ($this->optout) {
return false;
}
if ($this->invalid) {
return false;
}
if ($this->hasReachedFailLimit()) {
return false;
}
return true;
}
public function hasReachedFailLimit(): bool
{
return ($this->fail_count >= Emails::FAIL_LIMIT);
}
public function incrementSentCount(): void
{
$this->set('sent_count', $this->sent_count+1);
}
|
|
|
<
<
<
<
|
|
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
throw new UserException('Adresse e-mail invalide : vérifiez que vous n\'avez pas fait une faute de frappe.');
}
getmxrr($host, $mx_list);
if (!count($mx_list)) {
throw new UserException('Adresse e-mail invalide (le domaine indiqué n\'a pas de service e-mail) : vérifiez que vous n\'avez pas fait une faute de frappe.');
}
$mx_list = array_filter($mx_list,
fn ($mx) => !preg_match(self::BLACKLIST_MANUAL_VALIDATION_MX, $mx)
);
if (!count($mx_list)) {
throw new UserException('Adresse e-mail invalide : impossible d\'envoyer des mails à un service (de type mailinblack ou spamenmoins) qui demande une validation manuelle de l\'expéditeur. Merci de choisir une autre adresse e-mail.');
}
}
public function canSend(): bool
{
if (!empty($this->optout)) {
return false;
}
if (!empty($this->invalid)) {
return false;
}
if ($this->hasReachedFailLimit()) {
return false;
}
return true;
}
public function hasReachedFailLimit(): bool
{
return !empty($this->fail_count) && ($this->fail_count >= Emails::FAIL_LIMIT);
}
public function incrementSentCount(): void
{
$this->set('sent_count', $this->sent_count+1);
}
|
︙ | | | ︙ | |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?php
namespace Garradin\Users;
use Garradin\Config;
use Garradin\DB;
use Garradin\Plugin;
use Garradin\Entities\Users\Email;
use const Garradin\{USE_CRON};
use const Garradin\{SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_SECURITY};
use KD2\SMTP;
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?php
namespace Garradin\Users;
use Garradin\Config;
use Garradin\DB;
use Garradin\DynamicList;
use Garradin\Plugin;
use Garradin\Entities\Users\Email;
use const Garradin\{USE_CRON};
use const Garradin\{SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_SECURITY};
use KD2\SMTP;
|
︙ | | | ︙ | |
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
VALUES (:sender, :subject, :recipient, :content, :content_html, :context);');
$st->bindValue(':sender', $sender);
$st->bindValue(':subject', $subject);
$st->bindValue(':context', $context);
foreach ($recipients as $to => $variables) {
// Ignore obviously invalid emails here
if (self::checkAddress($to)) {
self::markAddressAsInvalid($to);
continue;
}
// We won't try to reject invalid/optout recipients here,
// it's done in the queue clearing (more efficient)
$hash = Email::getHash($to);
$content = $template->fetch($variables);
$content_html = $template_html ? $template_html->fetch($variables) : null;
|
<
<
<
<
<
<
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
VALUES (:sender, :subject, :recipient, :content, :content_html, :context);');
$st->bindValue(':sender', $sender);
$st->bindValue(':subject', $subject);
$st->bindValue(':context', $context);
foreach ($recipients as $to => $variables) {
// We won't try to reject invalid/optout recipients here,
// it's done in the queue clearing (more efficient)
$hash = Email::getHash($to);
$content = $template->fetch($variables);
$content_html = $template_html ? $template_html->fetch($variables) : null;
|
︙ | | | ︙ | |
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
$recipients = array_unique($recipients);
$db = DB::getInstance();
$st = $db->prepare('INSERT INTO emails_queue (sender, subject, recipient, recipient_hash, content, context)
VALUES (:sender, :subject, :recipient, :recipient_hash, :content, :context);');
foreach ($recipients as $to) {
// Ignore obviously invalid emails here
if (!self::checkAddress($to)) {
self::markAddressAsInvalid($to);
continue;
}
// We won't try to reject invalid/optout recipients here,
// it's done in the queue clearing (more efficient)
$hash = Email::getHash($to);
$st->bindValue(':sender', $sender);
$st->bindValue(':subject', $subject);
$st->bindValue(':context', $context);
|
<
<
<
<
<
<
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
$recipients = array_unique($recipients);
$db = DB::getInstance();
$st = $db->prepare('INSERT INTO emails_queue (sender, subject, recipient, recipient_hash, content, context)
VALUES (:sender, :subject, :recipient, :recipient_hash, :content, :context);');
foreach ($recipients as $to) {
// We won't try to reject invalid/optout recipients here,
// it's done in the queue clearing (more efficient)
$hash = Email::getHash($to);
$st->bindValue(':sender', $sender);
$st->bindValue(':subject', $subject);
$st->bindValue(':context', $context);
|
︙ | | | ︙ | |
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
}
static public function getEmail(string $address): ?Email
{
return EM::findOne(Email::class, 'SELECT * FROM @TABLE WHERE hash = ?;', Email::getHash($address));
}
/**
* Vérifie qu'une adresse est valide
* @param string $address
* @return boolean FALSE si l'adresse est invalide (syntaxe)
*/
static public function checkAddress(string $address): bool
{
$address = strtolower(trim($address));
// Ce domaine n'existe pas (MX inexistant), erreur de saisie courante
if (false !== stristr($address, '@gmail.fr'))
{
return false;
}
if (!SMTP::checkEmailIsValid($address, true))
{
return false;
}
return true;
}
static public function runQueue()
{
$db = DB::getInstance();
$queue = self::listQueueAndMarkAsSending();
$ids = [];
// listQueue nettoie déjà la queue
foreach ($queue as $row) {
// Don't send emails to opt-out address, unless it's a password reminder
if ($row->context != self::CONTEXT_SYSTEM && $row->optout) {
self::deleteFromQueue($row->id);
continue;
}
$headers = [
'From' => $row->sender,
'To' => $row->recipient,
'Subject' => $row->subject,
];
self::send($row->context, $row->recipient_hash, $headers, $row->content, $row->content_html);
$ids[] = $row->id;
}
// Update emails list and send count
// then delete messages from queue
$db->exec(sprintf('
BEGIN;
UPDATE emails_queue SET sending = 2 WHERE %s;
INSERT OR IGNORE INTO %s (hash) SELECT recipient_hash FROM emails_queue WHERE sending = 2;
UPDATE %2$s SET sent_count = sent_count + 1 WHERE hash IN (SELECT recipient_hash FROM emails_queue WHERE sending = 2);
DELETE FROM emails_queue WHERE sending = 2;
END;', $db->where('id', $ids), Email::TABLE));
}
/**
* Liste la file d'attente et marque les éléments listés comme "en cours de traitement"
* @return array
|
<
<
<
<
<
|
|
<
|
<
<
<
|
>
|
<
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
}
static public function getEmail(string $address): ?Email
{
return EM::findOne(Email::class, 'SELECT * FROM @TABLE WHERE hash = ?;', Email::getHash($address));
}
static public function getOrCreateEmail(string $address): Email
{
$e = self::getEmail($address);
if (!$e) {
$e = new Email;
$e->added = new \DateTime;
$e->hash = $e::getHash($address);
$e->validate($address);
$e->save();
}
return $e;
}
static public function runQueue()
{
$db = DB::getInstance();
$queue = self::listQueueAndMarkAsSending();
$ids = [];
// listQueue nettoie déjà la queue
foreach ($queue as $row) {
// Don't send emails to opt-out address, unless it's a password reminder
if ($row->context != self::CONTEXT_SYSTEM && $row->optout) {
self::deleteFromQueue($row->id);
continue;
}
// Create email address in database
if (!$row->email_hash) {
$email = self::getOrCreateEmail($row->recipient);
if (!$email->canSend()) {
// Email address is invalid, skip
self::deleteFromQueue($row->id);
continue;
}
}
$headers = [
'From' => $row->sender,
'To' => $row->recipient,
'Subject' => $row->subject,
];
self::send($row->context, $row->recipient_hash, $headers, $row->content, $row->content_html);
$ids[] = $row->id;
}
// Update emails list and send count
// then delete messages from queue
$db->exec(sprintf('
BEGIN;
UPDATE emails_queue SET sending = 2 WHERE %s;
INSERT OR IGNORE INTO %s (hash) SELECT recipient_hash FROM emails_queue WHERE sending = 2;
UPDATE %2$s SET sent_count = sent_count + 1, last_sent = datetime()
WHERE hash IN (SELECT recipient_hash FROM emails_queue WHERE sending = 2);
DELETE FROM emails_queue WHERE sending = 2;
END;', $db->where('id', $ids), Email::TABLE));
}
/**
* Liste la file d'attente et marque les éléments listés comme "en cours de traitement"
* @return array
|
︙ | | | ︙ | |
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
* @return array
*/
static protected function listQueue(): array
{
// Nettoyage de la queue déjà
self::purgeQueueFromRejected();
self::resetFailed();
return DB::getInstance()->get('SELECT q.*, e.optout, e.verified
FROM emails_queue q
LEFT JOIN emails e ON e.hash = q.recipient_hash
WHERE q.sending = 0;');
}
static public function listRejectedUsers(): array
{
$sql = sprintf('SELECT e.*, u.email, u.id, u.%s AS identity
FROMS emails e
LEFT JOIN membres u ON u.email IS NOT NULL AND u.email != \'\' AND e.hash = email_hash(u.email)
WHERE e.optout = 1 OR e.invalid = 1 OR e.fail_count >= %d;',
$id_field,
self::FAIL_LIMIT
);
return DB::getInstance()->get($sql);
}
/**
* Supprime de la queue les messages liés à des adresses invalides
* ou qui ne souhaitent plus recevoir de message
* @return boolean
*/
|
|
>
>
>
>
>
|
>
|
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
* @return array
*/
static protected function listQueue(): array
{
// Nettoyage de la queue déjà
self::purgeQueueFromRejected();
self::resetFailed();
return DB::getInstance()->get('SELECT q.*, e.optout, e.verified, e.hash AS email_hash
FROM emails_queue q
LEFT JOIN emails e ON e.hash = q.recipient_hash
WHERE q.sending = 0;');
}
static public function countQueue(): int
{
return DB::getInstance()->count('emails_queue');
}
static public function listRejectedUsers(): DynamicList
{
$db = DB::getInstance();
$columns = [
'identity' => [
'label' => 'Membre',
'select' => 'u.' . $db->quoteIdentifier(Config::getInstance()->champ_identite),
],
'email' => [
'label' => 'Adresse',
'select' => 'u.email',
],
'user_id' => [
'select' => 'u.id',
],
'hash' => [
],
'status' => [
'label' => 'Statut',
'select' => sprintf('CASE
WHEN e.optout = 1 THEN \'Désinscription\'
WHEN e.invalid = 1 THEN \'Invalide\'
WHEN e.fail_count >= %d THEN \'Trop de tentatives\'
WHEN e.verified = 1 THEN \'Vérifiée\'
ELSE \'\'
END', self::FAIL_LIMIT),
],
'sent_count' => [
'label' => 'Messages envoyés',
],
'fail_log' => [
'label' => 'Journal d\'erreurs',
],
'last_sent' => [
'label' => 'Dernière tentative d\'envoi',
],
'optout' => [],
'fail_count' => [],
];
$tables = 'emails e
INNER JOIN membres u ON u.email IS NOT NULL AND u.email != \'\' AND e.hash = email_hash(u.email)';
$conditions = sprintf('e.optout = 1 OR e.invalid = 1 OR e.fail_count >= %d', self::FAIL_LIMIT);
$list = new DynamicList($columns, $tables, $conditions);
$list->orderBy('last_sent', true);
return $list;
}
/**
* Supprime de la queue les messages liés à des adresses invalides
* ou qui ne souhaitent plus recevoir de message
* @return boolean
*/
|
︙ | | | ︙ | |