public function run(Context $context) { foreach ($this->config['accounts'] as $account) { $job = new Job(CheckIncomingMailAccount::class, ['account' => $account]); $context->getDaemon()->enqueue($job); } }
public function run(Context $context) { $account = $context->getParam('account'); if (!$account) { $context->getLogger()->debug('No account provided, stopping job.'); return; } $mail = $this->getStorage($account); $mailCount = $mail->countMessages(); // We only check the latest 'n' messages, assumption that no more than this // amount of messages come in per day. $messagesToCheck = 100; $lastMessageIndex = max(1, $mailCount - $messagesToCheck); $context->getLogger()->debug(sprintf('Found %d messages, checking latest %d messages', $mailCount, $messagesToCheck)); for ($messageIndex = $mailCount; $messageIndex >= $lastMessageIndex; --$messageIndex) { $job = new Job(CheckIncomingMailMessage::class, ['account' => $account, 'message' => $messageIndex]); $context->getDaemon()->enqueue($job); } }
public function run(Context $context) { $account = $context->getParam('account'); if (!$account) { $context->getLogger()->debug('No account provided, stopping job.'); return; } // Gracefully sleep a little a bit to not flood the server. sleep(1); $mail = $this->getStorage($account); $messageNum = $context->getParam('message'); $message = $mail->getMessage($messageNum); if (!$message) { $context->getLogger()->debug(sprintf('Could not find message with index %d, stopping job.', $messageNum)); return; } $context->getLogger()->debug(sprintf('Found %d parts in this message.', $message->countParts())); $handled = false; /** @var IncomingMailHandlerInterface $handler */ foreach ($this->handlers as $handler) { if ($handler->canHandle($message)) { $handler->handle($message); $handled = true; } } $context->getLogger()->info($handled ? 'The message was handled.' : 'No valid handler found for message.'); return; for ($i = 1; $i <= $message->countParts(); ++$i) { $part = $message->getPart($i); $contentType = strtok($part->contentType, ';'); switch (true) { case $contentType === 'multipart/alternative': break; case substr($contentType, 0, 6) === 'image/': //$this->downloadAttachment(); break; default: $context->getLogger()->info('Ignoring non-implemented Content-Type: ' . $contentType); exit; break; } } }