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
|
|
|
|
2016-08-31 11:53:46 +00:00
|
|
|
class Clean extends Edi\Method
|
2016-08-26 12:43:45 +00:00
|
|
|
{
|
2016-10-16 14:16:08 +00:00
|
|
|
function ediRun ($db)
|
2016-08-26 12:43:45 +00:00
|
|
|
{
|
|
|
|
$imap = $this->imap;
|
|
|
|
|
|
|
|
$cleanPeriod = $db->getValue ('SELECT clean_period FROM imap_config');
|
|
|
|
|
|
|
|
$deleted = 0;
|
|
|
|
$date = new DateTime (NULL);
|
|
|
|
$date->sub (new DateInterval ($cleanPeriod));
|
|
|
|
$filter = sprintf ('BEFORE "%s"', $date->format('D, j M Y'));
|
|
|
|
|
|
|
|
$folders = [
|
|
|
|
$this->imapConf['success_folder']
|
|
|
|
,$this->imapConf['error_folder']
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($folders as $folder)
|
2017-07-10 11:37:04 +00:00
|
|
|
if (imap_reopen ($imap, "{$this->mailbox}$folder"))
|
2016-08-26 12:43:45 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
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";
|
|
|
|
$db->query ('DELETE FROM message WHERE created < #', [$date]);
|
|
|
|
echo "Done\n";
|
2016-08-26 12:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|