feat: Prepare Zemailnator for Dokploy deployment
- Add highly optimized Dockerfile with Nginx and PHP-FPM 8.4 - Add docker-compose.yml configured with Redis and MariaDB 10.11 - Implement entrypoint.sh and supervisord.conf for background workers - Refactor legacy IMAP scripts into scheduled Artisan Commands - Secure app by removing old routes with hardcoded basic auth credentials - Configure email attachments to use Laravel Storage instead of insecure public/tmp
This commit is contained in:
74
dropmail.php
74
dropmail.php
@@ -11,71 +11,11 @@ $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['host'] ?? 'localhost').':'.($imapDB['port'] ?? '993').'/ssl}INBOX';
|
||||
$username = $imapDB['username'] ?? '';
|
||||
$password = $imapDB['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());
|
||||
try {
|
||||
// Run the new Artisan command fallback
|
||||
$exitCode = $kernel->call('mailbox:clean');
|
||||
$output = $kernel->output();
|
||||
echo $output;
|
||||
} catch (\Exception $e) {
|
||||
echo 'Error running Artisan command: '.$e->getMessage();
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
$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) {
|
||||
// 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);
|
||||
}
|
||||
echo $deleted_count.' messages older than 2 hours have been deleted.';
|
||||
} else {
|
||||
echo 'No messages found in mailbox.';
|
||||
}
|
||||
|
||||
// Close mailbox connection
|
||||
imap_close($inbox);
|
||||
|
||||
Reference in New Issue
Block a user