1
0
Fork 0
django-mailbox/django_mailbox/management/commands/getmail.py

17 lines
662 B
Python

from django.core.management.base import BaseCommand
from django_mailbox.models import Mailbox
class Command(BaseCommand):
def handle(self, *args, **options):
mailboxes = Mailbox.active_mailboxes.all()
if args:
mailboxes = mailboxes.filter(name = ' '.join(args))
for mailbox in mailboxes:
self.stdout.write('Gathering messages for %s\n' % mailbox.name)
messages = mailbox.get_new_mail()
for message in messages:
self.stdout.write('Recieved %s (from %s)\n' % (
message.subject,
message.from_address
))