Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Improvements (#2007)
Browse files Browse the repository at this point in the history
* Add delete flag

* Add Command to run mail sync
  • Loading branch information
Rindula authored Jul 15, 2024
1 parent adb3c4f commit 03c72fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
40 changes: 40 additions & 0 deletions src/Command/ConsumeMailCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Command;

use App\Message\SyncMenuMessage;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Messenger\MessageBusInterface;

#[AsCommand(
name: 'app:consume:mail',
description: 'Add a short description for your command',
)]
class ConsumeMailCommand extends Command
{
public function __construct(private readonly MessageBusInterface $messageBus)
{
parent::__construct();
}

protected function configure(): void
{
$this->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete all messages');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$delete = $input->getOption('delete');

$this->messageBus->dispatch(new SyncMenuMessage(!!$delete));

return Command::SUCCESS;
}
}
8 changes: 4 additions & 4 deletions src/Message/SyncMenuMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ final class SyncMenuMessage
* to hold the data for this message class.
*/

// public function __construct(
// public readonly string $name,
// ) {
// }
public function __construct(
public readonly bool $delete = true,
) {
}
}
3 changes: 2 additions & 1 deletion src/MessageHandler/SyncMenuMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public function __invoke(SyncMenuMessage $message): void
break;
}
// delete the mails so the inbox is empty again
imap_delete($mbox, $emailId);
if ($message->delete)
imap_delete($mbox, $emailId);
}
}

Expand Down

0 comments on commit 03c72fd

Please sign in to comment.