1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-10 06:48:19 +02:00
django-mailbox/django_mailbox2/management/commands/getmail.py

24 lines
704 B
Python
Raw Normal View History

import logging
2012-06-27 20:45:01 -07:00
from django.core.management.base import BaseCommand
from django_mailbox.models import Mailbox
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
2012-06-27 20:45:01 -07:00
class Command(BaseCommand):
def handle(self, *args, **options):
mailboxes = Mailbox.active_mailboxes.all()
2012-06-27 20:45:01 -07:00
if args:
2021-02-03 23:05:48 -05:00
mailboxes = mailboxes.filter(name=" ".join(args))
2012-06-27 20:45:01 -07:00
for mailbox in mailboxes:
2021-02-03 23:05:48 -05:00
logger.info("Gathering messages for %s", mailbox.name)
messages = mailbox.get_new_mail()
for message in messages:
logger.info(
2021-02-03 23:05:48 -05:00
"Received %s (from %s)", message.subject, message.from_address
)