2016-08-26 12:43:45 +00:00
|
|
|
<?php
|
|
|
|
|
2016-09-24 14:32:31 +00:00
|
|
|
require_once __DIR__.'/lib/method.php';
|
2016-08-26 12:43:45 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
class Clean extends Edi\Method {
|
|
|
|
function ediRun($db) {
|
2016-08-26 12:43:45 +00:00
|
|
|
$imap = $this->imap;
|
|
|
|
|
2022-07-07 12:55:34 +00:00
|
|
|
$cleanPeriod = $db->getValue(
|
|
|
|
"SELECT ic.cleanPeriod
|
2024-07-19 05:50:02 +00:00
|
|
|
FROM imapMultiConfig ic
|
2022-07-07 12:55:34 +00:00
|
|
|
JOIN util.config c ON c.environment = ic.environment");
|
2016-08-26 12:43:45 +00:00
|
|
|
|
|
|
|
$deleted = 0;
|
2018-05-23 10:14:20 +00:00
|
|
|
$date = new DateTime(NULL);
|
|
|
|
$date->sub(new DateInterval($cleanPeriod));
|
|
|
|
$filter = sprintf('BEFORE "%s"', $date->format('D, j M Y'));
|
2016-08-26 12:43:45 +00:00
|
|
|
|
|
|
|
$folders = [
|
2019-05-24 13:30:48 +00:00
|
|
|
$this->imapConf['successFolder']
|
|
|
|
,$this->imapConf['errorFolder']
|
2016-08-26 12:43:45 +00:00
|
|
|
];
|
|
|
|
|
2018-06-06 11:08:17 +00:00
|
|
|
foreach ($folders as $folder)
|
2018-05-23 10:14:20 +00:00
|
|
|
if (imap_reopen($imap, "{$this->mailbox}$folder")) {
|
|
|
|
if ($messages = imap_search($imap, $filter)) {
|
2018-06-06 11:08:17 +00:00
|
|
|
foreach ($messages as $message)
|
2018-05-23 10:14:20 +00:00
|
|
|
imap_delete($imap, $message);
|
2016-08-26 12:43:45 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
imap_expunge($imap);
|
|
|
|
$count = count($messages);
|
2016-08-26 12:43:45 +00:00
|
|
|
$deleted += $count;
|
2018-05-23 11:09:55 +00:00
|
|
|
} else
|
2016-08-26 12:43:45 +00:00
|
|
|
$count = 0;
|
|
|
|
|
2016-08-31 11:53:46 +00:00
|
|
|
echo "$count mails deleted from $folder mailbox\n";
|
2016-08-26 12:43:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 11:53:46 +00:00
|
|
|
echo "Total $deleted mails deleted\n";
|
2017-07-10 11:37:04 +00:00
|
|
|
|
|
|
|
echo "Deleting records from database\n";
|
2019-05-24 13:30:48 +00:00
|
|
|
$db->query('DELETE FROM mail WHERE created < #', [$date]);
|
2017-07-10 11:37:04 +00:00
|
|
|
echo "Done\n";
|
2016-08-26 12:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|