fixed dropmail.php to check every 2 hours
This commit is contained in:
36
dropmail.php
36
dropmail.php
@@ -32,24 +32,48 @@ if (!$inbox) {
|
||||
$current_time = time();
|
||||
|
||||
// Search for messages older than one day
|
||||
$search_criteria = 'BEFORE "' . date('d-M-Y', strtotime('-3 hours', $current_time)) . '"';
|
||||
$messages = imap_search($inbox, $search_criteria);
|
||||
//$search_criteria = 'BEFORE "' . date('d-M-Y', strtotime('-3 hours', $current_time)) . '"';
|
||||
//$messages = imap_search($inbox, $search_criteria);
|
||||
|
||||
$messages = imap_search($inbox, 'ALL');
|
||||
|
||||
$batch_size = 10;
|
||||
$deleted_count = 0;
|
||||
|
||||
//if ($messages) {
|
||||
// $chunks = array_chunk($messages, $batch_size);
|
||||
// foreach ($chunks as $chunk) {
|
||||
// foreach ($chunk as $message_number) {
|
||||
// imap_delete($inbox, $message_number);
|
||||
// }
|
||||
// imap_expunge($inbox);
|
||||
// $deleted_count += count($chunk);
|
||||
// }
|
||||
// echo $deleted_count . ' messages older than specified time have been deleted.';
|
||||
//} else {
|
||||
// echo 'No messages older than specified time found in mailbox.';
|
||||
//}
|
||||
|
||||
if ($messages) {
|
||||
$chunks = array_chunk($messages, $batch_size);
|
||||
foreach ($chunks as $chunk) {
|
||||
foreach ($chunk as $message_number) {
|
||||
imap_delete($inbox, $message_number);
|
||||
// Get message header to fetch internal date
|
||||
$header = imap_headerinfo($inbox, $message_number);
|
||||
$date_str = $header->date;
|
||||
$msg_time = strtotime($date_str);
|
||||
|
||||
// Check if message is older than 3 hours
|
||||
if ($msg_time !== false && ($current_time - $msg_time) > 2 * 3600) {
|
||||
imap_delete($inbox, $message_number);
|
||||
$deleted_count++;
|
||||
}
|
||||
}
|
||||
imap_expunge($inbox);
|
||||
$deleted_count += count($chunk);
|
||||
}
|
||||
echo $deleted_count . ' messages older than specified time have been deleted.';
|
||||
echo $deleted_count . ' messages older than 2 hours have been deleted.';
|
||||
} else {
|
||||
echo 'No messages older than specified time found in mailbox.';
|
||||
echo 'No messages found in mailbox.';
|
||||
}
|
||||
|
||||
// Close mailbox connection
|
||||
|
||||
Reference in New Issue
Block a user