58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
// 1. Bootstrap Laravel
|
|
require __DIR__.'/vendor/autoload.php';
|
|
|
|
$app = require __DIR__.'/bootstrap/app.php';
|
|
|
|
// 2. Start Laravel container
|
|
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
|
$kernel->bootstrap();
|
|
|
|
set_time_limit(0);
|
|
|
|
$newTimezone = 'Europe/London';
|
|
date_default_timezone_set($newTimezone);
|
|
|
|
$imapDB = json_decode(config('app.settings.imap_settings') ?: '{}', true);
|
|
|
|
// Mailbox credentials
|
|
$hostname = '{'.($imapDB['premium_host'] ?? 'localhost').':'.($imapDB['premium_port'] ?? '993').'/ssl}INBOX';
|
|
$username = $imapDB['premium_username'] ?? '';
|
|
$password = $imapDB['premium_password'] ?? '';
|
|
|
|
// Connect to mailbox
|
|
$inbox = imap_open($hostname, $username, $password);
|
|
|
|
// Check for connection errors
|
|
if (! $inbox) {
|
|
exit('Could not connect to mailbox: '.imap_last_error());
|
|
}
|
|
|
|
// Get current time in Unix timestamp
|
|
$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);
|
|
|
|
$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.';
|
|
}
|
|
|
|
// Close mailbox connection
|
|
imap_close($inbox);
|