fixed autofetch, fixed ads
This commit is contained in:
@@ -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.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user