public function sendDigestMails()
    {
        $subscriptionRepository = $this->entityManager->getRepository('PhlexibleMessageBundle:Subscription');
        $subscriptions = $subscriptionRepository->findByHandler('digest');

        $digests = [];
        foreach ($subscriptions as $subscription) {
            $filter = $this->filterManager->find($subscription->getFilterId());
            if (!$filter) {
                continue;
            }

            $user = $this->userManager->find($subscription->getUserId());
            if (!$user || !$user->getEmail()) {
                continue;
            }

            $lastSend = $subscription->getAttribute('lastSend', null);
            if (!$lastSend) {
                $lastSend = new \DateTime();
                $lastSend = $lastSend->sub(new \DateInterval('P30D'));
            } else {
                $lastSend = new \DateTime($lastSend);
            }

            $criteria = new Criteria([$filter->getCriteria()], Criteria::MODE_AND);
            $criteria->dateFrom($lastSend);
            $messages = $this->messageRepository->findByCriteria($criteria);
            if (!count($messages)) {
                continue;
            }

            if ($this->mailer->sendDigestMail($user, $messages)) {
                $digests[] = ['filter' => $filter->getTitle(), 'to' => $user->getEmail(), 'status' => 'ok'];
                $subscription->setAttribute('lastSend', date('Y-m-d H:i:s'));
                $this->subscriptionRepository->save($subscription);
            } else {
                $digests[] = ['filter' => $filter->getTitle(), 'to' => $user->getEmail(), 'status' => 'failed'];
            }
        }

        if (count($digests)) {
            $message = Message::create(
                count($digests).' digest mail(s) sent.',
                'Status: '.PHP_EOL.print_r($digests, true),
                Message::PRIORITY_NORMAL,
                null,
                'ROLE_MESSAGES',
                'cli'
            );
            $this->messageService->post($message);
        }

        return $digests;
    }