2023-06-09 00:54:34 -04:00
|
|
|
<?php
|
|
|
|
namespace ProVM\Command\Mailboxes;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2023-06-12 21:14:07 -04:00
|
|
|
use ProVM\Service\Mailboxes;
|
2023-06-09 00:54:34 -04:00
|
|
|
|
|
|
|
#[AsCommand(
|
|
|
|
name: 'mailboxes:check',
|
|
|
|
description: 'Check registered mailboxes for new emails',
|
|
|
|
hidden: false
|
|
|
|
)]
|
|
|
|
class Check extends Command
|
|
|
|
{
|
2023-06-12 21:14:07 -04:00
|
|
|
public function __construct(protected Mailboxes $service, string $name = null)
|
2023-06-09 00:54:34 -04:00
|
|
|
{
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$section1 = $output->section();
|
|
|
|
$section2 = $output->section();
|
|
|
|
$io1 = new SymfonyStyle($input, $section1);
|
|
|
|
$io2 = new SymfonyStyle($input, $section2);
|
|
|
|
$io1->title('Checking for New Messages');
|
2023-06-12 21:14:07 -04:00
|
|
|
$mailboxes = $this->service->getAll();
|
2023-06-09 00:54:34 -04:00
|
|
|
$notice = 'Found ' . count($mailboxes) . ' mailboxes';
|
|
|
|
$io1->text($notice);
|
|
|
|
if (count($mailboxes) > 0) {
|
|
|
|
$io1->section('Checking for new messages');
|
|
|
|
$io1->progressStart(count($mailboxes));
|
|
|
|
foreach ($mailboxes as $mailbox) {
|
|
|
|
$section2->clear();
|
|
|
|
$io2->text("Checking {$mailbox->name}");
|
2023-06-12 21:14:07 -04:00
|
|
|
if ($this->service->check($mailbox)) {
|
2023-06-09 00:54:34 -04:00
|
|
|
$io2->success("Found new emails in {$mailbox->name}");
|
|
|
|
} else {
|
|
|
|
$io2->info("No new emails in {$mailbox->name}");
|
|
|
|
}
|
|
|
|
$io1->progressAdvance();
|
|
|
|
}
|
|
|
|
$io1->progressFinish();
|
|
|
|
}
|
|
|
|
$section2->clear();
|
|
|
|
$io2->success('Done');
|
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|