2014-08-22 20:02:58 -07:00
|
|
|
import logging
|
|
|
|
|
|
2012-06-27 20:45:01 -07:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
2021-02-08 23:39:19 -05:00
|
|
|
from django_mailbox2.models import Mailbox
|
2012-06-27 20:45:01 -07:00
|
|
|
|
2014-08-22 20:02:58 -07:00
|
|
|
|
|
|
|
|
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):
|
2012-10-09 05:52:04 +00:00
|
|
|
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)
|
2012-06-28 09:41:31 -07:00
|
|
|
messages = mailbox.get_new_mail()
|
|
|
|
|
for message in messages:
|
2014-08-22 20:02:58 -07:00
|
|
|
logger.info(
|
2021-02-03 23:05:48 -05:00
|
|
|
"Received %s (from %s)", message.subject, message.from_address
|
2014-08-22 20:02:58 -07:00
|
|
|
)
|