class DeleteMailsFromMailQueueTask implements Task {

    @Override
    public Result run() {
        try (ManageableMailQueue queue = factory.create(queueName)) {
            this.initialCount = Optional.of(getRemainingSize(queue));
            this.queue = Optional.of(queue);
            optionalSender.ifPresent(Throwing.consumer(
                (MailAddress sender) -> queue.remove(ManageableMailQueue.Type.Sender, sender.asString())));
            optionalName.ifPresent(Throwing.consumer(
                (String name) -> queue.remove(ManageableMailQueue.Type.Name, name)));
            optionalRecipient.ifPresent(Throwing.consumer(
                (MailAddress recipient) -> queue.remove(ManageableMailQueue.Type.Recipient, recipient.asString())));

            this.lastAdditionalInformation = details();

            return Result.COMPLETED;
        } catch (IOException | MailQueue.MailQueueException e) {
            LOGGER.error("Delete mails from MailQueue got an exception", e);
            return Result.PARTIAL;
        } finally {
            this.queue = Optional.empty();
        }
    }

    public  DeleteMailsFromMailQueueTask(MailQueueName queueName, MailQueueFactory factory,
                                        Optional<MailAddress> optionalSender,
                                        Optional<String> optionalName,
                                        Optional<MailAddress> optionalRecipient);

}