0
1
Fork 0
hedera-web-mindshore/rest/edi/clean.php

50 lines
965 B
PHP
Raw Normal View History

<?php
require_once (__DIR__.'/lib/edi-method.php');
class Clean extends EdiMethod
{
function ediRun ()
{
$db = $this->getSysConn ();
$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)
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;
printf ('%d mails deleted from %s mailbox.'
,$count
,$folder
);
}
printf ('Total: %d mails deleted.', $deleted);
}
}
?>