forked from verdnatura/hedera-web
44 lines
994 B
PHP
44 lines
994 B
PHP
<?php
|
|
|
|
require_once __DIR__.'/lib/method.php';
|
|
|
|
class Clean extends Edi\Method {
|
|
function ediRun($db) {
|
|
$imap = $this->imap;
|
|
|
|
$cleanPeriod = $db->getValue('SELECT cleanPeriod FROM imapConfig');
|
|
|
|
$deleted = 0;
|
|
$date = new DateTime(NULL);
|
|
$date->sub(new DateInterval($cleanPeriod));
|
|
$filter = sprintf('BEFORE "%s"', $date->format('D, j M Y'));
|
|
|
|
$folders = [
|
|
$this->imapConf['successFolder']
|
|
,$this->imapConf['errorFolder']
|
|
];
|
|
|
|
foreach ($folders as $folder)
|
|
if (imap_reopen($imap, "{$this->mailbox}$folder")) {
|
|
if ($messages = imap_search($imap, $filter)) {
|
|
foreach ($messages as $message)
|
|
imap_delete($imap, $message);
|
|
|
|
imap_expunge($imap);
|
|
$count = count($messages);
|
|
$deleted += $count;
|
|
} else
|
|
$count = 0;
|
|
|
|
echo "$count mails deleted from $folder mailbox\n";
|
|
}
|
|
|
|
echo "Total $deleted mails deleted\n";
|
|
|
|
echo "Deleting records from database\n";
|
|
$db->query('DELETE FROM mail WHERE created < #', [$date]);
|
|
echo "Done\n";
|
|
}
|
|
}
|
|
|