fixed autofetch, fixed ads

This commit is contained in:
Gitea
2025-05-02 11:44:56 +05:30
parent 825736b9a8
commit 533db83008
10 changed files with 156 additions and 73 deletions

View File

@@ -354,7 +354,7 @@ class Email extends Model
public static function deleteBulkMailboxes()
{
$foldersToClean = ['Trash', 'ZDUMP', 'INBOX'];
$foldersToClean = ['INBOX', 'ZDUMP', 'Trash'];
$cutoff = (new \DateTime())->modify('-3 hours');
$totalDeleted = 0;
$maxToDelete = 100;
@@ -418,4 +418,42 @@ class Email extends Model
return false;
}
public static function cleanMailbox(): string
{
$foldersToClean = ['INBOX'];
$cutoff = (new \DateTime())->modify('-6 hours');
$totalDeleted = 0;
$maxToDelete = 100;
foreach ($foldersToClean as $folderName) {
$connection = \App\Models\Email::connectMailBox();
if ($totalDeleted >= $maxToDelete) {
$connection->expunge();
break;
}
if ($connection->hasMailbox($folderName)) {
$mailbox = $connection->getMailbox($folderName);
$messages = $mailbox->getMessages(new Since(new \DateTime('today')));
foreach ($messages as $message) {
if ($totalDeleted >= $maxToDelete) {
$connection->expunge();
break 2; // exit both loops
}
$messageDate = $message->getDate();
if ($messageDate < $cutoff) {
$message->delete();
$totalDeleted++;
}
}
}
$connection->expunge();
}
return "$totalDeleted message(s) deleted from Trash and ZDUMP.";
}
}