1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00
django-mailbox/django_mailbox/management/commands/getmail.py
2012-06-27 20:45:01 -07:00

18 lines
674 B
Python

from django.core.management.base import BaseCommand
from django.dispatch import receiver
from django_mailbox.models import Mailbox
from django_mailbox.signals import message_received
class Command(BaseCommand):
def handle(self, *args, **options):
mailboxes = Mailbox.objects.all()
if args:
mailboxes = mailboxes.filter(name = ' '.join(args))
for mailbox in mailboxes:
self.stdout.write('Gathering messages for %s\n' % mailbox.name)
mailbox.get_new_mail()
@receiver(message_received)
def incoming_message(self, sender, message, **kwargs):
self.stdout.write('Received %s\n' % message.subject)