accountService = $service;
$this->classifier = $classifier;
$this->logger = $logger;
$this->config = $config;
}
protected function configure(): void {
$this->setName('mail:predict-importance');
$this->setDescription('Predict importance of an incoming message');
$this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED);
$this->addArgument(self::ARGUMENT_SENDER, InputArgument::REQUIRED);
$this->addArgument(self::ARGUMENT_SUBJECT, InputArgument::OPTIONAL);
}
public function isEnabled(): bool {
return $this->config->getSystemValueBool('debug');
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID);
$sender = $input->getArgument(self::ARGUMENT_SENDER);
$subject = $input->getArgument(self::ARGUMENT_SUBJECT) ?? '';
$consoleLogger = new ConsoleLoggerDecorator(
$this->logger,
$output
);
try {
$account = $this->accountService->findById($accountId);
} catch (DoesNotExistException $e) {
$output->writeln("account $accountId does not exist");
return 1;
}
$fakeMessage = new Message();
$fakeMessage->setUid(0);
$fakeMessage->setFrom(AddressList::parse("Name <$sender>"));
$fakeMessage->setSubject($subject);
[$prediction] = $this->classifier->classifyImportance(
$account,
[$fakeMessage],
$consoleLogger
);
if ($prediction) {
$output->writeln('Message is important');
} else {
$output->writeln('Message is not important');
}
$mbs = (int)(memory_get_peak_usage() / 1024 / 1024);
$output->writeln('' . $mbs . 'MB of memory used');
return 0;
}
}