Various updates
This commit is contained in:
@ -4,6 +4,7 @@ namespace ProVM\Common\Service;
|
||||
use Ddeboer\Imap\Exception\MessageDoesNotExistException;
|
||||
use Ddeboer\Imap\MailboxInterface;
|
||||
use PDOException;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
use ProVM\Common\Exception\Mailbox\Stateless;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Ddeboer\Imap\MessageInterface;
|
||||
@ -14,17 +15,19 @@ use Safe\DateTimeImmutable;
|
||||
|
||||
class Messages extends Base
|
||||
{
|
||||
public function __construct(Mailboxes $mailboxes, Message $repository, Remote\Messages $remoteService, LoggerInterface $logger)
|
||||
public function __construct(Mailboxes $mailboxes, Message $repository, Remote\Messages $remoteService, Jobs $jobsService, LoggerInterface $logger)
|
||||
{
|
||||
$this->setMailboxes($mailboxes)
|
||||
->setRepository($repository)
|
||||
->setRemoteService($remoteService)
|
||||
->setJobsService($jobsService)
|
||||
->setLogger($logger);
|
||||
}
|
||||
|
||||
protected Mailboxes $mailboxes;
|
||||
protected Message $repository;
|
||||
protected Remote\Messages $remoteService;
|
||||
protected Jobs $jobsService;
|
||||
|
||||
public function getMailboxes(): Mailboxes
|
||||
{
|
||||
@ -38,6 +41,10 @@ class Messages extends Base
|
||||
{
|
||||
return $this->remoteService;
|
||||
}
|
||||
public function getJobsService(): Jobs
|
||||
{
|
||||
return $this->jobsService;
|
||||
}
|
||||
|
||||
public function setMailboxes(Mailboxes $mailboxes): Messages
|
||||
{
|
||||
@ -54,6 +61,11 @@ class Messages extends Base
|
||||
$this->remoteService = $service;
|
||||
return $this;
|
||||
}
|
||||
public function setJobsService(Jobs $service): Messages
|
||||
{
|
||||
$this->jobsService = $service;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLocalMessage(string $message_uid): \ProVM\Emails\Model\Message
|
||||
{
|
||||
@ -142,6 +154,7 @@ class Messages extends Base
|
||||
$message->doesHaveValidAttachments();
|
||||
}
|
||||
}
|
||||
error_log(json_encode(compact('message')).PHP_EOL,3,'/logs/debug');
|
||||
$this->getRepository()->save($message);
|
||||
return true;
|
||||
} catch (PDOException $e) {
|
||||
@ -174,4 +187,30 @@ class Messages extends Base
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function find(string $subject, string $date): array
|
||||
{
|
||||
return $this->repository->fetchAllBySubjectAndDate($subject, new DateTimeImmutable($date));
|
||||
}
|
||||
public function checkUpdate(): void
|
||||
{
|
||||
$registered = $this->getMailboxes()->getRegistered();
|
||||
foreach ($registered as $mailbox) {
|
||||
if (!$this->getMailboxes()->isUpdated($mailbox)) {
|
||||
$this->logger->info("Updating messages from {$mailbox->getName()}");
|
||||
$this->grab($mailbox->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
public function checkSchedule(): void
|
||||
{
|
||||
$messages = $this->getRepository()->fetchAll();
|
||||
foreach ($messages as $message) {
|
||||
if ($message->hasAttachments() and $message->hasValidAttachments() and !$message->hasDownloadedAttachments() and !$message->hasScheduledDownloads()) {
|
||||
if ($this->getJobsService()->schedule($message->getId())) {
|
||||
$message->doesHaveDownloadedAttachments();
|
||||
$this->getRepository()->save($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user